leanprover / leanprover/lean4

Structure fails to compile when nested type parameters are defeq

Open
#9,898 2 comments 0 reactions 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

Prerequisites

Please put an X between the brackets as you perform the following steps:

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)
  1. 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.