Repository navigation
Conversation
…ed type Elaborating the discriminant never constrains the level metavariable (`Quoted` is `implicit_reducible`), so it survived into the generated `match_eq` hypothesis and made `match` generalization fail with "type of pattern variable 'match_eq✝' contains metavariables". Fixes leanprover-community#30.
The previous commit's transcription dropped the `isEscapedAntiquot` guard; this restores the file to exactly the tested content.
Covers the issue MWE (nested `match` in a `~q` branch) and the multi-discriminant variant where the `~q` pattern is not in the last position; both failed with "type of pattern variable 'match_eq✝' contains metavariables" before the fix.
…th master Upstream master bumped the toolchain past this branch (v4.36.0-rc2 -> v4.36.0 -> v4.37.0-rc1 in leanprover-community#179/leanprover-community#180), conflicting with the rc1->rc2 bump this branch carried from the fork's merge-base. Setting the branch's toolchain to master's makes the merge clean; the PR diff relative to the merge result is unchanged. Verified locally on leanprover/lean4:v4.37.0-rc1 (upstream master ad0c9f8 + this branch, toolchain conflict resolved to master's version): `lake build --wfail` passes (31 jobs, no warnings) and `lake test` passes (exit 0, incl. QqTest.matchLevelMVar).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #30.
Problem
A
~qpattern that is not in the last discriminant position of a multi-discriminantmatch— or whose branch contains anothermatch— failed withe.g. 0art0's example from the issue discussion:
Root cause
_qq_matchcreates two metavariables:argLvlExpr : Q(Level)andargTyExpr : Q(Quoted (.sort $argLvlExpr)), and elaborates the discriminant with expected typeQuoted $argTyExpr. SinceQuotedisimplicit_reducible(def Quoted (α : Expr) := Expr), unifying the expected and inferred types assignsargTyExpr(e.g. toExpr.sort 0for aQ(Prop)discriminant) but never constrainsargLvlExpr— checking the assignment only requires unfoldingQuotedtoExpr.With
pp.all, the surviving metavariable is visible as the universe argument of thematch_eqhypothesis:@Qq.QuotedDefEq (?m.56 x✝² ...) (Lean.Expr.sort Lean.Level.zero) x✝² .... It originates fromargLvlExpr, which flows into theQuotedDefEqtype elaborated inmakeMatchCode. As soon asmatchgeneralization needs to abstract that hypothesis (a nestedmatch, or the~qpattern in a non-final discriminant position), core rejects the unassigned metavariable.Fix
After unquoting the discriminant's type in
_qq_match, ifargLvlExpris still unassigned, determine the level from the unquoted type (getLevel) and quote it back (quoteLevel), mirroring whatunquoteLCtxalready does for let-bound local declarations (Qq/Macro.lean). If the level still contains metavariables or cannot be quoted in the current context, the previous behavior is kept.Tests
New
QqTest/matchLevelMVar.lean(picked up by theQqTest.+glob):matchinside a~qbranch);~qpattern in a non-final discriminant position (failed with the issue's exact error before the fix);#evalchecks that the matched functions still compute correctly.Verification
On the pinned toolchain (
leanprover/lean4:v4.36.0-rc2, masterb025662):master(both thepp.alldiagnosis above and the issue's error message).lake build --wfailpasses (30 jobs, no warnings);lake testpasses (exit 0; fullQqTestsuite, 59 jobs, including the new file).Qq/Match.leanmakes the new regression file fail with the issue's exact error.sorry/admitintroduced; the change is meta-only inQq/Match.leanplus tests.git hash-object) to the locally built and tested sources.Note: a
~qmatch under a sectionLevelvariable (e.g.{u : Level} {α : Q(Type u)}discriminants) hits a separate pre-existingmaximum recursion depthfailure that is unchanged by this fix (reproduces identically on unmodifiedmaster); I did not investigate it here.Branch note: the branch is based on my fork's master (
859a214), whose tree is identical to upstreamb025662; the diff is exactlyQq/Match.leanand the newQqTest/matchLevelMVar.lean. (Three commits because the file upload API is per-file and one transcription slip in the first commit was fully corrected in the second; the final tree is hash-verified. Feel free to squash.)