]> Cypherpunks repositories - gostls13.git/commitdiff
reflect bug: NewZeroValue was refusing to create slices.
authorRuss Cox <rsc@golang.org>
Wed, 20 May 2009 22:42:14 +0000 (15:42 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 20 May 2009 22:42:14 +0000 (15:42 -0700)
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

src/lib/reflect/all_test.go
src/lib/reflect/value.go

index 8d4ea4865176fdb9a1e975aeccac80a2cfa8c229..ec770078d49e58bda36881a0b960ea487fba8aaf 100644 (file)
@@ -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
index d20d8cbe01fa753db5a4875207aff7a33c64cbe6..e3258b11f32e13edcceda34cf010a3f059e35927 100644 (file)
@@ -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;