internal/shader: bug fix: error on a function name in a function call

Updates #2891
This commit is contained in:
Hajime Hoshi 2024-02-11 21:09:47 +09:00
parent 60725eba86
commit 75103f39dd
2 changed files with 22 additions and 0 deletions

View File

@ -187,6 +187,12 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
cs.addError(e.Pos(), fmt.Sprintf("single-value context and multiple-value context cannot be mixed: %s", e.Fun))
return nil, nil, nil, false
}
for _, expr := range es {
if expr.Type == shaderir.FunctionExpr {
cs.addError(e.Pos(), fmt.Sprintf("function name cannot be an argument: %s", e.Fun))
return nil, nil, nil, false
}
}
args = append(args, es...)
argts = append(argts, ts...)
stmts = append(stmts, ss...)

View File

@ -3818,3 +3818,19 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
}
}
}
// Issue #2891
func TestSyntaxInvalidArgument(t *testing.T) {
if _, err := compileToIR([]byte(`package main
func Foo(x int) int {
return 0
}
func Bar() int {
return Foo(Foo)
}
`)); err == nil {
t.Error("compileToIR must return an error but did not")
}
}