Skip to content

Reject Leo keywords as package names#29496

Merged
mohammadfawaz merged 2 commits into
ProvableHQ:masterfrom
Kuhai9801:reject-keyword-program-names
Jun 8, 2026
Merged

Reject Leo keywords as package names#29496
mohammadfawaz merged 2 commits into
ProvableHQ:masterfrom
Kuhai9801:reject-keyword-program-names

Conversation

@Kuhai9801

Copy link
Copy Markdown
Contributor

Motivation

Fixes #29071.

leo new currently accepts package names that are Leo keywords. Those names later conflict with Leo syntax, so this rejects keyword names during package name validation.

Test Plan

  • cargo test -p leo-package -- --nocapture

Related PRs

None

@Kuhai9801 Kuhai9801 marked this pull request as ready for review June 8, 2026 13:48
@mohammadfawaz mohammadfawaz self-assigned this Jun 8, 2026
@mohammadfawaz mohammadfawaz added the 🖥️ CLI Anything related to the Leo CLI. label Jun 8, 2026
@mohammadfawaz mohammadfawaz self-requested a review June 8, 2026 16:23

@mohammadfawaz mohammadfawaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread crates/package/src/lib.rs
Program::<TestnetV0>::KEYWORDS.iter().copied().chain(restricted)
}

fn is_leo_keyword(name: &str) -> bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is already validated as a single identifier above, so this could skip the full lex() + collect. Worth exposing one pub fn is_keyword(&str) -> bool in parser-rowan and routing all keyword checks through it — including the parser's symbol_is_keyword (crates/parser/src/rowan.rs), which is a hand-maintained matches! over sym::* that's already drifted from the lexer (e.g. missing view/dyn). It could be deleted in favor of the shared helper so the lexer stays the single source of truth.

Comment thread crates/package/src/lib.rs Outdated
}

// Check reserved keywords.
if reserved_keywords().any(|kw| kw == name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we also reject Leo keywords, consider renaming reserved_keywords -> aleo_reserved_keywords and adding an is_aleo_keyword(name) predicate, so the two checks read symmetrically: is_leo_keyword(name) / is_aleo_keyword(name).

@mohammadfawaz mohammadfawaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you.

@mohammadfawaz mohammadfawaz force-pushed the reject-keyword-program-names branch from 7b2a1c6 to 747e6e8 Compare June 8, 2026 18:52
@mohammadfawaz mohammadfawaz merged commit 6dedd5c into ProvableHQ:master Jun 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🖥️ CLI Anything related to the Leo CLI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] leo new shouldn't allow Leo keywords as program names

2 participants