git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Tests, Check all unknowns in unsolved constraints will be generalized
commit8a318971aa5b6676c4b15b582ad7b609ea14404e authorPhil Freeman <paf31@cantab.net> dateThu 3 Mar 2016, 22:17 (11 years ago) parent855c372
4 files changed+26
examples/failing/ConstraintInference.purs+10 examples/passing/ConstraintInference.purs+7 src/Language/PureScript/TypeChecker/Types.hs+8 src/Language/PureScript/TypeChecker/Unify.hs+1
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
7777 forM tys $ \(shouldGeneralize, (ident, (val, ty))) -> do
7878 -- Replace type class dictionary placeholders with actual dictionaries
7979 (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
8088 -- Check skolem variables did not escape their scope
8189 skolemEscapeCheck val'
8290 -- Check rows do not contain duplicate labels
src/Language/PureScript/TypeChecker/Unify.hs+1
@@ -23,6 +23,7 @@ module Language.PureScript.TypeChecker.Unify (
2323 freshType,
2424 solveType,
2525 substituteType,
26+ unknownsInType,
2627 unifyTypes,
2728 unifyRows,
2829 unifiesWith,