git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Tests, Check all unknowns in unsolved constraints will be generalized
8a31897Phil Freeman
examples/failing/ConstraintInference.pursnew file+10
@@ -0,0 +1,10 @@
1+-- @shouldFailWith NoInstanceFound
2+
3+module Main where
4+
5+import Prelude
6+
7+spin :: forall a b. a -> b
8+spin x = spin x
9+
10+test = show <<< spin
examples/passing/ConstraintInference.pursnew file+7
@@ -0,0 +1,7 @@
1+module Main where
2+
3+import Prelude
4+
5+shout = Control.Monad.Eff.Console.log <<< (<> "!") <<< show
6+
7+main = shout "Done"
src/Language/PureScript/TypeChecker/Types.hs+8
@@ -77,6 +77,14 @@ typesOf moduleName vals = do
77 forM tys $ \(shouldGeneralize, (ident, (val, ty))) -> do
77 forM tys $ \(shouldGeneralize, (ident, (val, ty))) -> do
78 -- Replace type class dictionary placeholders with actual dictionaries
78 -- Replace type class dictionary placeholders with actual dictionaries
79 (val', unsolved) <- replaceTypeClassDictionaries shouldGeneralize moduleName val
79 (val', unsolved) <- replaceTypeClassDictionaries shouldGeneralize moduleName val
80+ let unsolvedTypeVars = nub $ unknownsInType ty
81+ -- Make sure any unsolved type constraints only use type variables which appear
82+ -- unknown in the inferred type.
83+ when shouldGeneralize $
84+ forM_ unsolved $ \(_, (className, classTys)) -> do
85+ let constraintTypeVars = nub $ foldMap unknownsInType classTys
86+ when (any (`notElem` unsolvedTypeVars) constraintTypeVars) $
87+ throwError . errorMessage $ NoInstanceFound className classTys
80 -- Check skolem variables did not escape their scope
88 -- Check skolem variables did not escape their scope
81 skolemEscapeCheck val'
89 skolemEscapeCheck val'
82 -- Check rows do not contain duplicate labels
90 -- Check rows do not contain duplicate labels
src/Language/PureScript/TypeChecker/Unify.hs+1
@@ -23,6 +23,7 @@ module Language.PureScript.TypeChecker.Unify (
23 freshType,
23 freshType,
24 solveType,
24 solveType,
25 substituteType,
25 substituteType,
26+ unknownsInType,
26 unifyTypes,
27 unifyTypes,
27 unifyRows,
28 unifyRows,
28 unifiesWith,
29 unifiesWith,