Repository navigation
Description
Prerequisites
- 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”) - When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
If in doubt, please reach out on [email protected] for responsible disclosure.
Description
Field projection resolution can unexpectedly fail due to open namespaces.
When there is a structure protected Special.Foo and a def Foo := Special.Foo, terms of type (_root_.)Foo cannot use .-notation to access Special.Foo's fields when Special is open (but can otherwise).
Context
This was noticed in mathlib when trying to move from numeric projections to readable field name projections. Mathlib has protected SubModule.IsAssociatedPrime as well as IsAssociatedPrime, and uses the former to help with the latter in this way (using a numeric projection) in the theorem IsAssociatedPrime.isPrime. Attempting to use the named field instead of the numeric projection fails.
Steps to Reproduce
namespace Special
-- 1. Define `Special.Foo`
protected structure Foo (n : Nat) : Prop where a : 0 < n
end Special
-- 2. Define top-level `Foo`
def Foo (n : Nat) : Prop := Special.Foo n
-- Note: works, yields `Special.Foo.a`
example (h : Foo 1) : 0 < 1 := h.a
-- Note: works, also yields `Special.Foo.a`
open Special in
example (h : Foo 1) : 0 < 1 := h.1
-- 3.
/--
error: Invalid field notation: Function `Foo.a` does not have a usable parameter of type `Foo ...` for which to substitute `h`
Note: Such a parameter must be explicit, or implicit with a unique name, to be used by field notation
-/
#guard_msgs in
open Special in
example (h : Foo 1) : 0 < 1 := h.a
(One can also remove protected in exchange for (h : _root_.Foo 1), but I figure protected is closer to acceptable practice.)
Expected behavior: All examples succeed, since there is no ambiguity even when open is present.
Actual behavior: open Special in example (h : Foo 1) : 0 < 1 := h.a fails.
Versions
4.37.0-nightly-2026-10-27
Lean web
Additional Information
This may have been inadvertently introduced when improving dot notation in #6189.
The issue roughly seems to be that the open Special allows us to resolve a to Special.Foo.a correctly by respecting opens, but succeeding here causes us to avoid unfolding Foo (which we need to do in order to recognize that the parameter has an acceptable type).
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Activity
chore: manual revert due to leanprover/lean4#16044