Skip to content

Commit d289ed6

Browse files
committed
[ fix #1887 ] Parse _ <- as DoBind instead of DoBinPat
1 parent 2428b35 commit d289ed6

File tree

7 files changed

+40
-3
lines changed

7 files changed

+40
-3
lines changed

src/Idris/Parser.idr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,13 +843,13 @@ mutual
843843

844844
validPatternVar : Name -> EmptyRule ()
845845
validPatternVar (UN n)
846-
= if lowerFirst n then pure ()
847-
else fail "Not a pattern variable"
846+
= unless (lowerFirst n || n == "_") $
847+
fail "Not a pattern variable"
848848
validPatternVar _ = fail "Not a pattern variable"
849849

850850
doAct : OriginDesc -> IndentInfo -> Rule (List PDo)
851851
doAct fname indents
852-
= do b <- bounds (do n <- bounds name
852+
= do b <- bounds (do n <- bounds (name <|> UN "_" <$ symbol "_")
853853
-- If the name doesn't begin with a lower case letter, we should
854854
-- treat this as a pattern, so fail
855855
validPatternVar n.val

src/Libraries/Text/Parser.idr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,8 @@ public export
226226
when : Bool -> Lazy (Grammar state token False ()) -> Grammar state token False ()
227227
when True y = y
228228
when False y = pure ()
229+
230+
public export
231+
%inline
232+
unless : Bool -> Lazy (Grammar state token False ()) -> Grammar state token False ()
233+
unless = when . not

tests/Main.idr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ idrisTestsBasic = MkTestPool "Fundamental language features" [] Nothing
4141
"basic046", "basic047", "basic049", "basic050",
4242
"basic051", "basic052", "basic053", "basic054", "basic055",
4343
"basic056", "basic057", "basic058", "basic059", "basic060",
44+
"basic061",
4445
"interpolation001", "interpolation002"]
4546

4647
idrisTestsCoverage : TestPool

tests/idris2/basic061/IgnoreDo.idr

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module IgnoreDo
2+
3+
bound : Maybe () -> Maybe b -> Maybe b
4+
bound m n = do
5+
x <- m
6+
n
7+
8+
ignored : Maybe () -> Maybe b -> Maybe b
9+
ignored m n = do
10+
_ <- m
11+
n
12+
13+
seqd : Maybe () -> Maybe b -> Maybe b
14+
seqd m n = do
15+
m
16+
n

tests/idris2/basic061/expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1/1: Building IgnoreDo (IgnoreDo.idr)
2+
IgnoreDo> IgnoreDo.bound : Maybe () -> Maybe b -> Maybe b
3+
bound m n = m >>= (\x => n)
4+
IgnoreDo> IgnoreDo.ignored : Maybe () -> Maybe b -> Maybe b
5+
ignored m n = m >>= (\_ => n)
6+
IgnoreDo> IgnoreDo.seqd : Maybe () -> Maybe b -> Maybe b
7+
seqd m n = m >> Delay n
8+
IgnoreDo> Bye for now!

tests/idris2/basic061/input

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:printdef bound
2+
:printdef ignored
3+
:printdef seqd
4+
:q

tests/idris2/basic061/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rm -rf build
2+
3+
$1 --no-color --console-width 0 --no-banner IgnoreDo.idr < input

0 commit comments

Comments
 (0)