On Sun, Feb 23, 2020 at 8:19 AM Jimu Yang wrote:

> I am reading the doc about Assignability in Golang Specification
> <https://golang.org/ref/spec#Assignability> . It says:
>
> A value x is *assignable* to a variable
> <https://golang.org/ref/spec#Variables> of type T ("x is assignable to T")
> if one of the following conditions applies:
>
>    - ...
>    - x's type V and T have identical underlying types
>    <https://golang.org/ref/spec#Types> and at least one of V or T is not
>    a defined <https://golang.org/ref/spec#Type_definitions> type.
>    - ...
>
>
> type str string
>
> func main() {
> string1 := "string"
> var str1 str = "str1"
> str1 = string1 // cannot use string1 (type string) as type str in
> assignment
> }
>
>
> string1's type string and str have identical underlying type (string) and
> string is not a defined type.
>
> So why cannot i assign string1 to str1?
>

According to the language specification (
https://golang.org/ref/spec#String_types), string is a defined type, and so
it is distinct from your type str.

-- 
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/CAOU-OAJXB%3DkMDKcJWTjmcP6KmM_9WOVpUeqAiTnoU_3ciuY_Uw%40mail.gmail.com.

Reply via email to