leanprover / leanprover/lean4

`sizeOf` generation failure on higher-order nested types

Open
#11,828 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

When defining certain kinds of nested inductive types, lean may throw a kernel error related to auxiliary theorems produced when generating the SizeOf instance.

Steps to Reproduce
inductive Higher (f : Type → Type) (A : Type) where
  | c_higher : f A → Higher f A

inductive Bar where
  | bar : Higher List Bar → Bar

Expected behavior: No error

Actual behavior:

(kernel) application type mismatch
  Eq.trans (congrArg (Nat.add 1) (Bar._sizeOf_3_eq a✝))
    (Eq.symm (Higher.c_higher.sizeOf_spec List Bar (fun a => List._sizeOf_inst a) Bar._sizeOf_inst a✝))
argument has type
  1 + sizeOf a✝ = sizeOf (Higher.c_higher List Bar a✝)
but function has type
  Nat.add 1 (sizeOf a✝) = sizeOf (Higher.c_higher List Bar a✝) →
    Nat.add 1 (Bar._sizeOf_3 a✝) = sizeOf (Higher.c_higher List Bar a✝)
Versions

Lean 4.28.0-nightly-2025-12-28
Target: x86_64-unknown-linux-gnu

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 Higher/List/Bar reproducer against the reported Lean nightly version and inspect the SizeOf instance generation and auxiliary theorem error. Trace the failing application involving Bar._sizeOf_3_eq and Higher.c_higher.sizeOf_spec; done means the example elaborates without the kernel type-mismatch error.

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.