Skip to content

fix(gnovm): allow type-switch with sole case nil: (preprocess single-case branch must tag-type-only when ct is nil)#5766

Open
ltzmaxwell wants to merge 4 commits into
masterfrom
fix/typeswitch1
Open

fix(gnovm): allow type-switch with sole case nil: (preprocess single-case branch must tag-type-only when ct is nil)#5766
ltzmaxwell wants to merge 4 commits into
masterfrom
fix/typeswitch1

Conversation

@ltzmaxwell

Copy link
Copy Markdown
Contributor
  • Before: a type-switch whose sole case was case nil: (e.g. switch xx := x.(type) { case nil: ... }) panicked at preprocess with name xx not declared because the single-case shortcut registered the switch var with anyValue(ct) where ct == nil; after: the sole-nil form is accepted and xx is bound to the tag's static type, matching Go.
  • preprocess1's *TypeSwitchStmt branch in gnovm/pkg/gnolang/preprocess.go now gates the len(n.Cases) == 1 define-with-case-type shortcut on ct != nil, so a nil ct falls through to the same tag-type define used for multi-case switches.
  • New filetest gnovm/tests/files/typeswitch1.gno mirrors gocorpus's typeswitch1 (sole case nil: alongside mixed multi-type cases) and exercises both the xx := x.(type) and bare xx.(type) shapes.

@Gno2D2

Gno2D2 commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

🛠 PR Checks Summary

All Automated Checks passed. ✅

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):

No automated checks match this pull request.

☑️ 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
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

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Reserve() remains the legitimate entry point for nil-typed placeholder slots; Define() is for real bindings only. Catches the type-switch `case nil:` class of bug at the offending caller instead of as a confusing downstream "name not declared" panic.
@thehowl thehowl added the a/vm GnoVM, Security, Runtime team label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a/vm GnoVM, Security, Runtime team 📦 🤖 gnovm Issues or PRs gnovm related

Projects

Development

Successfully merging this pull request may close these issues.

4 participants