Hi folks, I am not sure but to me it seems that the third assignment in the below code adheres to assignability <https://golang.org/ref/spec#Assignability> rule #2 from the spec, yet it fails to compile:
package main import "fmt" /* Assignability rule #2 (https://golang.org/ref/spec#Assignability): A value x is assignable to a variable of type T if one of the following conditions applies: x's type V and T have identical underlying types and at least one of V or T is not a defined type. */ type intp *int type integer int func main() { i := 1 var ip1 *int var ip2 intp var i2 integer ip1 = &i // (1) assign *int to *int: ok - expected, both var expressions are of identical type *int ip2 = &i // (2) assign *int to intp: ok - expected, rule #2 satisfied i2 = i // (4) assign int to integer: fail - unexpected, rule #2 should allow this: // underlying type of integer is int and the type of i (int) is not a defined type // error: ./prog.go:23:5: cannot use i (type int) as type integer in assignment fmt.Println(ip1, ip2, i2) // avoid "variable declared but not used" error } (Playground link <https://play.golang.org/p/UZOSu8xdjQJ>) For pointers the rule works but not for non-pointer types. Or do I just fail to see the obvious... Thoughts? Thanks, Christoph -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c65746c9-f353-41cb-8a28-316c5ee4ccf6%40googlegroups.com.