internal/shader: bug fix: non-name on the left side of :=

Closes #2891
This commit is contained in:
Hajime Hoshi 2024-02-11 21:21:14 +09:00
parent 75103f39dd
commit fca8ebb9af
2 changed files with 16 additions and 0 deletions

View File

@ -488,6 +488,10 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
stmts = append(stmts, ss...) stmts = append(stmts, ss...)
if define { 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 name := e.(*ast.Ident).Name
if name != "_" { if name != "_" {
for _, v := range block.vars { for _, v := range block.vars {

View File

@ -3834,3 +3834,15 @@ func Bar() int {
t.Error("compileToIR must return an error but did not") t.Error("compileToIR must return an error but did not")
} }
} }
// Issue #2891
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")
}
}