Skip to content

Commit

Permalink
Make sure error messages announce that they are, in fact, error messa…
Browse files Browse the repository at this point in the history
…ges. Addresses #16.
  • Loading branch information
dougalm committed Nov 22, 2019
1 parent 634e911 commit c91078f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions examples/shadow-tests.dx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

-- repeated vars in patterns not allowed
:p (x, x) = (1, 1); x
> Variable redefined: x
> Error: variable already defined: x

:p f (x, x) = x; f (1, 1)
> Variable redefined: x
> Error: variable already defined: x

-- TODO: re-enable if we choose to allow non-peer shadowing
-- -- shouldn't cause error even though it shadows x elsewhere
Expand All @@ -21,7 +21,7 @@ arr = 10
-- _ = 10 -- underscore shadows allowed

arr = 20
> Variable redefined: arr
> Error: variable already defined: arr

:p arr
> 10
Expand Down
2 changes: 1 addition & 1 deletion examples/type-tests.dx
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ f x =
> ^^
:t x = 3
for i::x. 0
> Variable not in scope:type variable "x" (a term variable of the same name is in scope)
> Error: variable not in scope: type variable "x" (a term variable of the same name is in scope)
4 changes: 2 additions & 2 deletions src/lib/DeShadow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ freshBinderP :: BinderP a -> DeShadowCat (BinderP a)
freshBinderP (v:>ann) = do
shadowed <- looks $ (v `isin`) . fst . fst
if shadowed && v /= Name "_" 0
then throw RepeatedVarErr (" " ++ pprint v)
then throw RepeatedVarErr (pprint v)
else return ()
v' <- looks $ rename v . snd
extend (asFst (v@>v'), v'@>())
Expand All @@ -129,7 +129,7 @@ freshTBinder :: TBinder -> DeShadowCat TBinder
freshTBinder (v:>k) = do
shadowed <- looks $ (v `isin`) . snd . fst
if shadowed && v /= Name "_" 0
then throw RepeatedVarErr (" " ++ pprint v)
then throw RepeatedVarErr (pprint v)
else return ()
v' <- looks $ rename v . snd
extend (asSnd (v@>TypeVar v'), v'@>())
Expand Down
2 changes: 1 addition & 1 deletion src/lib/JIT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ compileBuiltin b ts = case b of
FDiv -> compileBinop RealType (\x y -> L.FDiv noFastMathFlags x y [])
FLT -> compileBinop BoolType (\x y -> L.FCmp L.OLT x y [])
FGT -> compileBinop BoolType (\x y -> L.FCmp L.OGT x y [])
Todo -> const $ throw OtherErr "Can't compile 'todo'"
Todo -> const $ throw MiscErr "Can't compile 'todo'"
BoolToInt -> compileUnop IntType (\x -> L.ZExt x longTy [])
IntToReal -> compileUnop RealType (\x -> L.SIToFP x realTy [])
FFICall _ name -> compileFFICall name ts
Expand Down
9 changes: 4 additions & 5 deletions src/lib/PPrint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ instance Pretty ErrType where
ParseErr -> "Parse error:"
TypeErr -> "Type error:"
LinErr -> "Linearity error:"
CompilerErr -> "Compiler bug!"
UnboundVarErr -> "Variable not in scope:"
RepeatedVarErr -> "Variable redefined:"
UnboundVarErr -> "Error: variable not in scope: "
RepeatedVarErr -> "Error: variable already defined: "

This comment has been minimized.

Copy link
@oxinabox

oxinabox Nov 22, 2019

Contributor

Why do these have spaces and others don't.

E.g
Compiler bug!Can't lower type to imp: (Real -> (Real, (Real -> Real)))

Shouldn't they all have spaces?

This comment has been minimized.

Copy link
@dougalm

dougalm Nov 22, 2019

Author Collaborator

I was hoping nobody would notice! It's just a little hack. The type errors tend to put their context on a new line, which means that spaces become trailing spaces on the line, which looks very ugly in my editor. Consistent and well formatted error messages would be nice, but it's low priority at this stage of the project.

This comment has been minimized.

Copy link
@oxinabox

oxinabox Nov 22, 2019

Contributor

legit

NotImplementedErr -> "Not implemented:"
OtherErr -> "Error:"
UpstreamErr -> "Upstream failure"
CompilerErr -> "Compiler bug!"
MiscErr -> "Error:"

instance Pretty Type where
pretty t = prettyTyDepth 0 t
Expand Down
3 changes: 1 addition & 2 deletions src/lib/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ data ErrType = NoErr
| RepeatedVarErr
| CompilerErr
| NotImplementedErr
| UpstreamErr
| OtherErr
| MiscErr
deriving (Show)

type Except a = Either Err a
Expand Down

0 comments on commit c91078f

Please sign in to comment.