fix bug in IR regarding type aliases
Этот коммит содержится в:
родитель
cf2a7b5089
коммит
7732c6f449
3 изменённых файлов: 45 добавлений и 0 удалений
3
ir/ir.go
3
ir/ir.go
|
@ -178,6 +178,9 @@ func (p *Program) AddPackage(pkg *ssa.Package) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Program) addFunction(ssaFn *ssa.Function) {
|
func (p *Program) addFunction(ssaFn *ssa.Function) {
|
||||||
|
if _, ok := p.functionMap[ssaFn]; ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
f := &Function{Function: ssaFn}
|
f := &Function{Function: ssaFn}
|
||||||
f.parsePragmas()
|
f.parsePragmas()
|
||||||
p.Functions = append(p.Functions, f)
|
p.Functions = append(p.Functions, f)
|
||||||
|
|
38
testdata/alias.go
предоставленный
Обычный файл
38
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})
|
||||||
|
}
|
4
testdata/alias.txt
предоставленный
Обычный файл
4
testdata/alias.txt
предоставленный
Обычный файл
|
@ -0,0 +1,4 @@
|
||||||
|
x
|
||||||
|
apple
|
||||||
|
true
|
||||||
|
false
|
Загрузка…
Создание таблицы
Сослаться в новой задаче