internal/shader: bug fix: wrong lhs in an assignment

Closes #2910
This commit is contained in:
Hajime Hoshi 2024-02-15 02:29:19 +09:00
parent 6bdd686a29
commit 820c996329
2 changed files with 17 additions and 1 deletions

View File

@ -622,6 +622,10 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
}
if define {
if _, ok := e.(*ast.Ident); !ok {
cs.addError(pos, "non-name on the left side of :=")
return nil, false
}
name := e.(*ast.Ident).Name
if name != "_" {
for _, v := range block.vars {

View File

@ -3835,13 +3835,25 @@ func Bar() int {
}
}
// Issue #2891
// Issue #2891, #2910
func TestSyntaxTailingUnaryOperator(t *testing.T) {
if _, err := compileToIR([]byte(`package main
func Foo() {
1 + x := vec2(2)
}
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
if _, err := compileToIR([]byte(`package main
func Foo() {
1 + x, y := Bar()
}
func Bar() (int, int) {
return 0, 0
}
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}