@@ -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: "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: "c := uint(1); d := uint(+(-(1 << c)))", res: "18446744073709551614"},
|
||||||
{src: "e, f := uint32(0), uint32(0); f = 1 << -(e * 2)", res: "1"},
|
{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"},
|
{pre: func() { eval(t, i, "const k uint = 1 << 17") }, src: "int(k)", res: "131072"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -634,16 +634,13 @@ func (check typecheck) conversion(n *node, typ *itype) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return n.cfgErrorf("cannot convert expression of type %s to type %s", n.typ.id(), typ.id())
|
return n.cfgErrorf("cannot convert expression of type %s to type %s", n.typ.id(), typ.id())
|
||||||
}
|
}
|
||||||
|
if !n.typ.untyped || c == nil {
|
||||||
if n.typ.untyped {
|
return nil
|
||||||
if isInterface(typ) || c != nil && !isConstType(typ) {
|
|
||||||
typ = n.typ.defaultType()
|
|
||||||
}
|
|
||||||
if err := check.convertUntyped(n, typ); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
if isInterface(typ) || !isConstType(typ) {
|
||||||
|
typ = n.typ.defaultType()
|
||||||
|
}
|
||||||
|
return check.convertUntyped(n, typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
type param struct {
|
type param struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user