Repository navigation
Closed
Labels
bugSomething isn't working
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- 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.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
The following code gives (kernel) declaration has free variables 'getHexDigit?' on Lean 4.9.0-rc1.
def getHexDigit? (char : Char) : Option (Fin 16) :=
if char.toNat < 0x0030 then
none
else
let n := if char.toNat < 0xFF10 then char.toNat - 0x0030 else char.toNat - 0xFF10
if h : n < 10 then
some ⟨n, Nat.lt_trans h (by decide)⟩
else if n >= 17 then
let n := n - 7
if h : n < 16 then
some ⟨n, h⟩
else if n >= 32 then
let n := n - 32
if h : n < 16 then
some ⟨n, h⟩
else
none
else
none
else
noneRemoving the second let or the third let eliminates the problem.
Context
Discovered while updating lean4-unicode-basic to v4.9.0-rc1. Posted on Zulip.
Versions
Lean (version 4.9.0-rc1, arm64-apple-darwin23.5.0, commit be6c4894e0a6, Release)
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Reacted by François G. Dorais, SnO₂WMaN, Henrik Böving, Utensil, Lawrence Wu, Michael Stoll and Mauricio Collares
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
[-]Bug with ifs and lets[/-][+]Bug with nested ifs and lets[/+]llllvvuu commentedon Jun 7, 2024
I've minimized it to:
This is broken all the way back to Lean 4.0.0. Similarly, removing the
(char : Char)argument from OP's example causes it to break on 4.0.0.In either example, if there is an argument in the declaration header, the bug only shows up in f97a7d4 and later.
fgdorais commentedon Jun 8, 2024
Great insight! I thought let reassignments might be the issue but that was a red herring.
hwatheod commentedon Jun 8, 2024
I also found a
(kernel) declaration has free variablesissue involvingletwhich I minimized to the following:It also fails at version 4.0.0. I thought it might be related to this issue so I am adding it here.
llllvvuu commentedon Jun 8, 2024
Yup, same bug indeed, since
haveislet_fun, which plays the role of theditein the OP's example. Can remove all mvars but the lastOfNat:The
_uniq.4here looks suspicious:fix: kernel exception from fvars left from `?m a b` instantiation (#4410
kmill commentedon Jul 23, 2024
I do not think that this was fixed by #4410. The change in #4410 seems fine, but it does not fix the underlying issue in (I think!)
isDefEq.Here's another test case that's simpler still:
While #4110 makes some ill-formed metavariable assignments end up not mattering, they are still present. The issue seems to be that the OfNat instance metavariable for
0forgets to includeaas one of the let bindings it depends on.If you add well-formedness checks to
checkTypesAndAssignlike so, then you can see this reflected as an elaboration error, as "typeclass instance problem is stuck".Is there any justification in the PR for not zeta reducing being called a bug in this comment? It seems to me that
instantiateMVarsis not responsible for correcting for incorrect metavariable assignments, and I think a followup fix should change that comment.llllvvuu commentedon Jul 25, 2024
I had a similar theory prior to changing the fix: 625b45c (this implementation is not good but the idea was essentially to change
mkLambdaFVarsWithLetDepsbehavior to include let decls that come before the first argxs[0]:lean4/src/Lean/Meta/ExprDefEq.lean
Lines 390 to 420 in 93fa9c8
^Is this what you're referring to?
I backtracked on that idea because the existing behavior looked intentional / I couldn't be sure.
Kha commentedon Jul 25, 2024
@kmill Your test case is failing for me on "Mathlib stable" but not latest or nightly
Kha commentedon Aug 8, 2024
Closing until reconfirmation