git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix bad error for non-existent methods on a class
20f350dBrian McKenna
src/Language/PureScript/Sugar/TypeClasses.hs+6−4
@@ -106,13 +106,15 @@ typeInstanceDictionaryDeclaration mn deps name ty decls = do
106typeInstanceDictionaryEntryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> Declaration -> Desugar Declaration
106typeInstanceDictionaryEntryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> Declaration -> Desugar Declaration
107typeInstanceDictionaryEntryDeclaration mn deps name ty (ValueDeclaration ident [] _ val) = do
107typeInstanceDictionaryEntryDeclaration mn deps name ty (ValueDeclaration ident [] _ val) = do
108 m <- get
108 m <- get
109− valTy <- lift $ maybe (Left $ "Type class " ++ show name ++ " is undefined. Type class names must be qualified.") Right $
109+ valTy <- lift $ do (arg, members) <- lookupTypeClass m
110− do (arg, members) <- M.lookup (qualify mn name) m
110+ ty' <- lookupIdent members
111− ty' <- lookup (identToJs ident) members
112− return $ replaceTypeVars arg ty ty'
111+ return $ replaceTypeVars arg ty ty'
113 entryName <- mkDictionaryEntryName mn name ty ident
112 entryName <- mkDictionaryEntryName mn name ty ident
114 return $ ValueDeclaration entryName [] Nothing
113 return $ ValueDeclaration entryName [] Nothing
115 (TypedValue True val (quantify (if null deps then valTy else ConstrainedType deps valTy)))
114 (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
116typeInstanceDictionaryEntryDeclaration _ _ _ _ _ = error "Invalid declaration in type instance definition"
118typeInstanceDictionaryEntryDeclaration _ _ _ _ _ = error "Invalid declaration in type instance definition"
117
119
118qualifiedToString :: ModuleName -> Qualified ProperName -> String
120qualifiedToString :: ModuleName -> Qualified ProperName -> String