From c390f0a9fa0aad0516abbea980a99f7463ed4821 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 29 Apr 2024 16:44:31 +0900 Subject: [PATCH] internal/shader: bug fix: treat a built-in function as an invalid argument Closes #2965 --- internal/shader/expr.go | 2 +- internal/shader/syntax_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/shader/expr.go b/internal/shader/expr.go index 1c063820f..f5460a831 100644 --- a/internal/shader/expr.go +++ b/internal/shader/expr.go @@ -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 } diff --git a/internal/shader/syntax_test.go b/internal/shader/syntax_test.go index 61512ee2e..3c07065b2 100644 --- a/internal/shader/syntax_test.go +++ b/internal/shader/syntax_test.go @@ -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") }