@@ -90,6 +90,15 @@ addTypeClassDictionaries :: [TypeClassDictionaryInScope] -> Check ()
9090addTypeClassDictionaries entries = do
9191 modify $ \st -> st { checkEnv = (checkEnv st) { typeClassDictionaries = entries ++ (typeClassDictionaries . checkEnv $ st) } }
9292
93+checkTypeClassInstance :: ModuleName -> Type -> Check ()
94+checkTypeClassInstance _ (TypeVar _) = return ()
95+checkTypeClassInstance m (TypeConstructor ctor) = do
96+ env <- getEnv
97+ when (canonicalizeType m env ctor `M.member` typeSynonyms env) $ throwError "Type synonym instances are disallowed"
98+ return ()
99+checkTypeClassInstance m (TypeApp ty (TypeVar _)) = checkTypeClassInstance m ty
100+checkTypeClassInstance _ _ = throwError "Type class instance must be of the form T a1 ... an"
101+
93102-- |
94103-- Type check all declarations in a module
95104--
@@ -242,6 +251,8 @@ typeCheckAll moduleName (d@(TypeClassDeclaration _ _ _) : rest) = do
242251typeCheckAll moduleName (d@(TypeInstanceDeclaration deps className ty _) : rest) = do
243252 env <- getEnv
244253 dictName <- Check . lift $ mkDictionaryValueName moduleName className ty
254+ checkTypeClassInstance moduleName ty
255+ forM_ deps $ checkTypeClassInstance moduleName . snd
245256 addTypeClassDictionaries (qualifyAllUnqualifiedNames moduleName env
246257 [TypeClassDictionaryInScope (Qualified (Just moduleName) dictName) className ty (Just deps) TCDRegular])
247258 ds <- typeCheckAll moduleName rest