Skip to content

fix(preprocess): avoid shadowing of iota - #5981

Open
Villaquiranm wants to merge 10 commits into
gnolang:masterfrom
Villaquiranm:fix/avoid-shadowing-iota
Open

fix(preprocess): avoid shadowing of iota#5981
Villaquiranm wants to merge 10 commits into
gnolang:masterfrom
Villaquiranm:fix/avoid-shadowing-iota

Conversation

@Villaquiranm

Copy link
Copy Markdown
Contributor

closes #5876

@Gno2D2

Gno2D2 commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

🛠 PR Checks Summary

🔴 Pending initial approval by a review team member, or review from tech-staff

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🔴 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: Villaquiranm/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🔴 Requirement not satisfied
└── 🔴 If
    ├── 🔴 Condition
    │   └── 🔴 Or
    │       ├── 🔴 At least one of these user(s) reviewed the pull request: [aronpark1007 davd-gzl jefft0 notJoon omarsy MikaelVallenet] (with state "APPROVED")
    │       ├── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🔴 Else
        └── 🔴 And
            ├── 🟢 This label is applied to pull request: review/triage-pending
            └── 🔴 On no pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@Villaquiranm
Villaquiranm marked this pull request as ready for review July 24, 2026 05:47
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Jul 24, 2026

@davd-gzl davd-gzl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[AI bot]

Verified on af3accb: gno lint rejects a package whose exported function takes an iota parameter, as gnoPreprocessError, matching the VM even though go/types accepts the source. Nested const groups still evaluate iota exactly as the Go compiler does.

main / build is red only on formatting: four of the new filetests end with a trailing blank line. docs is red on an unreachable link in gnoland-networks.md, which this branch does not touch.

Full review: https://github.com/samouraiworld/gno-agent-workspace/blob/main/reviews/pr/5xxx/5981-avoid-shadowing-iota/2-af3accbce/review_claude-opus-4-8_davd-gzl.md

Comment on lines +2318 to +2321
// iota is a non-shadowable builtin; reject binding it as a receiver,
// parameter, named result, type-switch guard, short-var-define, or
// range key/value name. (uverse's own "iota" registration goes through
// Define2 directly, bypassing Reserve, so it is unaffected.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A three-clause for init never reaches this check. initStaticBlocks1 renames those names, and their body references, to <name>.loopvar, and it runs before Reserve sees them. So for iota := 0; iota < 2; iota++ { println(iota) } prints 0 and 1, while for iota := range s is rejected.

repro
# from a local clone of gnolang/gno:
gh pr checkout 5981 -R gnolang/gno
cat > gnovm/tests/files/iota_forinit.gno <<'EOF'
package main

func main() {
	for iota := 0; iota < 2; iota++ {
		println(iota)
	}
}

// Error:
// main/iota_forinit.gno:4:6-14: builtin identifiers cannot be shadowed: iota
EOF
go test -run 'TestFiles/iota_forinit.gno$' ./gnovm/pkg/gnolang/
rm gnovm/tests/files/iota_forinit.gno
--- FAIL: TestFiles (0.03s)
    --- FAIL: TestFiles/iota_forinit.gno (0.00s)
        files_test.go:135: unexpected output:
            0
            1

FAIL
FAIL	github.com/gnolang/gno/gnovm/pkg/gnolang	0.044s

// parameter, named result, type-switch guard, short-var-define, or
// range key/value name. (uverse's own "iota" registration goes through
// Define2 directly, bypassing Reserve, so it is unaffected.)
if nx.Name == iotaIdentifier {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

func f(iota int) { println("hi") }, func f() (iota int) and func (iota T) M() all run on master, because the name is bound but never referenced. Node startup re-preprocesses every stored package at VMKeeper.Initialize, with no per-package recover. A package already on chain that uses one of those forms would fail at boot rather than at its next call.

repro
# from a local clone of gnolang/gno:
gh pr checkout 5981 -R gnolang/gno
cat > iota_param.gno <<'EOF'
package main

func f(iota int) { println("hi") }

func main() { f(3) }
EOF
echo "== at PR head:"; go run ./gnovm/cmd/gno run iota_param.gno
git checkout $(git merge-base origin/master HEAD) -- gnovm/pkg/gnolang/nodes.go
echo "== with the check removed:"; go run ./gnovm/cmd/gno run iota_param.gno
git checkout HEAD -- gnovm/pkg/gnolang/nodes.go
rm iota_param.gno
== at PR head:
panic: builtin identifiers cannot be shadowed: iota [recovered]
	panic: main/iota_param.gno:3:1-35: builtin identifiers cannot be shadowed: iota:
	--- preprocess stack ---
== with the check removed:
hi

// range key/value name. (uverse's own "iota" registration goes through
// Define2 directly, bypassing Reserve, so it is unaffected.)
if nx.Name == iotaIdentifier {
panic(fmt.Sprintf("builtin identifiers cannot be shadowed: %s", nx.Name))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: func f(len int) int { return len } compiles here, and so does every uverse name but iota in that position. The message says builtin identifiers cannot be shadowed, so an author who hits it on a parameter reads a rule the compiler does not enforce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 🤖 gnovm Issues or PRs gnovm related review/triage-pending PRs opened by external contributors that are waiting for the 1st review

Projects

Development

Successfully merging this pull request may close these issues.

iota cannot be used as an identifier name outside constant declarations

4 participants