Recognition of `_` in Initial Condition of for Loop
Description
I'm not sure if this is a bug or a feature. In gno, using _ (underscore, typically for ignoring values) in the initialization of a for loop is accepted. Such usage is not permitted in Go syntax.
package main
func main() {
i := 1
for _; i < 5; i++ {
println(i)
}
}
// output: 1 2 3 4
// expect: cannot use _ as value or type
Note that, just like in standard Go, gno also allows leaving the initialization part of a for loop blank, as shown below:
package main
func main() {
i := 1
for ; i < 5; i++ {
println(i)
}
}
// output:
1
2
3
4
May related with op_exec
This test reproduces the case where the loop's initialization condition is underscored, as shown below:
func TestForLoopIgnoredInital(t *testing.T) {
m := NewMachine("test", nil)
main := FuncD("main", nil, nil, Ss(
A("i", ":=", "0"),
For(
X("_"),
X("i < 5"),
Inc("i"),
),
))
m.RunDeclaration(main)
m.RunMain()
}
However, I'm not sure how to test for an empty value in the initial condition.
It probably shouldn't accept the syntax and have the same behaviour as Go, there's no good reason why the feature should be accepted in Gno. However, I think it's safe to say that if the only statement accepted in this context _ this can be considered low-priority :)
@thehowl I didn't think there was anything wrong with it, but it was vague. Thanks for the feedback
still an issue we should fix (I think more likely by not accepting all expressions as statements)
This now fails with cannot use _ as value or type