leanprover / leanprover/lean4

Inconsistent Behavior: User Declaration with Leading Underscore Allowed Despite Documentation

Open
#4,858 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

There appears to be an inconsistency between the Lean documentation and its actual behavior regarding user declarations with names starting with an underscore (_).

/-- The frontend does not allow user declarations to start with `_` in any of its parts.
   We use name parts starting with `_` internally to create auxiliary names (e.g., `_private`). -/
def isInternal : Name → Bool
  | str p s => s.get 0 == '_' || isInternal p
  | num p _ => isInternal p
  | _       => false

Example

def _inside := 0
#eval ``_inside |>.isInternal

In this case, _inside is successfully declared, and isInternal correctly returns true, indicating that the name starts with an underscore.

Additional Information

This issue raises questions about whether the documentation is outdated or if there is a bug in the frontend allowing names with leading underscores. Clarification on this behavior would be helpful for users to understand the intended constraints on naming.

Environment

  • Lean version: 4.8.0, 4.10.0-rc2 and more

Related issues

The difference between the two is that this issue attempts to determine an internal naming style supported by Lean.Elab, i.e.

The frontend does not allow user declarations to start with *** in any of its parts.

Unless another issue can be solved in this way:

I still think we should have some kind of explicit @[automatically_generated] attribute (this is what rust does BTW) to standardize this rather than using underscores, because sometimes autogenerated definitions are also intended for use by users. —— digama0

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 by comparing the documented isInternal rule with the _inside example across Lean 4.8.0 and 4.10.0-rc2. Determine whether frontend rejection or the documentation reflects the intended naming behavior, considering related issue #2850 and the proposed automatically_generated attribute. Done means the supported behavior and naming guidance are resolved and documented.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.