]> Cypherpunks repositories - gostls13.git/commitdiff
do not create interfaces containing interfaces
authorRuss Cox <rsc@golang.org>
Wed, 15 Apr 2009 02:03:57 +0000 (19:03 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 15 Apr 2009 02:03:57 +0000 (19:03 -0700)
R=r
DELTA=16  (14 added, 0 deleted, 2 changed)
OCL=27464
CL=27466

src/lib/reflect/all_test.go
src/lib/reflect/value.go
src/runtime/iface.c

index ed1e9639be54d179f4ee5895e1c1fee50ca2fae8..514fe7038cdaef3e2e882ac06c2487ba12162a4b 100644 (file)
@@ -310,6 +310,12 @@ func TestInterfaceValue(t *testing.T) {
        assert(v2.Type().String(), "interface { }");
        v3 := v2.(reflect.InterfaceValue).Value();
        assert(v3.Type().String(), "float");
+       
+       i3 := v2.Interface();
+       if f, ok := i3.(float); !ok {
+               a, typ, c := sys.Reflect(i3);
+               t.Error("v2.Interface() did not return float, got ", typ);
+       }
 }
 
 func TestFunctionValue(t *testing.T) {
index 35488034723d3f407ab1d53889e1f13760f626ce..ac7ed2f84a57453a90ce457fcca2abecadeff381 100644 (file)
@@ -58,9 +58,12 @@ func (c *commonValue) Addr() Addr {
 
 func (c *commonValue) Interface() interface {} {
        var i interface {};
-       if c.typ.Size() > 8 {   // TODO(rsc): how do we know it is 8?
+       switch {
+       case c.typ.Kind() == InterfaceKind:
+               i = *(*interface{})(c.addr);
+       case c.typ.Size() > 8:  // TODO(rsc): how do we know it is 8?
                i = sys.Unreflect(uint64(uintptr(c.addr)), c.typ.String(), true);
-       } else {
+       default:
                if uintptr(c.addr) == 0 {
                        panicln("reflect: address 0 for", c.typ.String());
                }
index 07a57ec1f25f53c5b607a6ff8fb199cf23ee9e4a..e5de5d16d7e11a33c35e92c8918f4f83e6a2d905 100644 (file)
@@ -766,6 +766,11 @@ sys·Unreflect(uint64 it, String type, bool indir, Iface ret)
        if(cmpstring(type, emptystring) == 0)
                goto out;
 
+       if(type.len > 10 && mcmp(type.str, (byte*)"interface ", 10) == 0) {
+               printf("sys.Unreflect: cannot put %S in interface\n", type);
+               throw("sys.Unreflect");
+       }
+
        // if we think the type should be indirect
        // and caller does not, play it safe, return nil.
        sigt = findtype(type, indir);