internal/shader: bug fix: treat a built-in function as an invalid argument

Closes #2965
This commit is contained in:
Hajime Hoshi 2024-04-29 16:44:31 +09:00
parent 13d15b0ed9
commit c390f0a9fa
2 changed files with 11 additions and 1 deletions

View File

@ -199,7 +199,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
return nil, nil, nil, false
}
for _, expr := range es {
if expr.Type == shaderir.FunctionExpr {
if expr.Type == shaderir.FunctionExpr || expr.Type == shaderir.BuiltinFuncExpr {
cs.addError(e.Pos(), fmt.Sprintf("function name cannot be an argument: %s", e.Fun))
return nil, nil, nil, false
}

View File

@ -1897,6 +1897,16 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
Foo(Bar())
return color
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
// Issue #2965
if _, err := compileToIR([]byte(`package main
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
abs(sign)
return color
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}