internal/shader: bug fix: wrong assignment rule for booleans

This commit is contained in:
Hajime Hoshi 2022-07-08 02:19:42 +09:00
parent 87be157b23
commit 6dcd2ff11c
2 changed files with 43 additions and 3 deletions

View File

@ -773,8 +773,15 @@ func canAssign(re *shaderir.Expr, lt *shaderir.Type, rt *shaderir.Type) bool {
if lt.Equal(rt) {
return true
}
if re.Type == shaderir.NumberExpr && (lt.Main == shaderir.Float || lt.Main == shaderir.Int || lt.Main == shaderir.Bool) {
return true
if re.Type == shaderir.NumberExpr {
switch lt.Main {
case shaderir.Bool:
return re.Const.Kind() == gconstant.Bool
case shaderir.Int:
return canTruncateToInteger(re.Const)
case shaderir.Float:
return gconstant.ToFloat(re.Const).Kind() != gconstant.Unknown
}
}
return false
}

View File

@ -444,7 +444,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
return true
}
`)); err != nil {
t.Errorf("error must be nil but was non-nil")
t.Error(err)
}
}
@ -928,6 +928,39 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
if _, err := compileToIR([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
var x float = true
_ = x
return vec4(0)
}
`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
if _, err := compileToIR([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
var x bool = true
_ = x
return vec4(0)
}
`)); err != nil {
t.Error(err)
}
if _, err := compileToIR([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
var x int = 1.0
_ = x
return vec4(0)
}
`)); err != nil {
t.Error(err)
}
}
// Issue #1963