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) {
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());
}
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);