internal/shader: Bug fix: Treat a non-typed consntat argument as a float

Closes #1874
This commit is contained in:
Hajime Hoshi 2021-11-14 15:03:22 +09:00
parent ee414ed849
commit 36ce3b836e
3 changed files with 22 additions and 0 deletions

View File

@ -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)) cs.addError(e.Pos(), fmt.Sprintf("single-value context and multiple-value context cannot be mixed: %s", e.Fun))
return nil, nil, nil, false 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...) args = append(args, es...)
argts = append(argts, ts...) argts = append(argts, ts...)
stmts = append(stmts, ss...) stmts = append(stmts, ss...)

View File

@ -0,0 +1,6 @@
void F0(out float l0);
void F0(out float l0) {
l0 = (sin(1.0000000000e-01)) + (cos(2.0000000000e-01));
return;
}

9
internal/shader/testdata/issue1874.go vendored Normal file
View File

@ -0,0 +1,9 @@
package main
func Foo() float {
const (
s = 0.1
c = 0.2
)
return sin(s) + cos(c)
}