Skip to content

Commit 643efd5

Browse files
authored
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
1 parent f4bcc28 commit 643efd5

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/InitialTypes.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ initialTypes typeEnv rootEnv root = evalState (visit rootEnv root) 0
9898
If -> pure (Left (InvalidObj If xobj))
9999
While -> pure (Left (InvalidObj While xobj))
100100
Do -> pure (Left (InvalidObj Do xobj))
101-
(Mod _ _) -> pure (Left (InvalidObj If xobj))
101+
m@(Mod _ _) -> pure (Left (InvalidObj m xobj))
102102
e@(Deftype _) -> pure (Left (InvalidObj e xobj))
103103
e@(External _) -> pure (Left (InvalidObj e xobj))
104104
e@(ExternalType _) -> pure (Left (InvalidObj e xobj))

src/TypeError.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ instance Show TypeError where
103103
show (InvalidObj If xobj) =
104104
"I didn’t understand the `if` statement at " ++ prettyInfoFromXObj xobj
105105
++ ".\n\nIs it valid? Every `if` needs to follow the form `(if cond iftrue iffalse)`."
106+
show (InvalidObj (Mod env _) xobj) =
107+
let moduleName =
108+
case envModuleName env of
109+
Just name -> "the module '" ++ name ++ "'"
110+
Nothing -> "an unnamed module"
111+
in "I didn’t understand the form mentioning " ++ moduleName ++ " at " ++ prettyInfoFromXObj xobj
112+
++ ".\n\nAre you using a module or type where a value is expected?"
106113
show (InvalidObj o xobj) =
107114
"I didn’t understand the form `" ++ prettyObj o ++ "` at "
108115
++ prettyInfoFromXObj xobj

0 commit comments

Comments
 (0)