diff --git a/ir/ir.go b/ir/ir.go index f3327a79..9d243bae 100644 --- a/ir/ir.go +++ b/ir/ir.go @@ -178,6 +178,9 @@ func (p *Program) AddPackage(pkg *ssa.Package) { } func (p *Program) addFunction(ssaFn *ssa.Function) { + if _, ok := p.functionMap[ssaFn]; ok { + return + } f := &Function{Function: ssaFn} f.parsePragmas() p.Functions = append(p.Functions, f) diff --git a/testdata/alias.go b/testdata/alias.go new file mode 100644 index 00000000..244bea5f --- /dev/null +++ b/testdata/alias.go @@ -0,0 +1,38 @@ +package main + +type x struct{} + +func (x x) name() string { + return "x" +} + +type y = x + +type a struct { + n int +} + +func (a a) fruit() string { + return "apple" +} + +type b = a + +type fruit interface { + fruit() string +} + +type f = fruit + +func main() { + // test a basic alias + println(y{}.name()) + + // test using a type alias value as an interface + var v f = b{} + println(v.fruit()) + + // test comparing an alias interface with the referred-to type + println(a{} == b{}) + println(a{2} == b{3}) +} diff --git a/testdata/alias.txt b/testdata/alias.txt new file mode 100644 index 00000000..17bcc884 --- /dev/null +++ b/testdata/alias.txt @@ -0,0 +1,4 @@ +x +apple +true +false