leanprover / leanprover/lean4

"Unknown free variable" during isDefEq for delayed assignments when synthetic opaque assignable

Open
#3,393 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Description

When synthetic opaque metavariables are assignable, it is possible to get an "unknown free variable" error from isDefEq.

Context

Zulip discussion where this was reported.

Steps to Reproduce

This reports "unknown free variable '_fvar.2067'" at refine:

example : (fun _ : Nat => 2) = (fun _ => 2) := by
  refine (?_ : (fun n : Nat => ?e) = _)
  rfl

Expected behavior: This succeeds, or at least gives a type mismatch error.

Versions
#eval Lean.versionString -- "4.6.0-rc1"
Additional Information

It appears that Lean.Meta.expandDelayedAssigned? is causing the type of a metavariable to leak an fvar from its local context. In mkAppRange (mkMVar mvarIdPending) fvars.size tArgs.size tArgs, the metavariable mvarIdPending might have a type that's not compatible with the current local context. In the above example, ?e has a type that depends on n.

For the test, it seems to be important that the type of the equality in the type ascription is a metavariable. Replacing the RHS _ of the equality with (_ : Nat → Nat) suppresses the issue.

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example at refine, then inspect Lean.Meta.expandDelayedAssigned? and the mkAppRange (mkMVar mvarIdPending) fvars.size tArgs.size tArgs path described in the issue. Trace how the metavariable type can retain an out-of-scope local variable, and verify the fix with the supplied reproduction, where elaboration should succeed or report a type mismatch instead of an unknown free variable.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.