`joinTypes?` erases a join point parameter that carries data when another branch returns a type
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- compilers
Research direction
The bug is in joinTypes? in Lean/Compiler/LCNF/Types.lean, where the join point parameter becomes erased when one branch's type is erased. Start by reproducing with the minimal h/get1 example in a file run through lean, then read the comment on compatibleTypes that the issue references. Done means the example prints 8, the decide and #eval results agree, and the existing test suite shows no new failures.
Written by the indexing model from the issue text.
Description
Prerequisites
- Check that your issue is not already filed: https://github.com/leanprover/lean4/issues
- Reduce the issue to a minimal, self-contained, reproducible test case.
- Test your test case against the latest nightly release.
- When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
No, the kernel gets it right. Butnative_decidecan proveget1 3 = 0next todecideprovingget1 3 = 8.
Description
If a match that isn't in tail position returns a type in one branch and a value in the other, the compiled code loses the value:
def T (b : Bool) : Type 1 := cond b Type (ULift.{1} Nat)
def h (b : Bool) (n : Nat) : T b × List Nat := (match b with
| true => (Nat : Type)
| false => (⟨n + 5⟩ : ULift.{1} Nat), [n, n+1, n*2, n*n, n+5, n+6, n+7, n+8, n*3, n*4, n*5, n*6, n*7, n*8, n*9, n+10, n+11, n+12, n+13])
def get1 (n : Nat) : Nat := (h false n).1.down
example : get1 3 = 8 := by decide
#eval get1 3
#eval get1 3 prints 0, while decide proves it's 8. h needs the long list, otherwise it gets inlined and the bug goes away.
joinTypes? in Lean/Compiler/LCNF/Types.lean returns ◾ as soon as one side is erased. Here one branch has type Type and the other ULift Nat, so the join point parameter ends up erased and the value from the false branch is dropped.
Steps to Reproduce
lean jointypes.lean
Expected behavior: prints 8
Actual behavior: prints 0
Possible fix
Return ◾ only if both sides are erased:
- if a.isErased || b.isErased then
- return erasedExpr -- See comment at `compatibleTypes`.
+ if a.isErased && b.isErased then
+ return erasedExpr
+ else if a.isErased || b.isErased then
+ return mkConst ``lcAny
With this the example prints 8, and make test has no new failures.
Versions
Lean (version 4.37.0-nightly-2026-11-11, x86_64-unknown-linux-gnu, commit 80799ea6aeb2f73f1cf60cabe9db80e409cb0c3a, Release). Also nightly-2026-10-30. Linux.
Additional Information
Assisted-by: Elenchus(claude-code):opus-5.5
- Dominant language
- Lean
- Stars
- 10.3k
- Forks
- 1.1k
- Avg merge
- 19h 8m
- Merged PRs (30d)
- 421
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from leanprover/lean4
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
leanprover/lean4#16305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
leanprover/lean4#16299 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16257 ·
Maintainers usually reply within 1 day
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
leanprover/lean4#15683 ·
Maintainers usually reply within 1 day
All issues in leanprover/lean4
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
swc-project/swc-next-issues#817 ·
-
Magma mode: div:=, mod:= and the other keyword assignments (join:=, meet:=, diff:=, sdiff:=, and:=, or:=, xor:=) are refusedPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sagemathinc/sagebrush#1683 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
microts: a model local that every branch assigns raises unused_assignments in the generated RustOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
pocket-stack/pocketjs#756 ·
-
bot-triaged module: aotinductor module: compile-time module: inductor module: performance module: rocm oncall: export oncall: pt2 triaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day