File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,14 @@ func TypeOf(i interface{}) Type {
133133 return ValueOf (i ).typecode
134134}
135135
136+ func PtrTo (t Type ) Type {
137+ ptrType := t << 5 | 5 // 0b0101 == 5
138+ if ptrType >> 5 != t {
139+ panic ("reflect: PtrTo type does not fit" )
140+ }
141+ return ptrType
142+ }
143+
136144func (t Type ) String () string {
137145 return "T"
138146}
Original file line number Diff line number Diff line change @@ -265,6 +265,13 @@ func main() {
265265 println ("type assertion failed (but should succeed)" )
266266 }
267267
268+ if reflect .TypeOf (new (myint )) != reflect .PtrTo (reflect .TypeOf (myint (0 ))) {
269+ println ("PtrTo failed for type myint" )
270+ }
271+ if reflect .TypeOf (new (myslice )) != reflect .PtrTo (reflect .TypeOf (make (myslice , 0 ))) {
272+ println ("PtrTo failed for type myslice" )
273+ }
274+
268275 println ("\n struct tags" )
269276 TestStructTag ()
270277}
You can’t perform that action at this time.
0 commit comments