mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/shader: bug fix: unary operators should keep the type info
Closes #2705
This commit is contained in:
parent
5a1109e56a
commit
20123e8420
@ -883,7 +883,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
}, []shaderir.Type{t}, stmts, true
|
}, []shaderir.Type{t}, stmts, true
|
||||||
|
|
||||||
case *ast.UnaryExpr:
|
case *ast.UnaryExpr:
|
||||||
exprs, t, stmts, ok := cs.parseExpr(block, fname, e.X, markLocalVariableUsed)
|
exprs, ts, stmts, ok := cs.parseExpr(block, fname, e.X, markLocalVariableUsed)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, nil, false
|
return nil, nil, nil, false
|
||||||
}
|
}
|
||||||
@ -894,16 +894,14 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
|
|
||||||
if exprs[0].Const != nil {
|
if exprs[0].Const != nil {
|
||||||
v := gconstant.UnaryOp(e.Op, exprs[0].Const, 0)
|
v := gconstant.UnaryOp(e.Op, exprs[0].Const, 0)
|
||||||
t := shaderir.Type{Main: shaderir.Int}
|
// Use the original type as it is.
|
||||||
if v.Kind() == gconstant.Float {
|
// Keep the type untyped if the original expression is untyped (#2705).
|
||||||
t = shaderir.Type{Main: shaderir.Float}
|
|
||||||
}
|
|
||||||
return []shaderir.Expr{
|
return []shaderir.Expr{
|
||||||
{
|
{
|
||||||
Type: shaderir.NumberExpr,
|
Type: shaderir.NumberExpr,
|
||||||
Const: v,
|
Const: v,
|
||||||
},
|
},
|
||||||
}, []shaderir.Type{t}, stmts, true
|
}, ts[:1], stmts, true
|
||||||
}
|
}
|
||||||
|
|
||||||
var op shaderir.Op
|
var op shaderir.Op
|
||||||
@ -924,7 +922,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
Op: op,
|
Op: op,
|
||||||
Exprs: exprs,
|
Exprs: exprs,
|
||||||
},
|
},
|
||||||
}, t, stmts, true
|
}, ts[:1], stmts, true
|
||||||
|
|
||||||
case *ast.CompositeLit:
|
case *ast.CompositeLit:
|
||||||
t, ok := cs.parseType(block, fname, e.Type)
|
t, ok := cs.parseType(block, fname, e.Type)
|
||||||
|
@ -3236,3 +3236,16 @@ func foo(x vec2) {
|
|||||||
t.Error("compileToIR must return an error but did not")
|
t.Error("compileToIR must return an error but did not")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2705
|
||||||
|
func TestSyntaxInitWithNegativeInteger(t *testing.T) {
|
||||||
|
if _, err := compileToIR([]byte(`package main
|
||||||
|
|
||||||
|
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||||
|
var x float = -0
|
||||||
|
_ = x
|
||||||
|
return position
|
||||||
|
}`)); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user