I wonder why this code compiles in go. I expected a compiler error as I would with e.g. string:
package main
import (
"fmt"
)
type myMap map[string]int
type mySlice []int
type myChan chan int
type myString string
func main() {
var mm myMap
var m map[string]int
m = mm // fine, but expected compiler error
var ms mySlice
var s []int
s = ms // same with slices
var mc myChan
var c chan int
c = mc // or channels
var mstr myString
var str string
// str = mstr // error, as expected
fmt.Printf("%T %T %T %T %T %T %T %T\n", mm, m, ms, s, mc, c, mstr, str)
}
Playground
Why don't I get a type mismatch error with those special "reference types" map, slice and chan?