diff --git a/internal/shader/expr.go b/internal/shader/expr.go index 6d148f53b..d17ee8ae5 100644 --- a/internal/shader/expr.go +++ b/internal/shader/expr.go @@ -200,6 +200,13 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable cs.addError(e.Pos(), fmt.Sprintf("single-value context and multiple-value context cannot be mixed: %s", e.Fun)) return nil, nil, nil, false } + // If the argument is a non-typed constant value, treat is as a float value (#1874). + for i, e := range es { + if e.Type == shaderir.NumberExpr && e.ConstType == shaderir.ConstTypeNone { + e.ConstType = shaderir.ConstTypeFloat + ts[i] = shaderir.Type{Main: shaderir.Float} + } + } args = append(args, es...) argts = append(argts, ts...) stmts = append(stmts, ss...) diff --git a/internal/shader/testdata/issue1874.expected.vs b/internal/shader/testdata/issue1874.expected.vs new file mode 100644 index 000000000..68cca2991 --- /dev/null +++ b/internal/shader/testdata/issue1874.expected.vs @@ -0,0 +1,6 @@ +void F0(out float l0); + +void F0(out float l0) { + l0 = (sin(1.0000000000e-01)) + (cos(2.0000000000e-01)); + return; +} diff --git a/internal/shader/testdata/issue1874.go b/internal/shader/testdata/issue1874.go new file mode 100644 index 000000000..81c9f3ee5 --- /dev/null +++ b/internal/shader/testdata/issue1874.go @@ -0,0 +1,9 @@ +package main + +func Foo() float { + const ( + s = 0.1 + c = 0.2 + ) + return sin(s) + cos(c) +}