mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
Revert "remove return type for deduced int"
This reverts commit 66a4b20bda
.
This commit is contained in:
parent
ced2d6ec8b
commit
8d15a459cf
@ -124,8 +124,11 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
|
|||||||
|
|
||||||
// If left is untyped const
|
// If left is untyped const
|
||||||
if lhst.Main == shaderir.None && lhs[0].Const != nil {
|
if lhst.Main == shaderir.None && lhs[0].Const != nil {
|
||||||
|
if rhs[0].Const != nil {
|
||||||
lhst = shaderir.Type{Main: shaderir.Int}
|
lhst = shaderir.Type{Main: shaderir.Int}
|
||||||
// Left should be implicitly converted to the type it would assume if the shift expression were replaced by its left operand alone.
|
} else {
|
||||||
|
lhst = shaderir.Type{Main: shaderir.DeducedInt}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -514,6 +514,9 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
t := ts[0]
|
t := ts[0]
|
||||||
|
if t.Main == shaderir.DeducedInt {
|
||||||
|
cs.addError(pos, "invalid operation: shifted operand 1 (type float) must be integer")
|
||||||
|
}
|
||||||
if t.Main == shaderir.None {
|
if t.Main == shaderir.None {
|
||||||
t = toDefaultType(r[0].Const)
|
t = toDefaultType(r[0].Const)
|
||||||
}
|
}
|
||||||
@ -705,6 +708,9 @@ func canAssign(lt *shaderir.Type, rt *shaderir.Type, rc gconstant.Value) bool {
|
|||||||
if lt.Equal(rt) {
|
if lt.Equal(rt) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if lt.Main == shaderir.Int && rt.Main == shaderir.DeducedInt {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if rc == nil {
|
if rc == nil {
|
||||||
return false
|
return false
|
||||||
|
@ -1324,16 +1324,16 @@ func TestSyntaxOperatorShift(t *testing.T) {
|
|||||||
// {stmt: "s := 1; var a float = float(1.0 << s); _ = a", err: true},
|
// {stmt: "s := 1; var a float = float(1.0 << s); _ = a", err: true},
|
||||||
// {stmt: "s := 1; var a int = int(1 << s); _ = a", err: false},
|
// {stmt: "s := 1; var a int = int(1 << s); _ = a", err: false},
|
||||||
// {stmt: "s := 1; var a int = int(1.0 << s); _ = a", err: false},
|
// {stmt: "s := 1; var a int = int(1.0 << s); _ = a", err: false},
|
||||||
// {stmt: "s := 1; a := 1 << s; _ = a", err: false},
|
|
||||||
// {stmt: "s := 1; a := 1.0 << s; _ = a", err: true},
|
|
||||||
// {stmt: "s := 1; a := int(1.0 << s); _ = a", err: false},
|
|
||||||
// {stmt: "s := 1; var a float = float(1.0 << s); _ = a", err: true},
|
|
||||||
// {stmt: "s := 1; var a float = 1.0 << s; _ = a", err: true},
|
|
||||||
// {stmt: "s := 1; var a float = 1 << s; _ = a", err: true},
|
|
||||||
// {stmt: "s := 1; var a int = 1.0 << s; _ = a", err: false},
|
|
||||||
// {stmt: "s := 1; var a int = 1 << s; _ = a", err: false},
|
|
||||||
|
|
||||||
|
{stmt: "s := 1; a := 1 << s; _ = a", err: false},
|
||||||
|
{stmt: "s := 1; a := 1.0 << s; _ = a", err: true},
|
||||||
|
{stmt: "s := 1; a := int(1.0 << s); _ = a", err: false},
|
||||||
{stmt: "var a float = 1.0 << 2.0; _ = a", err: false},
|
{stmt: "var a float = 1.0 << 2.0; _ = a", err: false},
|
||||||
|
{stmt: "s := 1; var a float = float(1.0 << s); _ = a", err: true},
|
||||||
|
{stmt: "s := 1; var a float = 1.0 << s; _ = a", err: true},
|
||||||
|
{stmt: "s := 1; var a float = 1 << s; _ = a", err: true},
|
||||||
|
{stmt: "s := 1; var a int = 1.0 << s; _ = a", err: false},
|
||||||
|
{stmt: "s := 1; var a int = 1 << s; _ = a", err: false},
|
||||||
{stmt: "var a int = 1.0 << 2; _ = a", err: false},
|
{stmt: "var a int = 1.0 << 2; _ = a", err: false},
|
||||||
{stmt: "var a float = 1.0 << 2; _ = a", err: false},
|
{stmt: "var a float = 1.0 << 2; _ = a", err: false},
|
||||||
{stmt: "var a = 1.0 << 2; _ = a", err: false},
|
{stmt: "var a = 1.0 << 2; _ = a", err: false},
|
||||||
@ -1363,7 +1363,12 @@ func TestSyntaxOperatorShift(t *testing.T) {
|
|||||||
{stmt: "a := vec3(1) << ivec2(2); _ = a", err: true},
|
{stmt: "a := vec3(1) << ivec2(2); _ = a", err: true},
|
||||||
{stmt: "a := ivec2(1) << vec3(2); _ = a", err: true},
|
{stmt: "a := ivec2(1) << vec3(2); _ = a", err: true},
|
||||||
|
|
||||||
{stmt: "var a float = 1.0 >> 2.0; _ = a", err: false},
|
{stmt: "s := 1; var a float = float(1.0 >> s); _ = a", err: true},
|
||||||
|
{stmt: "s := 1; var a int = int(1.0 >> s); _ = a", err: false},
|
||||||
|
{stmt: "s := 1; var a float = 1.0 >> s; _ = a", err: true},
|
||||||
|
{stmt: "s := 1; var a float = 1 >> s; _ = a", err: true},
|
||||||
|
{stmt: "s := 1; var a int = 1.0 >> s; _ = a", err: false},
|
||||||
|
{stmt: "s := 1; var a int = 1 >> s; _ = a", err: false},
|
||||||
{stmt: "var a int = 1.0 >> 2; _ = a", err: false},
|
{stmt: "var a int = 1.0 >> 2; _ = a", err: false},
|
||||||
{stmt: "var a float = 1.0 >> 2; _ = a", err: false},
|
{stmt: "var a float = 1.0 >> 2; _ = a", err: false},
|
||||||
{stmt: "var a = 1.0 >> 2; _ = a", err: false},
|
{stmt: "var a = 1.0 >> 2; _ = a", err: false},
|
||||||
|
@ -165,7 +165,7 @@ func checkArgsForIntBuiltinFunc(args []shaderir.Expr, argts []shaderir.Type) err
|
|||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return fmt.Errorf("number of int's arguments must be 1 but %d", len(args))
|
return fmt.Errorf("number of int's arguments must be 1 but %d", len(args))
|
||||||
}
|
}
|
||||||
if argts[0].Main == shaderir.Int || argts[0].Main == shaderir.Float {
|
if argts[0].Main == shaderir.Int || argts[0].Main == shaderir.Float || argts[0].Main == shaderir.DeducedInt {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if args[0].Const != nil && gconstant.ToInt(args[0].Const).Kind() != gconstant.Unknown {
|
if args[0].Const != nil && gconstant.ToInt(args[0].Const).Kind() != gconstant.Unknown {
|
||||||
|
@ -145,7 +145,7 @@ func TypeFromBinaryOp(op Op, lhst, rhst Type, lhsConst, rhsConst constant.Value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if op == LeftShift || op == RightShift {
|
if op == LeftShift || op == RightShift {
|
||||||
if lhst.Main == Int && rhst.Main == Int {
|
if (lhst.Main == Int || lhst.Main == DeducedInt) && rhst.Main == Int {
|
||||||
return Type{Main: lhst.Main}, true
|
return Type{Main: lhst.Main}, true
|
||||||
}
|
}
|
||||||
if lhst.IsIntVector() && rhst.Main == Int {
|
if lhst.IsIntVector() && rhst.Main == Int {
|
||||||
|
@ -180,6 +180,7 @@ const (
|
|||||||
Texture
|
Texture
|
||||||
Array
|
Array
|
||||||
Struct
|
Struct
|
||||||
|
DeducedInt
|
||||||
)
|
)
|
||||||
|
|
||||||
func descendantLocalVars(block, target *Block) ([]Type, bool) {
|
func descendantLocalVars(block, target *Block) ([]Type, bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user