leanprover-community / leanprover-community/lean
(No equational lemmas)/(Mistaken as field notation) when using a `namespace` inside a `section` with universe polymorphism
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 433
- Forks
- 79
- PR merge metrics
- No merged PRs in 30d
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Checked that your issue isn't already filed.
- Specifically, check out the wishlist, open RFCs,
or feature requests.
- Specifically, check out the wishlist, open RFCs,
- Reduced the issue to a self-contained, reproducible test case.
- Checked that your issue isn't already filed.
Description
Allowing a namespace inside a section can cause compile issues.
Steps to Reproduce
- Compile the following code:
section universes u inductive my_unit : Type u | foo namespace my_unit def one : ℕ := 1 end my_unit lemma test : my_unit.one = 1 := by refl end
Expected behavior: Code compiles, in particular, my_unit.one isn't treated as field notation.
Actual behavior: Obtain error message:
invalid field notation, type is not of the form (C ...) where C is a constant
my_unit
has type
Type u
Reproduces how often: 100%
Versions
- Lean (version 3.32.1, commit 35b3a9c4e2d3, Release) on cygwin.
Additional Information
If you rephrase the code, you can also get another issue which I think is related:
section
universes u
inductive my_unit : Type u
| foo
def my_unit.one (_ : my_unit) : ℕ := 1
lemma test : my_unit.one my_unit.foo = 1 := by unfold my_unit.one
end
gives:
unfold tactic failed, my_unit.one does not have equational lemmas nor is a projection
state:
⊢ my_unit.foo.one = 1
There some small adjustments I've been able to make to get either example to compile. I think the second and third qualifies as a workaround.
- Don't use universe polymorphism.
section inductive my_unit : Type | foo namespace my_unit def one : ℕ := 1 end my_unit lemma test : my_unit.one = 1 := by refl end - Move the
namespaceout of thesection.section universes u inductive my_unit : Type u | foo end namespace my_unit universes u def one : ℕ := 1 -- other code which uses `u` end my_unit section universes u lemma test : my_unit.one = 1 := by refl end - Use
_root_.section universes u inductive my_unit : Type u | foo namespace my_unit def one : ℕ := 1 end my_unit lemma test : _root_.my_unit.one = 1 := by refl end
Hopefully I haven't made any mistakes or missed an issue/PR, I couldn't find anything related when searching for both "namespace" and "section".
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing both minimal examples with Lean 3.32.1, focusing on the namespace inside a universe-polymorphic section and the resulting field-notation or equational-lemma errors. Compare the listed workarounds, including moving the namespace and using _root_. Done means the original examples compile, my_unit.one resolves as a name, and the second example can be unfolded.
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
- 25/100