improved error message a bit

This commit is contained in:
Paul Chiusano 2019-04-11 17:43:02 -04:00
parent ea113754f6
commit 4490f6318c
3 changed files with 19 additions and 6 deletions

View File

@ -423,6 +423,12 @@ renderTypeError e env src = case e of
, annotatedAsErrorSite src abilityCheckFailureSite
, debugSummary note
]
UnguardedLetRecCycle vs locs _ -> mconcat
[ "These definitions depend on each other cyclically but aren't guarded "
, "by a lambda: " <> intercalateMap ", " renderVar vs
, "\n"
, showSourceMaybes src [ (,ErrorSite) <$> rangeForAnnotated loc | loc <- locs ]]
UnknownType {..} -> mconcat
[ "I don't know about the type "
, style ErrorSite (renderVar unknownTypeV)

View File

@ -60,6 +60,9 @@ data TypeError v loc
, abilityCheckFailureSite :: loc
, note :: C.ErrorNote v loc
}
| UnguardedLetRecCycle { cycle :: [v]
, cycleLocs :: [loc]
, note :: C.ErrorNote v loc }
| UnknownType { unknownTypeV :: v
, typeSite :: loc
, note :: C.ErrorNote v loc
@ -94,7 +97,8 @@ typeInfoFromNote n = case n of
C.TopLevelComponent defs -> Just $ TopLevelComponent defs
_ -> Nothing
allErrors :: (Var v, Ord loc) => Ex.ErrorExtractor v loc (TypeError v loc)
allErrors
:: (Var v, Ord loc) => Ex.ErrorExtractor v loc (TypeError v loc)
allErrors = asum
[ and
, or
@ -107,6 +111,7 @@ allErrors = asum
, applyingNonFunction
, generalMismatch
, abilityCheckFailure
, unguardedCycle
, unknownType
, unknownTerm
]
@ -167,6 +172,13 @@ or = booleanMismatch0 OrMismatch (Ex.inSynthesizeApp >> Ex.inOrApp)
cond = booleanMismatch0 CondMismatch Ex.inIfCond
matchGuard = booleanMismatch0 GuardMismatch Ex.inMatchGuard
unguardedCycle :: Ex.ErrorExtractor v loc (TypeError v loc)
unguardedCycle = do
n <- Ex.errorNote
C.UnguardedLetRecCycle vs es <- Ex.cause
let loc = ABT.annotation . snd <$> es
pure $ UnguardedLetRecCycle vs loc n
-- | helper function to support `and` / `or` / `cond`
booleanMismatch0 :: (Var v, Ord loc)
=> BooleanMismatch

View File

@ -4,10 +4,5 @@ y = x + 1
> x
---
Currently crashes the runtime with a
unison: user error (type error, expecting N, got (UninitializedLetRecSlot x in [y,x]))