fix: Don't pass 'If' to InvalidObj when Obj actually is 'Mod' (#1327)

* fix: Don't pass 'If' to InvalidObj when Obj actually is 'Mod'

* fix: Better error message

* fix: Better error

* fix: Show the name of the module in the error message

* fix: Use `root` to get correct location for InvalidObj error

* fix: keep old xobj for now
This commit is contained in:
Erik Svedäng 2021-10-18 16:54:36 +02:00 committed by GitHub
parent f4bcc28fc0
commit 643efd5ad6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -98,7 +98,7 @@ initialTypes typeEnv rootEnv root = evalState (visit rootEnv root) 0
If -> pure (Left (InvalidObj If xobj))
While -> pure (Left (InvalidObj While xobj))
Do -> pure (Left (InvalidObj Do xobj))
(Mod _ _) -> pure (Left (InvalidObj If xobj))
m@(Mod _ _) -> pure (Left (InvalidObj m xobj))
e@(Deftype _) -> pure (Left (InvalidObj e xobj))
e@(External _) -> pure (Left (InvalidObj e xobj))
e@(ExternalType _) -> pure (Left (InvalidObj e xobj))

View File

@ -103,6 +103,13 @@ instance Show TypeError where
show (InvalidObj If xobj) =
"I didnt understand the `if` statement at " ++ prettyInfoFromXObj xobj
++ ".\n\nIs it valid? Every `if` needs to follow the form `(if cond iftrue iffalse)`."
show (InvalidObj (Mod env _) xobj) =
let moduleName =
case envModuleName env of
Just name -> "the module '" ++ name ++ "'"
Nothing -> "an unnamed module"
in "I didnt understand the form mentioning " ++ moduleName ++ " at " ++ prettyInfoFromXObj xobj
++ ".\n\nAre you using a module or type where a value is expected?"
show (InvalidObj o xobj) =
"I didnt understand the form `" ++ prettyObj o ++ "` at "
++ prettyInfoFromXObj xobj