diff options
| author | Ondřej Surý <ondrej@sury.org> | 2011-08-24 13:23:15 +0200 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2011-08-24 13:23:15 +0200 |
| commit | 0b48c8ae1c27bfcc1f5b3f611e64f47321cd18c6 (patch) | |
| tree | 107ba5c251175c7ce0d07eeb4748967510c548e2 /src/pkg/reflect/value.go | |
| parent | 825e92f34920934f09dbf4c614dbd2913ba464cb (diff) | |
| download | golang-0b48c8ae1c27bfcc1f5b3f611e64f47321cd18c6.tar.gz | |
Imported Upstream version 2011.08.17
Diffstat (limited to 'src/pkg/reflect/value.go')
| -rw-r--r-- | src/pkg/reflect/value.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go index 82985c575..d3c510ac2 100644 --- a/src/pkg/reflect/value.go +++ b/src/pkg/reflect/value.go @@ -860,6 +860,9 @@ func (v Value) Interface() interface{} { } func (iv internalValue) Interface() interface{} { + if iv.kind == 0 { + panic(&ValueError{"reflect.Value.Interface", iv.kind}) + } if iv.method { panic("reflect.Value.Interface: cannot create interface value for method with bound receiver") } @@ -974,7 +977,7 @@ func (v Value) MapIndex(key Value) Value { flag := (iv.flag | ikey.flag) & flagRO elemType := typ.Elem() - elemWord, ok := mapaccess(iv.word, ikey.word) + elemWord, ok := mapaccess(typ.runtimeType(), iv.word, ikey.word) if !ok { return Value{} } @@ -996,7 +999,7 @@ func (v Value) MapKeys() []Value { if m != 0 { mlen = maplen(m) } - it := mapiterinit(m) + it := mapiterinit(iv.typ.runtimeType(), m) a := make([]Value, mlen) var i int for i = 0; i < len(a); i++ { @@ -1159,7 +1162,7 @@ func (iv internalValue) recv(nb bool) (val Value, ok bool) { if ch == 0 { panic("recv on nil channel") } - valWord, selected, ok := chanrecv(ch, nb) + valWord, selected, ok := chanrecv(iv.typ.runtimeType(), ch, nb) if selected { val = valueFromIword(0, t.Elem(), valWord) } @@ -1189,7 +1192,7 @@ func (iv internalValue) send(x Value, nb bool) (selected bool) { if ch == 0 { panic("send on nil channel") } - return chansend(ch, ix.word, nb) + return chansend(iv.typ.runtimeType(), ch, ix.word, nb) } // Set assigns x to the value v. @@ -1306,7 +1309,7 @@ func (v Value) SetMapIndex(key, val Value) { ival = convertForAssignment("reflect.Value.SetMapIndex", nil, iv.typ.Elem(), ival) } - mapassign(iv.word, ikey.word, ival.word, ival.kind != Invalid) + mapassign(iv.typ.runtimeType(), iv.word, ikey.word, ival.word, ival.kind != Invalid) } // SetUint sets v's underlying value to x. @@ -1717,14 +1720,14 @@ func convertForAssignment(what string, addr unsafe.Pointer, dst Type, iv interna func chancap(ch iword) int32 func chanclose(ch iword) func chanlen(ch iword) int32 -func chanrecv(ch iword, nb bool) (val iword, selected, received bool) -func chansend(ch iword, val iword, nb bool) bool +func chanrecv(t *runtime.Type, ch iword, nb bool) (val iword, selected, received bool) +func chansend(t *runtime.Type, ch iword, val iword, nb bool) bool func makechan(typ *runtime.Type, size uint32) (ch iword) func makemap(t *runtime.Type) iword -func mapaccess(m iword, key iword) (val iword, ok bool) -func mapassign(m iword, key, val iword, ok bool) -func mapiterinit(m iword) *byte +func mapaccess(t *runtime.Type, m iword, key iword) (val iword, ok bool) +func mapassign(t *runtime.Type, m iword, key, val iword, ok bool) +func mapiterinit(t *runtime.Type, m iword) *byte func mapiterkey(it *byte) (key iword, ok bool) func mapiternext(it *byte) func maplen(m iword) int32 |
