Go assignment shows error for int
but not for []int
slice.
working code here
package main
import (
"fmt"
)
type testType []int
func main() {
var i testType
var t []int
t = i
fmt.Println("Hello, playground", t, i)
}
However, if it is int
type the compiler will surely show errors here:
cannot use i (type testType) as type int in assignment
package main
import (
"fmt"
)
type testType int
func main() {
var i testType
var t int
t = i
fmt.Println("Hello, playground", t, i)
}
Why does it error out for the custom int
type and not the custom []int
type?