diff --git a/gnovm/pkg/gnolang/type_check.go b/gnovm/pkg/gnolang/type_check.go index af175dc1ef2..1276efd05b0 100644 --- a/gnovm/pkg/gnolang/type_check.go +++ b/gnovm/pkg/gnolang/type_check.go @@ -829,8 +829,8 @@ func (x *RangeStmt) AssertCompatible(store Store, last BlockNode) { if x.Op != ASSIGN { return } - if isBlankIdentifier(x.Key) && isBlankIdentifier(x.Value) { - // both "_" + if isBlankIdentifier(x.Key) && (x.Value == nil || isBlankIdentifier(x.Value)) { + // both "_" or key is "_" and value is not present return } assertValidAssignLhs(store, last, x.Key) diff --git a/gnovm/tests/files/types/range_blank_key.gno b/gnovm/tests/files/types/range_blank_key.gno new file mode 100644 index 00000000000..696b5736c0f --- /dev/null +++ b/gnovm/tests/files/types/range_blank_key.gno @@ -0,0 +1,26 @@ +// https://github.com/gnolang/gno/issues/5664 +package main + +type matrix struct { + e []int +} + +func (a matrix) equal() bool { + for _ = range a.e { + } + for _, _ = range a.e { + } + for range a.e { + } + return true +} + +func main() { + var a matrix + var i interface{} + i = true && a.equal() + println(i) +} + +// Output: +// true