Skip to content

Commit

Permalink
Suggest missing 'valueOf' in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksbp authored and quark17 committed Apr 12, 2021
1 parent 9fab423 commit 4ffc934
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/comp/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ data ErrMsg =
| EBadInstanceOverlap String String Position

| EUndefinedTask String
| EUnboundCon String
| EUnboundCon String (Maybe String)
| EUnboundVar String
| EUnboundField String
| EUnboundClCon String
Expand Down Expand Up @@ -1879,8 +1879,13 @@ getErrorText (EDeriveCtx s) =

getErrorText (EUndefinedTask c) =
(Type 2, empty, s2par ("Unsupported system task " ++ ishow c))
getErrorText (EUnboundCon c) =
(Type 3, empty, s2par ("Unbound constructor " ++ ishow c))
getErrorText (EUnboundCon c maybeSuggest) =
(Type 3, empty,
let intro_msg = "Unbound constructor " ++ ishow c
msg = case maybeSuggest of
Nothing -> intro_msg
Just fname -> intro_msg ++ ". Perhaps " ++ quote fname ++ " is missing?"
in s2par msg)
getErrorText (EUnboundVar c) =
(Type 4, empty, s2par ("Unbound variable " ++ ishow c))
getErrorText (EUnboundField c) =
Expand Down
12 changes: 10 additions & 2 deletions src/comp/TIMonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,17 @@ findCons ct i = do
Nothing -> errorAtId (EConstrAmb (pfpString ct')) i
Just di -> case [ a | ConInfo {ci_id = i', ci_assump = a} <- cs, qualEq di i'] of
[a] -> return (updAssumpPos i a, di)
[] -> errorAtId EUnboundCon i
[] -> errSuggest r i
_ -> internalError "findCons ambig"
Nothing -> errorAtId EUnboundCon i
Nothing -> errSuggest r i
where
errSuggest :: SymTab -> Id -> TI (Assump, Id)
errSuggest r i =
let mSuggest = case findType r i of
Just (TypeInfo _ KNum _ _) -> Just "valueOf"
Just (TypeInfo _ KStr _ _) -> Just "stringOf"
_ -> Nothing
in err (getIdPosition i, EUnboundCon (pfpString i) mSuggest)

findTyCon :: Id -> TI TyCon
findTyCon i = do
Expand Down

0 comments on commit 4ffc934

Please sign in to comment.