The following code works just fine:
type alias []byte
type data struct {
x alias
}
func main() {
s2 := []byte("s2")
s1 := &data{
x: s2,
}
var s4 alias = s2
fmt.Println(s1,s2, s4)
}
but the following doesn't compile
type alias string
type data struct {
x alias
}
func main() {
s2 := string("s2")
s1 := &data{
x: s2, // needs explicit alias(s2)
}
var s4 alias = s2 // needs explicit alias(s2)
fmt.Println(s1,s2, s4)
}
}
The only difference is the type alias changes from a slice of bytes to a string.
What's the difference between those types, that the one is auto-converted and the other is not?