Skip to content

Commit 58495a3

Browse files
committed
fix shift by uint64 (fixes #418)
1 parent e2a337c commit 58495a3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

compiler/expressions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
375375
return c.fixNumber(c.formatExpr("%e %s %e", e.X, op, e.Y), basic)
376376
}
377377
if e.Op == token.SHR && !isUnsigned(basic) {
378-
return c.fixNumber(c.formatParenExpr("%e >> $min(%e, 31)", e.X, e.Y), basic)
378+
return c.fixNumber(c.formatParenExpr("%e >> $min(%f, 31)", e.X, e.Y), basic)
379379
}
380380
y := c.newVariable("y")
381-
return c.fixNumber(c.formatExpr("(%s = %s, %s < 32 ? (%e %s %s) : 0)", y, c.translateImplicitConversion(e.Y, types.Typ[types.Uint]), y, e.X, op, y), basic)
381+
return c.fixNumber(c.formatExpr("(%s = %f, %s < 32 ? (%e %s %s) : 0)", y, e.Y, y, e.X, op, y), basic)
382382
case token.AND, token.OR:
383383
if isUnsigned(basic) {
384384
return c.formatParenExpr("(%e %t %e) >>> 0", e.X, e.Op, e.Y)

tests/misc_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,12 @@ func TestVendoring(t *testing.T) {
509509
t.Fail()
510510
}
511511
}
512+
513+
func TestShift(t *testing.T) {
514+
if x := uint(32); uint32(1)<<x != 0 {
515+
t.Fail()
516+
}
517+
if x := uint64(0); uint32(1)<<x != 1 {
518+
t.Fail()
519+
}
520+
}

0 commit comments

Comments
 (0)