diff --git a/src/reflect/value.go b/src/reflect/value.go index 814fdb5c..35bb2a89 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -1,24 +1,21 @@ package reflect import ( - _ "unsafe" // for go:linkname + "unsafe" ) // This is the same thing as an interface{}. type Value struct { typecode Type - value *uint8 + value unsafe.Pointer } func Indirect(v Value) Value { return v } -func ValueOf(i interface{}) Value - -//go:linkname _ValueOf reflect.ValueOf -func _ValueOf(i Value) Value { - return i +func ValueOf(i interface{}) Value { + return *(*Value)(unsafe.Pointer(&i)) } func (v Value) Interface() interface{} diff --git a/src/runtime/interface.go b/src/runtime/interface.go index 7eba2a79..3daf56d2 100644 --- a/src/runtime/interface.go +++ b/src/runtime/interface.go @@ -5,9 +5,11 @@ package runtime // Interfaces are represented as a pair of {typecode, value}, where value can be // anything (including non-pointers). +import "unsafe" + type _interface struct { typecode uintptr - value *uint8 + value unsafe.Pointer } // Return true iff both interfaces are equal. diff --git a/testdata/reflect.go b/testdata/reflect.go new file mode 100644 index 00000000..4493cdc5 --- /dev/null +++ b/testdata/reflect.go @@ -0,0 +1,12 @@ +package main + +import "reflect" + +type myint int + +func main() { + println("matching types") + println(reflect.TypeOf(int(3)) == reflect.TypeOf(int(5))) + println(reflect.TypeOf(int(3)) == reflect.TypeOf(uint(5))) + println(reflect.TypeOf(myint(3)) == reflect.TypeOf(int(5))) +} diff --git a/testdata/reflect.txt b/testdata/reflect.txt new file mode 100644 index 00000000..5228cf6b --- /dev/null +++ b/testdata/reflect.txt @@ -0,0 +1,4 @@ +matching types +true +false +false