Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ error ] Improve error messages for Delay &co #3037

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Idris/Parser.idr
Original file line number Diff line number Diff line change
Expand Up @@ -946,16 +946,20 @@ mutual
lazy : OriginDesc -> IndentInfo -> Rule PTerm
lazy fname indents
= do tm <- bounds (decorate fname Typ (exactIdent "Lazy")
*> simpleExpr fname indents)
*> simpleExpr fname indents
<* mustFailBecause "Lazy only takes one argument" (continue indents >> simpleExpr fname indents))
pure (PDelayed (boundToFC fname tm) LLazy tm.val)
<|> do tm <- bounds (decorate fname Typ (exactIdent "Inf")
*> simpleExpr fname indents)
*> simpleExpr fname indents
<* mustFailBecause "Inf only takes one argument" (continue indents >> simpleExpr fname indents))
pure (PDelayed (boundToFC fname tm) LInf tm.val)
<|> do tm <- bounds (decorate fname Data (exactIdent "Delay")
*> simpleExpr fname indents)
*> simpleExpr fname indents
<* mustFailBecause "Delay only takes one argument" (continue indents >> simpleExpr fname indents))
pure (PDelay (boundToFC fname tm) tm.val)
<|> do tm <- bounds (decorate fname Data (exactIdent "Force")
*> simpleExpr fname indents)
*> simpleExpr fname indents
<* mustFailBecause "Force only takes one argument" (continue indents >> simpleExpr fname indents))
pure (PForce (boundToFC fname tm) tm.val)

binder : OriginDesc -> IndentInfo -> Rule PTerm
Expand Down
7 changes: 7 additions & 0 deletions src/Libraries/Text/Parser/Core.idr
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ export %inline
bounds : Grammar state tok c ty -> Grammar state tok c (WithBounds ty)
bounds = Bounds

export
mustFailBecause :
String ->
Grammar state tok True ty -> Grammar state tok False Unit
mustFailBecause msg p
= (bounds p >>= \res => fatalLoc {c=False} res.bounds msg) <|> pure ()

export %inline
position : Grammar state tok False Bounds
position = Position
Expand Down
2 changes: 1 addition & 1 deletion tests/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ idrisTestsError = MkTestPool "Error messages" [] Nothing
"perror011", "perror012", "perror013", "perror014", "perror015",
"perror016", "perror017", "perror018", "perror019", "perror020",
"perror021", "perror022", "perror023", "perror024", "perror025",
"perror026", "perror027", "perror028"]
"perror026", "perror027", "perror028", "perror029"]

idrisTestsInteractive : TestPool
idrisTestsInteractive = MkTestPool "Interactive editing" [] Nothing
Expand Down
13 changes: 13 additions & 0 deletions tests/idris2/perror029/DelayParse.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module DelayParse

public export
data MyStream : Type where
(::) : (anA : a)
-> (nextA : a -> a)
-> Inf MyStream
-> MyStream

public export
go : a -> (a -> a) -> MyStream
go initA fn =
MyStream.(::) initA fn (Delay (fn initA) fn)
11 changes: 11 additions & 0 deletions tests/idris2/perror029/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1/1: Building DelayParse (DelayParse.idr)
Error: Delay only takes one argument.

DelayParse:13:44--13:46
09 |
10 | public export
11 | go : a -> (a -> a) -> MyStream
12 | go initA fn =
13 | MyStream.(::) initA fn (Delay (fn initA) fn)
^^

3 changes: 3 additions & 0 deletions tests/idris2/perror029/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rm -rf build

$1 --no-color --console-width 0 --check DelayParse.idr
Loading