-
Notifications
You must be signed in to change notification settings - Fork 808
@[init] declarations are sometimes run in the wrong order #10175
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
@[init] declarations are not run in dependency order but by order on declaration names, producing the error cannot evaluate `[init]` declaration 'a' in the same module sometimes when two init declarations depend on each other.
Context
https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Cannot.20evaluation.20.5Binit.5D.20declaration.20in.20same.20module/near/536828403
and
https://leanprover.zulipchat.com/#narrow/channel/428973-nightly-testing/topic/Mathlib.20status.20updates/near/535934676
Steps to Reproduce
- Create two files
Foo.leanandBar.lean - Import
FooinBar.lean - Put this into
Foo.lean:def a_init : IO Nat := pure 5 @[init a_init] opaque a : Nat def b_init : IO Nat := pure (a + 7) @[init b_init] opaque b : Nat
- Reload
Bar.lean - Put this into
Foo.lean:def b_init : IO Nat := pure 5 @[init b_init] opaque b : Nat def a_init : IO Nat := pure (b + 7) @[init a_init] opaque a : Nat
- Reload
Bar.lean
Expected behavior: The initializers are run in dependency order and thus both variants work, regardless of naming.
Actual behavior: Only the second one works because the order depends on the names and not on dependencies.
Versions
Lean 4.24.0-nightly-2025-08-29
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.