Skip to content

Commit ae7b5f0

Browse files
committed
[ fix ] Handle PLet in setLinear
1 parent acde1c9 commit ae7b5f0

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

CHANGELOG_NEXT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ should target this file (`CHANGELOG_NEXT`).
3636
typically happens when a numeric literal or an ambiguous name appears in an
3737
`impossible` clause.
3838
* Do not inline `Core.sequence`, because it is recursively defined.
39+
* Fixed incorrect argument multiplicity when using an as-pattern (#3687).
3940

4041
### Building/Packaging changes
4142

src/TTImp/ProcessDef.idr

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,17 @@ findLinear top bound rig tm
310310
findLinArg _ _ [] = pure []
311311

312312
setLinear : List (Name, RigCount) -> Term vars -> Term vars
313-
setLinear vs (Bind fc x b@(PVar {}) sc)
314-
= case lookup x vs of
315-
Just c' => Bind fc x (setMultiplicity b c') (setLinear vs sc)
316-
_ => Bind fc x b (setLinear vs sc)
317-
setLinear vs (Bind fc x b@(PVTy {}) sc)
318-
= case lookup x vs of
319-
Just c' => Bind fc x (setMultiplicity b c') (setLinear vs sc)
320-
_ => Bind fc x b (setLinear vs sc)
313+
setLinear vs (Bind fc x b sc)
314+
= do let b' = case guard (isPatternBinder b) *> lookup x vs of
315+
Just c' => setMultiplicity b c'
316+
Nothing => b
317+
Bind fc x b' (setLinear vs sc)
318+
where
319+
isPatternBinder : Binder a -> Bool
320+
isPatternBinder (PVar {}) = True
321+
isPatternBinder (PVTy {}) = True
322+
isPatternBinder (PLet {}) = True
323+
isPatternBinder _ = False
321324
setLinear vs tm = tm
322325

323326
-- Combining multiplicities on LHS:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data X : Nat -> Type where
2+
XS : X (S n)
3+
4+
f : () -> (n : Nat) -> X n -> Nat
5+
f b@() .(S m) XS = ?hole
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1/1: Building Issue3687 (Issue3687.idr)
2+
Main> b : ()
3+
0 m : Nat
4+
------------------------------
5+
hole : Nat
6+
Main>
7+
Bye for now!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:t hole

tests/idris2/linear/linear018/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
. ../../../testutils.sh
2+
3+
idris2 Issue3687.idr < input

0 commit comments

Comments
 (0)