on master help sign in
Make errors a little bit better when a type alias gets the wrong number of arguments.
commita3f62c34c3e25464ce250b08b9292e4e70758634 authorEvan Czaplicki <info@elm-lang.org> dateTue 6 Aug 2013, 15:43 (13 years ago) parent7af7c1f
1 file changed+5−3
compiler/Type/Environment.hs+5−3
compiler/Type/Environment.hs+5−3
@@ -99,7 +99,7 @@ ctorToType env (name, tvars, ctors) =
9999get :: Environment -> (Environment -> Map.Map String a) -> String -> a
100100get env subDict key = Map.findWithDefault err key (subDict env)
101101 where
102− err = error $ "Could not find type constructor '" ++ key ++ "' while checking types."
102+ err = error $ "\nCould not find type constructor '" ++ key ++ "' while checking types."
103103
104104
105105freshDataScheme :: Environment -> String -> IO (Int, [Variable], [Type], Type)
@@ -146,9 +146,11 @@ instantiator env sourceType = go sourceType
146146 Just t -> return $ foldl (<|) t ts'
147147 Nothing ->
148148 case Map.lookup name (aliases env) of
149− Nothing -> error $ "Could not find type constructor '" ++ name ++ "' while checking types."
149+ Nothing -> error $ "\nCould not find type constructor '" ++ name ++ "' while checking types."
150150 Just (tvars, t) ->
151− let msg = "Type alias '" ++ name ++ "' expects " ++ show (length tvars) ++
151+ let tvarLen = length tvars
152+ msg = "\nType alias '" ++ name ++ "' expects " ++ show tvarLen ++
153+ " type argument" ++ (if tvarLen == 1 then "" else "s") ++
152154 " but was given " ++ show (length ts')
153155 in if length ts' /= length tvars then error msg else
154156 do (dict, aliases) <- State.get