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
package main
func main() {
type T string
var x string
var y T
x = y
y = x
_, _ = x, y
}
This program fails to compile:
prog.go:7: cannot use y (type T) as type string in assignment
prog.go:8: cannot use x (type string) as type T in assignment
It succeeds after running s/string/[]string/g.
I was expecting both versions to work due to the rule:
A value x is assignable to a variable of type T ("x is assignable to T")
if x's type V and T have identical underlying types and at least one
of V or T is not a named type."
According to the spec, the types of x and y have identical underlying type
in both versions of the program, string and []string respectively. I can't find
a justification for the failure of the string version.
The compiler is 6g at version go1.0.3.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: