internal/shader: bug fix: crash with an invalid operand

Closes #2989
This commit is contained in:
Hajime Hoshi 2024-07-26 00:06:09 +09:00
parent 268b638a15
commit 09cefc6e71
2 changed files with 16 additions and 1 deletions

View File

@ -88,6 +88,10 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
return nil, nil, nil, false
}
stmts = append(stmts, ss...)
if len(ts) == 0 {
cs.addError(e.Pos(), fmt.Sprintf("unexpected binary operator: %s", e.Y))
return nil, nil, nil, false
}
rhst := ts[0]
op := e.Op

View File

@ -4277,7 +4277,7 @@ func Bar() (int, int) {
}
}
// Issue #2926
// Issue #2926, #2989
func TestSyntaxNonTypeExpression(t *testing.T) {
if _, err := compileToIR([]byte(`package main
@ -4306,6 +4306,17 @@ func Bar() float {
func Foo() {
}
func Bar() float {
return 1.0 + Foo
}
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
if _, err := compileToIR([]byte(`package main
func Foo() {
}
func Bar() float {
return Foo.x
}