internal/shader: bug fix: deduction checks for the % operator were lacked

This commit is contained in:
Hajime Hoshi 2022-01-14 03:50:30 +09:00
parent ab7c0c9137
commit 260f7e07df
2 changed files with 21 additions and 1 deletions

View File

@ -202,9 +202,11 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr, markLocalVariable
return nil, nil, nil, false
}
// For `%`, both types must be deducible to integers.
if op == shaderir.ModOp {
// TODO: What about ivec?
if lhst.Main != shaderir.Int || rhst.Main != shaderir.Int {
if lhst.Main != shaderir.Int && (lhs[0].ConstType == shaderir.ConstTypeNone || !canTruncateToInteger(lhs[0].Const)) ||
rhst.Main != shaderir.Int && (rhs[0].ConstType == shaderir.ConstTypeNone || !canTruncateToInteger(rhs[0].Const)) {
var wrongType shaderir.Type
if lhst.Main != shaderir.Int {
wrongType = lhst

View File

@ -1283,6 +1283,24 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
if _, err := ebiten.NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
a := int(2) % 0.5
return vec4(a)
}`)); err == nil {
t.Errorf("error must be non-nil but was nil")
}
if _, err := ebiten.NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
a := int(2) % 1.0
return vec4(a)
}`)); err != nil {
t.Error(err)
}
if _, err := ebiten.NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
a := 2.0
b := 0.5