Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func getTypeCodeName(t types.Type) (string, bool) {
switch t := types.Unalias(t).(type) {
case *types.Named:
if t.Obj().Parent() != t.Obj().Pkg().Scope() {
return "named:" + t.String() + "$local", true
return fmt.Sprintf("named:%s$local:%p", t.String(), t.Obj().Parent()), true
}
return "named:" + t.String(), false
case *types.Array:
Expand Down
47 changes: 46 additions & 1 deletion testdata/interface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "time"
import (
"reflect"
"time"
)

func main() {
thing := &Thing{"foo"}
Expand Down Expand Up @@ -119,6 +122,10 @@ func main() {

// check that type asserts to interfaces with no methods work
emptyintfcrash()

// These are part of a test that checks that `main.Foo` can refer to 2+ different entities without getting them confused.
namedFoo()
namedFoo2Nested()
}

func printItf(val interface{}) {
Expand Down Expand Up @@ -343,3 +350,41 @@ func emptyintfcrash() {
println("x is", x.(int))
}
}

func namedFoo() {
type Foo struct {
A int
}
f1 := &Foo{}
fcopy := copyOf(f1)
f2 := fcopy.(*Foo)
println(f2.A)
}

func namedFoo2Nested() {
type Foo struct {
A *int
}
f1 := &Foo{}
fcopy := copyOf(f1)
f2 := fcopy.(*Foo)
println(f2.A == nil)

if f2.A == nil {
type Foo struct {
A *int
}
nestedf1 := &Foo{}
fcopy := copyOf(nestedf1)
nestedf2 := fcopy.(*Foo)
println(nestedf2.A == nil)
}
}

func copyOf(src interface{}) (dst interface{}) {
t := reflect.TypeOf(src)
println(t.String())
dsti := reflect.New(t.Elem())
dst = dsti.Interface()
return dst
}
6 changes: 6 additions & 0 deletions testdata/interface.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ type is int
type is *int
type is **int
x is 5
*main.Foo
0
*main.Foo
true
*main.Foo
true
Loading