Kernel: nested-inductive auxiliary name `_nested_1` can be referenced by user declarations when the nested type's name is anonymous/macro-scoped
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
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- compilers
Línea de trabajo
Start with src/kernel/inductive.cpp, especially elim_nested_inductive_fn::replace_if_nested and check_no_nested_aux, which the issue identifies as the name creation and validation paths. Reproduce the case with the supplied Lean file, then trace how anonymous and macro-scoped names are minted and checked. Done means addDeclCore rejects the reproduced declaration with an unknown constant error.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Prerequisites
- 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
- When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
(Not believed to be a soundness bug: no inconsistency was derived.)
Description
The kernel accepts an inductive T whose constructor T.bad : _nested_1 → T refers to a
constant that does not exist, and stores T.bad with a different type than declared.
When T is nested (T.mk : J T → T), the kernel replaces J T by an auxiliary type it
names _nested + J and declares that name in a temporary environment. User declarations
are kept from naming these auxiliaries by check_no_nested_aux, which rejects any constant
whose name has the prefix _nested. But if J's name is anonymous (as here) or
macro-scoped (e.g. [email protected]._hyg.1, which macro-generated inductives have), the minted name is
_nested_1 or [email protected]._hyg.1. Neither has _nested as a prefix, so the user can
name it, it resolves to the auxiliary during checking, and the restore pass then rewrites it
to J T.
Reachable through addDecl or a crafted .olean (the elaborator does not create an
anonymous inductive). No inconsistency was derived; the environment ends up containing a
constructor whose declared type mentioned a constant that is declared nowhere.
Steps to Reproduce
Save as NestedAuxUndeclaredConstant.lean and run lean NestedAuxUndeclaredConstant.lean:
import Lean
open Lean Elab Command
-- inductive <anonymous> (α : Type) : Type | mk : α → <anonymous> α
def declJ : Declaration := .inductDecl [] 1 [{
name := .anonymous, type := .forallE `α (.sort 1) (.sort 1) .default,
ctors := [{ name := `AnonMk,
type := .forallE `α (.sort 1) (.forallE `a (.bvar 0) (.app (.const .anonymous []) (.bvar 1)) .default) .implicit }] }] false
-- inductive T : Type | mk : <anonymous> T → T | bad : _nested_1 → T
def declT : Declaration := .inductDecl [] 0 [{
name := `T, type := .sort 1,
ctors := [{ name := `T.mk, type := .forallE `x (.app (.const .anonymous []) (.const `T [])) (.const `T []) .default },
{ name := `T.bad, type := .forallE `x (.const `_nested_1 []) (.const `T []) .default }] }] false
#eval show CommandElabM Unit from do
let .ok env := (← getEnv).addDeclCore 0 512 declJ none | throwError "J rejected"
match env.addDeclCore 0 512 declT none with
| .error e => logInfo m!"T rejected: {e.toMessageData {}}"
| .ok env =>
logInfo m!"T ACCEPTED, although its constructor T.bad mentions the undeclared constant _nested_1"
logInfo m!"_nested_1 declared afterwards? {(env.find? `_nested_1).isSome}"
logInfo m!"T.bad stored as: {(env.find? `T.bad).get!.type}"
Expected output if the kernel were correct: T rejected: unknown constant '_nested_1'. Actual output (Lean 4.35.0, and 4.37.0-nightly-2026-11-14, commit 62e0cf0):
Actual behavior:
T ACCEPTED, although its constructor T.bad mentions the undeclared constant _nested_1
_nested_1 declared afterwards? false
T.bad stored as: [anonymous] T → T
Versions
Lean 4.35.0, 4.36.0 (arm64-apple-darwin, macOS / Darwin 25.6.0), and 4.37.0-nightly-2026-11-14 (commit 62e0cf0).
Additional Information
Where it is in the kernel (leanprover/lean4 master, commit e048ef7, 2026-11-16):
src/kernel/inductive.cpp
-
Line 1093,
elim_nested_inductive_fn::replace_if_nested:name auxJ_name = mk_unique_name(*g_nested + J_name);mk_unique_name(line 989) appends an index withappend_after, which for an anonymous
J_nameproduces the atomic name_nested_1, and for a macro-scoped name puts the index
before the macro scopes. Neither result is under the prefix_nested. -
Lines 1210-1219,
check_no_nested_aux: testsis_prefix_of(*g_nested, const_name(e)),
which is false for these names, so the user's reference is not rejected.
Possible fix: after minting auxJ_name, check is_prefix_of(*g_nested, auxJ_name) and, if it
fails, mint the name under a fixed prefix such as _nested._aux instead.
- 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 ·