Structure fails to compile when nested type parameters are defeq
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
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
Kernel error from a specific kind of structure declaration.
Context
I was stubbing out some code (a structure S containing two arrays of a type parametrized by S and two separately defined but defeq other types, analogous to A and B below) when I noticed this.
Steps to Reproduce
/- MWE -/
abbrev A := Nat -- the specific type doesn't matter as long as they're the same
abbrev B := Nat
-- can also replace `T` with e.g. `Prod`,
-- and `Option` with e.g. `Array`
structure T (α β : Type)
structure S where
x : Option (T A S)
y : Option (T B S)
- On the current nightly build (nightly-2025-08-13), 4.22.0-rc4, and 4.21.0, a kernel error is produced:
(kernel) declaration type mismatch, 'S._sizeOf_3_eq' has type
∀ (x : Option (T B S)), (fun t => S._sizeOf_2 t = sizeOf t) x
but it is expected to have type
∀ (x : Option (T B S)), S._sizeOf_3 x = sizeOf x
Expected behavior: [Clear and concise description of what you expect to happen]
I think this should compile? It does if I remove Option, replace T A S with T B S, or insert the values of A and B directly.
Actual behavior: [Clear and concise description of what actually happens]
See above.
Versions
Lean 4.21.0
Target: arm64-apple-darwin23.6.0 macOS
MacOS Sonoma 14.1
Additional Information
N/A
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the minimal self-contained structure example against the listed Lean versions and confirm the generated kernel error. Start from the nested S declaration and the generated _sizeOf_3_eq mismatch; done means the example compiles without this kernel error while preserving the reported behavior distinctions.
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
- 42/100