@@ -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