Skip to content

fix(gnovm): handle blank range key/value per-operand, validate assignment targets#5764

Open
ltzmaxwell wants to merge 43 commits into
gnolang:masterfrom
ltzmaxwell:fix/range_blank_key
Open

fix(gnovm): handle blank range key/value per-operand, validate assignment targets#5764
ltzmaxwell wants to merge 43 commits into
gnolang:masterfrom
ltzmaxwell:fix/range_blank_key

Conversation

@ltzmaxwell

@ltzmaxwell ltzmaxwell commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #5751 — main target: blank range key/value handled per-operand. Along the way it generalizes target/RHS validation to every assigning statement (absorbs #5804) and fixes adjacent issues found while unifying the pattern.

  • Main fix: RangeStmt.AssertCompatible checks each operand independently via the new evalAssignLhsType helper (validity asked of every operand; type check skipped for blank), fixing the for _, v = range slice panic and the string-branch message printing kt for vt.
  • Hardening: checkAssignableTo/assertIndexTypeIsInt panic on nil destination type — nil aliases an untyped-nil lvalue (for k, nil = range m) with blank, so a missing blank-skip now fails loudly in CI instead of silently skipping the check.
  • Adjacent fixes: unassignable targets rejected at preprocess everywhere (for _, c = range a with const, c += 1 / s[0] += 1 silently discarding writes, c++ runtime panic — IncDecStmt.AssertCompatible now takes (store, last) like its peers); _ = nil rejected (T(nil) stays legal); compound assigns get blank-target (_ += 1) and RHS validity (i += int, i += f()) checks; range/index ,ok checks resolve baseOf and use assignability instead of kind, fixing silent type confusion with declared map types and named int/rune operands — all with go/types-matching messages and error precedence.
  • Tests: types/range_blank_key25, assign_range_fk, assign_index_d/e, assign_op_ag (c–g also pin the check ORDER: each program has two errors and the golden records which fires first), incdec_a5, assign_nil3; nil-dt panic pinned in TestCheckAssignableTo.

@Gno2D2

Gno2D2 commented Jun 1, 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):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ 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: ltzmaxwell/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this 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

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread gnovm/tests/files/range_blank_key.gno Outdated
@@ -0,0 +1,11 @@
package main

// Regression: `for _ = range slice` used to panic on nil key in assertIndexTypeIsInt.

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.

This also fix

package main

func main() {
	a := []int{1, 2, 3}
	var v int
	for _, v = range a {
	}
	_ = v
	println("ok")
}

// Output:
// ok

Ref: #5751 (comment) (+ verified personally)

@ltzmaxwell ltzmaxwell changed the title fix(gnovm): guard nil kt in assertIndexTypeIsInt for blank-key range fix(gnovm): handle blank range key/value per-operand in AssertCompatible Jun 10, 2026
@ltzmaxwell ltzmaxwell changed the title fix(gnovm): handle blank range key/value per-operand in AssertCompatible fix(gnovm): handle blank range key/value per-operand Jun 10, 2026
@ltzmaxwell ltzmaxwell changed the title fix(gnovm): handle blank range key/value per-operand fix(gnovm): handle blank range key/value per-operand, validate assignment targets Jun 11, 2026
@thehowl thehowl added the a/vm GnoVM, Security, Runtime team label Jun 11, 2026
@ltzmaxwell ltzmaxwell requested review from omarsy and thehowl June 12, 2026 04:12
@ltzmaxwell

Copy link
Copy Markdown
Contributor Author

@davd-gzl requesting a fresh review: your approval was at fa5c11d3, and the PR has been substantially reworked since — it absorbed #5804 (closed) and now covers, beyond the original blank-range fix: a strict non-nil destination-type contract in checkAssignableTo (panics instead of vacuously accepting, with the nil-alias rationale in the description), assignment-target/RHS validation for range value, compound assign, and inc/dec, _ = nil rejection, and declared/named-type fixes (baseOf dispatch, assignability instead of kind checks for range index/value). Error messages and check ordering match go/types and are pinned by goldens (assign_op_cg). Best reviewed as a fresh pass rather than a delta.

@ltzmaxwell ltzmaxwell requested a review from davd-gzl June 12, 2026 04:16
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