diff --git a/interp/interp_eval_test.go b/interp/interp_eval_test.go index 6f3a23ff..2a167248 100644 --- a/interp/interp_eval_test.go +++ b/interp/interp_eval_test.go @@ -77,6 +77,7 @@ func TestEvalShift(t *testing.T) { {src: "a, b, m := uint32(1), uint32(2), uint32(0); m = a + (1 << b)", res: "5"}, {src: "c := uint(1); d := uint(+(-(1 << c)))", res: "18446744073709551614"}, {src: "e, f := uint32(0), uint32(0); f = 1 << -(e * 2)", res: "1"}, + {src: "p := uint(0xdead); byte((1 << (p & 7)) - 1)", res: "31"}, {pre: func() { eval(t, i, "const k uint = 1 << 17") }, src: "int(k)", res: "131072"}, }) } diff --git a/interp/typecheck.go b/interp/typecheck.go index 307df9c8..56ee4e94 100644 --- a/interp/typecheck.go +++ b/interp/typecheck.go @@ -634,16 +634,13 @@ func (check typecheck) conversion(n *node, typ *itype) error { if !ok { return n.cfgErrorf("cannot convert expression of type %s to type %s", n.typ.id(), typ.id()) } - - if n.typ.untyped { - if isInterface(typ) || c != nil && !isConstType(typ) { - typ = n.typ.defaultType() - } - if err := check.convertUntyped(n, typ); err != nil { - return err - } + if !n.typ.untyped || c == nil { + return nil } - return nil + if isInterface(typ) || !isConstType(typ) { + typ = n.typ.defaultType() + } + return check.convertUntyped(n, typ) } type param struct {