Files
Marc VertesandGitHub fdb9e37938 interp: fix processing of aliased types
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.
2022-10-26 17:00:07 +02:00

38 lines
436 B
Go

package main
import "fmt"
type Root struct {
Name string
}
func (r *Root) Hello() {
fmt.Println("Hello", r.Name)
}
type One = Root
func main() {
one := &One{Name: "one"}
displayOne(one)
displayRoot(one)
root := &Root{Name: "root"}
displayOne(root)
displayRoot(root)
}
func displayOne(val *One) {
fmt.Println(val)
}
func displayRoot(val *Root) {
fmt.Println(val)
}
// Output:
// &{one}
// &{one}
// &{root}
// &{root}