File tree Expand file tree Collapse file tree 3 files changed +53
-2
lines changed
Expand file tree Collapse file tree 3 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -518,7 +518,7 @@ func getTypeCodeName(t types.Type) (string, bool) {
518518 switch t := types .Unalias (t ).(type ) {
519519 case * types.Named :
520520 if t .Obj ().Parent () != t .Obj ().Pkg ().Scope () {
521- return "named:" + t .String () + "$local" , true
521+ return "named:" + t .String () + "$local:" + fmt . Sprintf ( "%p" , t . Obj (). Parent ()) , true
522522 }
523523 return "named:" + t .String (), false
524524 case * types.Array :
Original file line number Diff line number Diff line change 11package main
22
3- import "time"
3+ import (
4+ "reflect"
5+ "time"
6+ )
47
58func main () {
69 thing := & Thing {"foo" }
@@ -119,6 +122,10 @@ func main() {
119122
120123 // check that type asserts to interfaces with no methods work
121124 emptyintfcrash ()
125+
126+ // These are part of a test that checks that `main.Foo` can refer to 2+ different entities without getting them confused.
127+ namedFoo ()
128+ namedFoo2Nested ()
122129}
123130
124131func printItf (val interface {}) {
@@ -343,3 +350,41 @@ func emptyintfcrash() {
343350 println ("x is" , x .(int ))
344351 }
345352}
353+
354+ func namedFoo () {
355+ type Foo struct {
356+ A int
357+ }
358+ f1 := & Foo {}
359+ fcopy := copyOf (f1 )
360+ f2 := fcopy .(* Foo )
361+ println (f2 .A )
362+ }
363+
364+ func namedFoo2Nested () {
365+ type Foo struct {
366+ A * int
367+ }
368+ f1 := & Foo {}
369+ fcopy := copyOf (f1 )
370+ f2 := fcopy .(* Foo )
371+ println (f2 .A == nil )
372+
373+ if f2 .A == nil {
374+ type Foo struct {
375+ A * int
376+ }
377+ nestedf1 := & Foo {}
378+ fcopy := copyOf (nestedf1 )
379+ nestedf2 := fcopy .(* Foo )
380+ println (nestedf2 .A == nil )
381+ }
382+ }
383+
384+ func copyOf (src interface {}) (dst interface {}) {
385+ t := reflect .TypeOf (src )
386+ println (t .String ())
387+ dsti := reflect .New (t .Elem ())
388+ dst = dsti .Interface ()
389+ return dst
390+ }
Original file line number Diff line number Diff line change @@ -28,3 +28,9 @@ type is int
2828type is *int
2929type is **int
3030x is 5
31+ *main.Foo
32+ 0
33+ *main.Foo
34+ true
35+ *main.Foo
36+ true
You can’t perform that action at this time.
0 commit comments