remove return type for deduced int

This commit is contained in:
aoyako 2024-02-27 19:39:14 +09:00
parent 7f9d997175
commit 66a4b20bda
6 changed files with 13 additions and 28 deletions

View File

@ -124,11 +124,8 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
// If left is untyped const
if lhst.Main == shaderir.None && lhs[0].Const != nil {
if rhs[0].Const != nil {
lhst = shaderir.Type{Main: shaderir.Int}
} else {
lhst = shaderir.Type{Main: shaderir.DeducedInt}
}
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 {

View File

@ -514,9 +514,6 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
return nil, false
}
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 {
t = toDefaultType(r[0].Const)
}
@ -708,9 +705,6 @@ func canAssign(lt *shaderir.Type, rt *shaderir.Type, rc gconstant.Value) bool {
if lt.Equal(rt) {
return true
}
if lt.Main == shaderir.Int && rt.Main == shaderir.DeducedInt {
return true
}
if rc == nil {
return false

View File

@ -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 int = int(1 << 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: "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 float = 1.0 << 2; _ = a", err: false},
{stmt: "var a = 1.0 << 2; _ = a", err: false},
@ -1363,12 +1363,7 @@ func TestSyntaxOperatorShift(t *testing.T) {
{stmt: "a := vec3(1) << ivec2(2); _ = a", err: true},
{stmt: "a := ivec2(1) << vec3(2); _ = a", err: true},
{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 float = 1.0 >> 2.0; _ = 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 = 1.0 >> 2; _ = a", err: false},

View File

@ -165,7 +165,7 @@ func checkArgsForIntBuiltinFunc(args []shaderir.Expr, argts []shaderir.Type) err
if len(args) != 1 {
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 || argts[0].Main == shaderir.DeducedInt {
if argts[0].Main == shaderir.Int || argts[0].Main == shaderir.Float {
return nil
}
if args[0].Const != nil && gconstant.ToInt(args[0].Const).Kind() != gconstant.Unknown {

View File

@ -145,7 +145,7 @@ func TypeFromBinaryOp(op Op, lhst, rhst Type, lhsConst, rhsConst constant.Value)
}
if op == LeftShift || op == RightShift {
if (lhst.Main == Int || lhst.Main == DeducedInt) && rhst.Main == Int {
if lhst.Main == Int && rhst.Main == Int {
return Type{Main: lhst.Main}, true
}
if lhst.IsIntVector() && rhst.Main == Int {

View File

@ -180,7 +180,6 @@ const (
Texture
Array
Struct
DeducedInt
)
func descendantLocalVars(block, target *Block) ([]Type, bool) {