From ec66d772c5fd7ad781f956c461ec2679961b42cf Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 5 Aug 2014 11:31:32 -0700 Subject: spec: comma-ok expressions return untyped boolean 2nd result Technically a language change, this cleanup is a completely backward compatible change that brings the boolean results of comma-ok expressions in line with the boolean results of comparisons: they are now all untyped booleans. The implementation effort should be minimal (less than a handfull lines of code, depending how well factored the implementation of comma-ok expressions is). Fixes issue 8189. LGTM=iant, r, rsc R=r, rsc, iant, ken CC=golang-codereviews https://codereview.appspot.com/112320045 --- doc/go_spec.html | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'doc') diff --git a/doc/go_spec.html b/doc/go_spec.html index 0200762dc..a32fa457c 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -2626,7 +2626,7 @@ Otherwise a[x] is illegal.

An index expression on a map a of type map[K]V -may be used in an assignment or initialization of the special form +used in an assignment or initialization of the special form

@@ -2636,11 +2636,9 @@ var v, ok = a[x]
 

-where the result of the index expression is a pair of values with types -(V, bool). In this form, the value of ok is +yields an additional untyped boolean value. The value of ok is true if the key x is present in the map, and -false otherwise. The value of v is the value -a[x] as in the single-result form. +false otherwise.

@@ -2825,7 +2823,7 @@ r := y.(io.Reader) // r has type io.Reader and y must implement both I and i

-If a type assertion is used in an assignment or initialization of the form +A type assertion used in an assignment or initialization of the special form

@@ -2835,13 +2833,10 @@ var v, ok = x.(T)
 

-the result of the assertion is a pair of values with types (T, bool). -If the assertion holds, the expression returns the pair (x.(T), true); -otherwise, the expression returns (Z, false) where Z -is the zero value for type T. +yields an additional untyped boolean value. The value of ok is true +if the assertion holds. Otherwise it is false and the value of v is +the zero value for type T. No run-time panic occurs in this case. -The type assertion in this construct thus acts like a function call -returning a value and a boolean indicating success.

@@ -3423,7 +3418,7 @@ f(<-ch)

-A receive expression used in an assignment or initialization of the form +A receive expression used in an assignment or initialization of the special form

@@ -3433,7 +3428,7 @@ var x, ok = <-ch
 

-yields an additional result of type bool reporting whether the +yields an additional untyped boolean result reporting whether the communication succeeded. The value of ok is true if the value received was delivered by a successful send operation to the channel, or false if it is a zero value generated because the -- cgit v1.2.1