// `type A = B` is an alias: A and B are the same type object, so a value of // one assigns to the other and *A matches *B. stage4 built a new Named whose // underlying was B, which made them distinct and rejected `var c B = a`. // Aliases to another package's Named type keep the Named shape (the // export/import path rebuilds those as a clone carrying the target's methods), // so this covers the same-package cases. package main type B struct{ n int32 } type A = B type AliasSlice = []int32 type AliasInt = int32 type AliasPtr = *B func takesB(b *B) (r int32) { return b.n } func main() { a := A{n: 3} var c B = a p := &c var q *A = p if takesB(q) != 3 { panic("alias pointer did not match its target") } var s AliasSlice = []int32{:2} s[0] = 7 if s[0] != 7 { panic("alias slice element wrong") } var i AliasInt = 9 var j int32 = i if j+c.n != 12 { panic("alias int arithmetic wrong") } println(j + c.n) }