]> Cypherpunks.ru repositories - gostls13.git/commitdiff
spec: improve the example in Type assertions section
authortask4233 <tks.m1205@gmail.com>
Tue, 2 Feb 2021 03:54:24 +0000 (03:54 +0000)
committerRobert Griesemer <gri@golang.org>
Tue, 2 Feb 2021 16:35:53 +0000 (16:35 +0000)
The example, var v, ok T1 = x.(T), can be interpreted as type T1 interface{} or type T = bool; type T1 = T.
Separating the example would help understanding for readers.

Change-Id: I179f4564e67f4d503815d29307df2cebb50c82f9
GitHub-Last-Rev: b34fffb6bb07cb2883bc313ef3bc9980b3dd4abe
GitHub-Pull-Request: golang/go#44040
Reviewed-on: https://go-review.googlesource.com/c/go/+/288472
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>

doc/go_spec.html

index 676407f6f2bfd0799393da0ad40bbcfd4fc56eb6..c9e14a3fec70b8762de6c1a9e6d0d80ad6c45fdc 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "Title": "The Go Programming Language Specification",
-       "Subtitle": "Version of Oct 7, 2020",
+       "Subtitle": "Version of Feb 2, 2021",
        "Path": "/ref/spec"
 }-->
 
@@ -3400,7 +3400,7 @@ A type assertion used in an <a href="#Assignments">assignment</a> or initializat
 v, ok = x.(T)
 v, ok := x.(T)
 var v, ok = x.(T)
-var v, ok T1 = x.(T)
+var v, ok interface{} = x.(T) // dynamic types of v and ok are T and bool
 </pre>
 
 <p>