shader: Bug fix: Wrong type deduction with int(x)

Fixes #1298
This commit is contained in:
Hajime Hoshi 2020-08-12 12:16:08 +09:00
parent ed240b8393
commit 18732ca879
3 changed files with 20 additions and 0 deletions

View File

@ -198,6 +198,12 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
if callee.Type == shaderir.BuiltinFuncExpr {
var t shaderir.Type
switch callee.BuiltinFunc {
case shaderir.BoolF:
t = shaderir.Type{Main: shaderir.Bool}
case shaderir.IntF:
t = shaderir.Type{Main: shaderir.Int}
case shaderir.FloatF:
t = shaderir.Type{Main: shaderir.Float}
case shaderir.Vec2F:
t = shaderir.Type{Main: shaderir.Vec2}
case shaderir.Vec3F:

View File

@ -0,0 +1,8 @@
void F0(in float l0, out int l1);
void F0(in float l0, out int l1) {
int l2 = 0;
l2 = int(l0);
l1 = l2;
return;
}

6
internal/shader/testdata/issue1298.go vendored Normal file
View File

@ -0,0 +1,6 @@
package main
func Foo(f float) int {
x := int(f)
return x
}