mirror of
https://github.com/golang/go
synced 2024-11-18 18:04:46 -07:00
reflect bug: NewZeroValue was refusing to create slices.
as far as I can tell there's no reason not to. the Nillable test was succeeding because NewZeroValue returned the nil interface value and the type guard was letting it through. the only change in the test is more detail in the print. R=r DELTA=8 (0 added, 7 deleted, 1 changed) OCL=29124 CL=29126
This commit is contained in:
parent
a39bae095a
commit
2d5d4a1b41
@ -543,7 +543,7 @@ func TestIsNil(t *testing.T) {
|
||||
ty := reflect.ParseTypeString("", ts);
|
||||
v := reflect.NewZeroValue(ty);
|
||||
if nilable, ok := v.(Nillable); !ok {
|
||||
t.Errorf("%s is not nilable; should be", ts)
|
||||
t.Errorf("%s %T is not nilable; should be", ts, v)
|
||||
}
|
||||
}
|
||||
// Check the implementations
|
||||
|
@ -876,13 +876,6 @@ func newValueAddr(typ Type, addr Addr) Value {
|
||||
|
||||
// NewZeroValue creates a new, zero-initialized Value for the specified Type.
|
||||
func NewZeroValue(typ Type) Value {
|
||||
// Some values cannot be made this way.
|
||||
switch typ.Kind() {
|
||||
case ArrayKind:
|
||||
if typ.(ArrayType).IsSlice() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
size := typ.Size();
|
||||
if size == 0 {
|
||||
size = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user