Thank you all. 
i read all about defined types on the doc 
https://golang.org/ref/spec#String_types 
now i know many defined types (string bool int ...      but which are the 
"undefined" types? i didn't find a direct answer. 
my thinking is that the "literals" which including all type literals are 
not defined types. The following code confirms that.
could you give me a reference answer? 

type str string
var s str = "sdwf"

// boolean literal
type boolean bool
var b boolean = true

// integer literal
type integer int
var i integer = 1

// slice literal
type strarr []string
var strings []string = []string{"sfw"}
var strs strarr = strings

// pointer literal
type stringptr *string
var string1 string = "11"
var ptr stringptr = &string1






在 2020年2月23日星期日 UTC+8下午9:19:34,Jimu Yang写道:
>
> 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?
>

-- 
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/55a9008d-a7f0-4de1-a420-57f6bbb19774%40googlegroups.com.

Reply via email to