mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
For a long time, there was a confusion between aliased types and named types (due to my misunderstanding of alias types in Go at that time). The type category `aliasT` has been renamed into `linkedT`, which is correct semantically. Aliased types are only declared using `typeSpecAssign`, and its processing is now distinct from `typeSpec` statement, used for named types. A `linkedT` type is obtained by a statement like `type A uint32`, where `A` type category is therefore `linkedT`. An aliased type is obtained by a statement like `type A = uint32` (notice the `=` sign, translating into `typeSpecAssign`). The semantic difference is that in the first linkedT form, `A` and `uint32` are 2 distinct types, instead of being strictly equivalent in the `typeSpecAssign` form (the 2 names lead to one type definition). Fixes #1416.
40 lines
394 B
Go
40 lines
394 B
Go
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 (b B) Test3() {
|
|
for k, vals := range b {
|
|
for _, v := range vals {
|
|
fmt.Println(k, v)
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
b := B{}
|
|
|
|
b.Test2()
|
|
b["test"] = []string{"a", "b"}
|
|
b.Test3()
|
|
}
|
|
|
|
// Output:
|
|
// test2
|
|
// test a
|
|
// test b
|