Improve error message

This commit is contained in:
Paul Chiusano 2022-12-02 13:50:20 -06:00
parent b82c133778
commit e89fd61266
5 changed files with 16 additions and 18 deletions

View File

@ -375,17 +375,14 @@ renderTypeError e env src curPath = case e of
-- , (,Color.ForceShow) <$> rangeForType foundType
-- , (,Color.ForceShow) <$> rangeForType expectedType
-- ,
(,Type1) <$> rangeForAnnotated foundLeaf,
(,Type1) <$> rangeForAnnotated foundType,
(,Type2) <$> rangeForAnnotated expectedLeaf
],
fromOverHere'
src
[styleAnnotated Type1 foundLeaf]
[styleAnnotated Type1 mismatchSite],
if giveUnitHint then
"\nNote: actions within a block must have type " <>
style Type2 (renderType' env expectedLeaf) <> ".\n"
else "",
[styleAnnotated Type1 expectedLeaf],
unitHint,
intLiteralSyntaxTip mismatchSite expectedType,
debugNoteLoc
. mconcat
@ -405,6 +402,10 @@ renderTypeError e env src curPath = case e of
debugSummary note
]
where
unitHintMsg =
"\nNote: actions within a block must have type " <>
style Type2 (renderType' env expectedLeaf) <> ".\n"
unitHint = if giveUnitHint then unitHintMsg else ""
giveUnitHint = case expectedType of
Type.Ref' u | u == unitRef -> case mismatchSite of
Term.Let1Named' v _ _ -> Var.isAction v

View File

@ -11,13 +11,10 @@ x = 'f
```ucm
I found a value of type: (a1 ->{𝕖} a1) ->{𝕖} Nat
I found a value of type: (a1 ->{𝕖} a1) ->{𝕖} Nat
where I expected to find: (a -> 𝕣1) -> 𝕣
1 | f : (forall a . a -> a) -> Nat
2 | f id = id 0
3 |
4 | x = 'f
from right here:

View File

@ -33,11 +33,12 @@ ex2 = do
```ucm
I found a value of type: a ->{Stream a} Unit
I found a value of type: a ->{Stream a} Unit
where I expected to find: Unit
2 | Stream.emit
3 | 42
Note: actions within a block must have type Unit.
```
@ -92,15 +93,16 @@ ex4 =
```ucm
I found a value of type: [Nat]
I found a value of type: [Nat]
where I expected to find: Unit
2 | [1,2,3] -- no good
3 | ()
from right here:
2 | [1,2,3] -- no good
Note: actions within a block must have type Unit.
```

View File

@ -42,12 +42,10 @@ h0 req = match req with
```ucm
I found a value of type: Optional a1
I found a value of type: Optional a1
where I expected to find: Optional a
1 | h0 : Request {X t} b -> Optional b
2 | h0 req = match req with
3 | { X.x _ c -> _ } -> handle c with h0
from right here:

View File

@ -83,7 +83,7 @@ hmm = "Not, in fact, a number"
```ucm
I found a value of type: Text
I found a value of type: Text
where I expected to find: Nat
1 | hmm : .builtin.Nat