Skip to content

Commit

Permalink
[ parser ] Improve errors on incorrect list of determining parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
spcfox committed Feb 13, 2025
1 parent 4b2bfe4 commit 8fd6f52
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/Idris/Parser.idr
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,10 @@ dataOpt : OriginDesc -> Rule DataOpt
dataOpt fname
= (decorate fname Keyword (exactIdent "noHints") $> NoHints)
<|> (decorate fname Keyword (exactIdent "uniqueSearch") $> UniqueSearch)
<|> (do decorate fname Keyword (exactIdent "search")
SearchBy <$> some (decorate fname Bound name))
<|> (do b <- bounds $ decorate fname Keyword (exactIdent "search")
det <- mustWorkBecause b.bounds "Expected list of determining parameters" $
some (decorate fname Bound name)
pure $ SearchBy det)
<|> (decorate fname Keyword (exactIdent "external") $> External)
<|> (decorate fname Keyword (exactIdent "noNewtype") $> NoNewtype)

Expand Down Expand Up @@ -1766,7 +1768,10 @@ parameters {auto fname : OriginDesc} {auto indents : IndentInfo}
cons <- constraints fname indents
n <- decorate fname Typ name
params <- many ifaceParam
det <- optional $ decoratedSymbol fname "|" *> sepBy1 (decoratedSymbol fname ",") (decorate fname Bound name)
det <- optional $ do
b <- bounds $ decoratedSymbol fname "|"
mustWorkBecause b.bounds "Expected list of determining parameters" $
sepBy1 (decoratedSymbol fname ",") (decorate fname Bound name)
decoratedKeyword fname "where"
dc <- optional (recordConstructor fname)
body <- blockAfter col (topDecl fname)
Expand Down
2 changes: 2 additions & 0 deletions tests/idris2/data/data004/EmptySearch.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data X : Type where
[search]
8 changes: 8 additions & 0 deletions tests/idris2/data/data004/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1/1: Building EmptySearch (EmptySearch.idr)
Error: Expected list of determining parameters.

EmptySearch:2:4--2:10
1 | data X : Type where
2 | [search]
^^^^^^

3 changes: 3 additions & 0 deletions tests/idris2/data/data004/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ../../../testutils.sh

check EmptySearch.idr
2 changes: 2 additions & 0 deletions tests/idris2/data/record022/EmptySearch.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
record R where
[search]
8 changes: 8 additions & 0 deletions tests/idris2/data/record022/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1/1: Building EmptySearch (EmptySearch.idr)
Error: Expected list of determining parameters.

EmptySearch:2:4--2:10
1 | record R where
2 | [search]
^^^^^^

3 changes: 3 additions & 0 deletions tests/idris2/data/record022/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ../../../testutils.sh

check EmptySearch.idr
6 changes: 3 additions & 3 deletions tests/idris2/interface/interface034/expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1/1: Building Main (Main.idr)
Error: Expected end of input.
Error: Expected list of determining parameters.

Main:1:1--1:10
Main:1:17--1:18
1 | interface Iface | where
^^^^^^^^^
^

0 comments on commit 8fd6f52

Please sign in to comment.