From 643efd5ad6efc3d6afc75c96f264066dfa60d4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sved=C3=A4ng?= Date: Mon, 18 Oct 2021 16:54:36 +0200 Subject: [PATCH] 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 --- src/InitialTypes.hs | 2 +- src/TypeError.hs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/InitialTypes.hs b/src/InitialTypes.hs index 1594afb7..bd044640 100644 --- a/src/InitialTypes.hs +++ b/src/InitialTypes.hs @@ -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)) diff --git a/src/TypeError.hs b/src/TypeError.hs index 186097be..1dd46aa6 100644 --- a/src/TypeError.hs +++ b/src/TypeError.hs @@ -103,6 +103,13 @@ instance Show TypeError where show (InvalidObj If xobj) = "I didn’t 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 didn’t 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 didn’t understand the form `" ++ prettyObj o ++ "` at " ++ prettyInfoFromXObj xobj