git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix bad error for non-existent methods on a class

When defining an instance for Monad with a silly method: instance Monad X where fakeMethod = 100 Would say: > Type class Prelude.Monad is undefined. Type class names must be qualified. It now says: > Type class Prelude.Monad does not have method fakeMethod

commit20f350d260824e953566de9059b5ad207f36a914 authorBrian McKenna <brian@simpleenergy.com> dateSat 1 Feb 2014, 10:55 (13 years ago) parent8ff6185
1 file changed+6−4
src/Language/PureScript/Sugar/TypeClasses.hs+6−4
src/Language/PureScript/Sugar/TypeClasses.hs+6−4
@@ -106,13 +106,15 @@ typeInstanceDictionaryDeclaration mn deps name ty decls = do
106106typeInstanceDictionaryEntryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> Declaration -> Desugar Declaration
107107typeInstanceDictionaryEntryDeclaration mn deps name ty (ValueDeclaration ident [] _ val) = do
108108 m <- get
109− valTy <- lift $ maybe (Left $ "Type class " ++ show name ++ " is undefined. Type class names must be qualified.") Right $
110− do (arg, members) <- M.lookup (qualify mn name) m
111− ty' <- lookup (identToJs ident) members
112− return $ replaceTypeVars arg ty ty'
109+ valTy <- lift $ do (arg, members) <- lookupTypeClass m
110+ ty' <- lookupIdent members
111+ return $ replaceTypeVars arg ty ty'
113112 entryName <- mkDictionaryEntryName mn name ty ident
114113 return $ ValueDeclaration entryName [] Nothing
115114 (TypedValue True val (quantify (if null deps then valTy else ConstrainedType deps valTy)))
115+ where
116+ lookupTypeClass m = maybe (Left $ "Type class " ++ show name ++ " is undefined. Type class names must be qualified.") Right $ M.lookup (qualify mn name) m
117+ lookupIdent members = maybe (Left $ "Type class " ++ show name ++ " does not have method " ++ show ident) Right $ lookup (identToJs ident) members
116118typeInstanceDictionaryEntryDeclaration _ _ _ _ _ = error "Invalid declaration in type instance definition"
117119
118120qualifiedToString :: ModuleName -> Qualified ProperName -> String