Repository navigation
fix: kernel exception from fvars left from ?m a b instantiation - #4410
Conversation
aaaee8c to
dcfd93b
Compare
mkLambdaFVarsWithLetDeps handles lets before lambdasmkLambdaFVarsWithLetDeps, handle lets before lambdas
|
Hello @llllvvuu and thanks for your first contribution to lean! The Good issue reports, including good minimized test cases, and contributions to less central components (error messages, leaf tactics, etc.) are a good way to build expertise, reputation and trust, before high-risk areas of the code. |
3f03a5b to
f07661f
Compare
|
No worries, it's not a big deal to me whether this particular patch + test case is what gets merged. I'm glad if it's of some use. |
|
Mathlib CI status (docs):
|
mkLambdaFVarsWithLetDeps, handle lets before lambdas?m a b c; add (useZeta := true)
?m a b c; add (useZeta := true)?m a b c; add (useZeta := true)
8d77259 to
f73d07e
Compare
f73d07e to
80affa4
Compare
80affa4 to
c365a0e
Compare
?m a b c; add (useZeta := true)?m a b instantiation
|
I just changed the fix/description, new one is just changing a flag. It still doesn't achieve not touching central modules, but I hope it sheds some more light on the issue (test case further minimized as well). |
The following example raises `error: (kernel) declaration has free
variables '_example'`:
```lean
example: True → Nat :=
let a : Nat := Nat.zero
fun (_ : True) =>
let b : Nat := Nat.zero
(fun (_ : a = b) => 0) (Eq.refl a)
```
During elaboration of `0`, `elabNumLit` creates a synthetic mvar
`?_uniq.16` which gets abstracted by `elabFun` to `?_uniq.16 :=
?_uniq.50 _uniq.6 _uniq.12`. The `isDefEq` to `instOfNatNat 0` results
in:
```
?_uniq.50 :=
fun ([email protected]._hyg.13 : True) =>
let b : Nat := Nat.zero
fun ([email protected]._hyg.23 : Eq.{1} Nat _uniq.4 b) =>
instOfNatNat 0
```
This has a free variable `_uniq.4` which was `a`.
When the application of `?_uniq.50` to `#[leanprover#2, #0]` is instantiated, the
`let b : Nat := Nat.zero` blocks the beta-reduction and `_uniq.4`
remains in the expression.
fix: add `(useZeta := true)` here:
https://github.com/leanprover/lean4/blob/ea46bf2839ad1c98d3a0c3e5caad8a81f812934c/src/Lean/MetavarContext.lean#L567
c365a0e to
12395b2
Compare
Looks good. We will merge it. Thanks! |
This linter was silently not doing anything until leanprover/lean4#4410 was fixed, and now it is working so a backlog of warnings needed to be addressed. Some were addressed here: #13680. The warnings in this PRs are false positives (leanprover-community/batteries#428?), but a workaround is put in place. Co-authored-by: L Lllvvuu <[email protected]>
This linter was silently not doing anything until leanprover/lean4#4410 was fixed, and now it is working so a backlog of warnings needed to be addressed. Some were addressed here: #13680. The warnings in this PRs are false positives (leanprover-community/batteries#428?), but a workaround is put in place. Co-authored-by: L Lllvvuu <[email protected]>
Closes #4375
The following example raises
error: (kernel) declaration has free variables '_example':During elaboration of
0,elabNumLitcreates a synthetic mvar?_uniq.16which gets abstracted byelabFunto?_uniq.16 := ?_uniq.50 _uniq.6 _uniq.12. TheisDefEqtoinstOfNatNat 0results in:This has a free variable
_uniq.4which wasa.When the application of
?_uniq.50to#[#2, #0]is instantiated, thelet b : Nat := Nat.zeroblocks the beta-reduction and_uniq.4remains in the expression.fix: add
(useZeta := true)here:lean4/src/Lean/MetavarContext.lean
Line 567 in ea46bf2