leanprover / leanprover/lean4

Diamond import (plain + public meta import) causes lcAny compilation-type mismatch error.

Open
#14,561 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
Description

Importing the same module both plainly (import) and via public meta import in the same file triggers a Compilation failed, locally inferred compilation type ... differs from type lcAny error on a fully concrete, non-generic declaration. The message suggests adding @[expose], but the flagged type is a structure.

Context

Found while upgrading a project from Lean 4.29.1 to 4.31.0: a public meta import was added to fix a "not accessible here" meta-visibility error, and that broke an unrelated declaration elsewhere in the same file with this message. The repro below isolates the pattern with no project-specific code.

Steps to reproduce

lean-toolchain:

leanprover/lean4:v4.31.0

lakefile.toml:

name = "minimize"
defaultTargets = ["Minimize"]

[[lean_lib]]
name = "Minimize"

Minimize/Bundle.lean:

module
public structure Bundle where
  Ident : Type

Minimize.lean:

module
import Minimize.Bundle
public meta import Minimize.Bundle

abbrev Expression : Bundle := { Ident := Nat }

structure Container where
  f : List Expression.Ident

def v : Container := ⟨[]⟩

Run lake build.

Actual behavior

error: Minimize.lean:10:4: Compilation failed, locally inferred compilation type
  Nat
differs from type
  lcAny
that would be inferred in other modules. This usually means that a type `def` involved with the mentioned declarations needs to be `@[expose]`d. This is a current compiler limitation for `module`s that may be lifted in the future.

Reported on the f : List Expression.Ident field of Container (line 10). Removing either import line makes it disappear; only the combination of both triggers it.

Expected behavior

The build should succeed.

Version

Lean (version 4.31.0, x86_64-unknown-linux-gnu, commit 68218e876d2a38b1985b8590fff244a83c321783, Release)

Lean Nightly changes

Also reproduces on leanprover/lean4-nightly:nightly-2026-07-26 (Lean 4.34.0-nightly, commit b4fb9a75e9e1cfc8d936ee6a574a8b537662698b). On this nightly the error additionally fires one declaration earlier, on abbrev Expression : Bundle := { Ident := Nat } (line 7):

error: Minimize.lean:7:0: Compilation failed, locally inferred compilation type
  List Nat
differs from type
  List lcAny
that would be inferred in other modules. This usually means that a type `def` involved with the mentioned declarations needs to be `@[expose]`d. This is a current compiler limitation for `module`s that may be lifted in the future.

in addition to the original error on Container (line 10).

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

Start with the minimal files Minimize/Bundle.lean and Minimize.lean, then run lake build using the reported Lean toolchain or nightly version. Investigate how the plain import and public meta import affect compilation-type inference for Expression and Container; done means the reproducer builds without the lcAny mismatch.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.