add tests for shift op: untyped const with typed const

This commit is contained in:
aoyako 2024-03-22 17:37:36 +09:00
parent b0a7fb36c7
commit 94bd02af48
2 changed files with 8 additions and 2 deletions

View File

@ -153,9 +153,9 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
shift, ok := gconstant.Int64Val(rhs[0].Const)
if !ok {
cs.addError(e.Pos(), fmt.Sprintf("unexpected %s type for: %s", rhs[0].Const.String(), e.Op))
} else {
v = gconstant.Shift(lhs[0].Const, op, uint(shift))
return nil, nil, nil, false
}
v = gconstant.Shift(lhs[0].Const, op, uint(shift))
default:
v = gconstant.BinaryOp(lhs[0].Const, op, rhs[0].Const)
}

View File

@ -1324,6 +1324,9 @@ func TestSyntaxOperatorShift(t *testing.T) {
{stmt: "a := 1 << 2.0; _ = a", err: false},
{stmt: "a := 1.0 << 2; _ = a", err: false},
{stmt: "a := 1.0 << 2.0; _ = a", err: false},
{stmt: "a := 1.0 << int(1); _ = a", err: false},
{stmt: "a := int(1) << 2.0; _ = a", err: false},
{stmt: "a := ivec2(1) << 2.0; _ = a", err: false},
{stmt: "var a = 1; b := a << 2.0; _ = b", err: false},
{stmt: "var a = 1; b := 2.0 << a; _ = b", err: false}, // PR: #2916
{stmt: "a := float(1.0) << 2; _ = a", err: true},
@ -1351,6 +1354,9 @@ func TestSyntaxOperatorShift(t *testing.T) {
{stmt: "a := 1 >> 2.0; _ = a", err: false},
{stmt: "a := 1.0 >> 2; _ = a", err: false},
{stmt: "a := 1.0 >> 2.0; _ = a", err: false},
{stmt: "a := 1.0 >> int(1); _ = a", err: false},
{stmt: "a := int(1) >> 2.0; _ = a", err: false},
{stmt: "a := ivec2(1) >> 2.0; _ = a", err: false},
{stmt: "var a = 1; b := a >> 2.0; _ = b", err: false},
{stmt: "var a = 1; b := 2.0 >> a; _ = b", err: false}, // PR: #2916
{stmt: "a := float(1.0) >> 2; _ = a", err: true},