interp: handle alias of an alias
When dealing with an alias of an alias, the actual underlying type of the source alias should be used.
This commit is contained in:
27
_test/alias4.go
Normal file
27
_test/alias4.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type A http.Header
|
||||||
|
|
||||||
|
func (a A) Test1() {
|
||||||
|
fmt.Println("test1")
|
||||||
|
}
|
||||||
|
|
||||||
|
type B A
|
||||||
|
|
||||||
|
func (b B) Test2() {
|
||||||
|
fmt.Println("test2")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
b := B{}
|
||||||
|
|
||||||
|
b.Test2()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// test2
|
||||||
@@ -2560,7 +2560,7 @@ func gotoLabel(s *symbol) {
|
|||||||
func compositeGenerator(n *node, typ *itype, rtyp reflect.Type) (gen bltnGenerator) {
|
func compositeGenerator(n *node, typ *itype, rtyp reflect.Type) (gen bltnGenerator) {
|
||||||
switch typ.cat {
|
switch typ.cat {
|
||||||
case aliasT, ptrT:
|
case aliasT, ptrT:
|
||||||
gen = compositeGenerator(n, n.typ.val, rtyp)
|
gen = compositeGenerator(n, typ.val, rtyp)
|
||||||
case arrayT, sliceT:
|
case arrayT, sliceT:
|
||||||
gen = arrayLit
|
gen = arrayLit
|
||||||
case mapT:
|
case mapT:
|
||||||
|
|||||||
@@ -239,6 +239,9 @@ func namedOf(val *itype, path, name string, opts ...itypeOption) *itype {
|
|||||||
if path != "" {
|
if path != "" {
|
||||||
str = path + "." + name
|
str = path + "." + name
|
||||||
}
|
}
|
||||||
|
for val.cat == aliasT {
|
||||||
|
val = val.val
|
||||||
|
}
|
||||||
t := &itype{cat: aliasT, val: val, path: path, name: name, str: str}
|
t := &itype{cat: aliasT, val: val, path: path, name: name, str: str}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(t)
|
opt(t)
|
||||||
|
|||||||
Reference in New Issue
Block a user