git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #159 from puffnfresh/superclasses

Fix bad error for non-existent methods on a class

commit28420804d7e569186fa4ab17e149a20ce1f89f4f authorPhil Freeman <paf31@cantab.net> dateSat 1 Feb 2014, 12:45 (13 years ago) parent046884720f350d
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