Skip to content

Commit 586ea55

Browse files
authored
fix: enforce choice invariant in ElimDeadBranches (#11398)
This PR fixes a broken invariant in the choice nodes of ElimDeadBranches. Closes: #11389 and #11393
1 parent a4f9a79 commit 586ea55

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Lean/Compiler/LCNF/ElimDeadBranches.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ choice node further down the tree.
8484
partial def addChoice (env : Environment) (vs : List Value) (v : Value) : List Value :=
8585
match vs, v with
8686
| [], v => [v]
87-
| v1@(ctor i1 _ ) :: cs, ctor i2 _ =>
87+
| v1@(ctor i1 vs1) :: cs, ctor i2 vs2 =>
8888
if i1 == i2 then
89-
(merge env v1 v) :: cs
89+
ctor i1 (Array.zipWith (merge env) vs1 vs2) :: cs
9090
else
9191
v1 :: addChoice env cs v
92-
| _, _ => panic! "invalid addChoice"
92+
| _, _ => panic! s!"invalid addChoice {repr v} into {repr vs}"
9393

9494
/--
9595
Merge two values into one. `bot` is the neutral element, `top` the annihilator.

tests/lean/run/11389.lean

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/-!
2+
Regression tests for #11393 and #11389
3+
-/
4+
5+
#guard_msgs in
6+
open System in
7+
def loadModuleContent : IO Unit := do
8+
let lakefile : FilePath := "lakefile.lean"
9+
10+
if !(← lakefile.pathExists) then
11+
IO.println "nope"
12+
13+
discard <| IO.Process.output {
14+
cmd := "ls", args := #[]
15+
}
16+
17+
#guard_msgs in
18+
def test (s : String) : IO Bool := do
19+
if s.startsWith "x" then return true
20+
let b ← IO.Process.output {cmd := "true", args := #[]}
21+
return b.exitCode == 0

0 commit comments

Comments
 (0)