You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both of these functions contain expressions (m[1] and <-ch) that appear in a
"value,ok" context.
func f() (i interface{}, ok bool) {
m := map[int]string{1: "hi"}
i, ok = m[1]
return
}
func g() (i interface{}, ok bool) {
ch := make(chan string, 1)
ch <- "hi"
i, ok = <- ch
return
}
I would expect the inferred types for both to be (string, bool), but in fact both are
(interface{}, bool). i.e. the type checker has incorporated the type conversion to the
assignment's LHS into the type that is inferred. This is not ideal because a compiler
(for example) would assume that no conversion is necessary since the LHS and RHS types
are identical.