Dependent `match` fails with `unknown metavariable` using custom `DoOps`
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 47/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Área
- compilers
Línea de trabajo
Start with src/Lean/Elab/BuiltinDo/Match.lean, especially elabDoSeqWithRefinedType, and compare its metavariable scope handling with the custom DoOps example in tests/elab/doNotationPluggableOps.lean. Reproduce the failure with the linked Lean Web example and trace how Term.mkInstMVar requests survive withNewMCtxDepth. Done means the dependent match elaborates for the constrained custom monad.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Prerequisites
- Searched existing issues and pull requests; no matching report found.
- Reduced to a standalone example importing only
Lean(no Mathlib or Batteries). - Reproduced on the latest nightly,
4.37.0-nightly-2026-11-18, using Lean Web.
Description
A custom do notation using elabDoWith fails on match (dependent := true) when its mkMonadApp creates a typeclass metavariable with Term.mkInstMVar.
The failure appears to come from elabDoSeqWithRefinedType. It calls mkMonadApp on a fresh result-type metavariable inside withNewMCtxDepth. The temporary metavariables are discarded afterwards, but pending instance requests registered by Term.mkInstMVar remain in the term-elaboration state. Retrying such a request then refers to a discarded metavariable.
Context
The setup follows the custom DoOps and elabDoWith pattern in core's pluggable-operations test,
but uses a constrained monad with an Inhabited instance argument.
Steps to Reproduce
Open this example in Lean Web (nightly).
import Lean
open Lean Lean.Parser Lean.Meta Lean.Elab Lean.Elab.Do
def InhabitedId (α : Type) [Inhabited α] := α
def inhabitedOps : DoOps := { DoOps.default with
mkPureApp _ e := pure e
mkBindApp _ _ e k := pure (mkApp k e)
isPureApp? _ := none
splitMonadApp? type := do
let .app (.app m α) _ := type.consumeMData | return none
unless m.isConstOf ``InhabitedId do return none
return some ({ m, u := .zero, v := .zero }, α)
mkMonadApp α := do
let inst ← Term.mkInstMVar (mkApp (mkConst ``Inhabited [.succ .zero]) α)
return mkApp2 (← read).monadInfo.m α inst
}
syntax (name := idoKind) "ido " doSeq : term
@[term_elab idoKind] def elabIDo : Term.TermElab := fun stx expectedType? => do
let `(ido $seq) := stx | throwUnsupportedSyntax
elabDoWith inhabitedOps seq expectedType?
example (n : Nat) : InhabitedId (Fin (n + 1)) := ido
match (dependent := true) n with
| 0 => return (0 : Fin 1)
| k + 1 => return Fin.last (k + 1)
Expected behavior: The example elaborates. The corresponding example with regular do and Id succeeds:
example (n : Nat) : Id (Fin (n + 1)) := do
match (dependent := true) n with
| 0 => return (0 : Fin 1)
| k + 1 => return Fin.last (k + 1)
Actual behavior: The zero branch produces an unknown metavariable error.
Versions
- Lean Web,
lean-nightly:#eval Lean.versionStringreports"4.37.0-nightly-2026-11-18". - Also reproduced locally on Lean
4.36.0and4.35.0, on macOS 26.6.2 (arm64).
Impact
This prevents dependent matching in custom do notation for constrained monads with a typeclass argument on the result type.
- Lenguaje dominante
- Lean
- Estrellas
- 10.3k
- Forks
- 1.1k
- Merge medio
- 19 h 8 min
- PR fusionados (30 d)
- 421
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de leanprover/lean4
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
leanprover/lean4#16681 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
leanprover/lean4#16305 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
leanprover/lean4#16299 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
leanprover/lean4#16257 ·
Los mantenedores suelen responder en 1 día
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
leanprover/lean4#15683 ·
Los mantenedores suelen responder en 1 día
Todos los issues de leanprover/lean4
Issues similares
-
bug fixed form parser medium priority tokenizer
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 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 refusedPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
sagemathinc/sagebrush#1683 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
microts: a model local that every branch assigns raises unused_assignments in the generated RustAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
pocket-stack/pocketjs#756 ·