aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-06-08 09:11:18 -0700
committerRobert Griesemer <gri@golang.org>2011-06-08 09:11:18 -0700
commit636c5fac2d8bf0f7df69b2ea3cc54aeba92e70c4 (patch)
treeec6bb0e0b9edc4e5433eebae038addd1e6ea656d
parenta609a6bb6386494e1025d4195b29abe7d97f1121 (diff)
downloadgo-636c5fac2d8bf0f7df69b2ea3cc54aeba92e70c4.tar.gz
go-636c5fac2d8bf0f7df69b2ea3cc54aeba92e70c4.zip
go spec: handle a corner case of a special case for shifts...
- Added some additional examples. - 6g appears to implement this semantics already. Fixes #658. R=rsc, r, iant, ken CC=golang-dev https://golang.org/cl/4538119
-rw-r--r--doc/go_spec.html9
1 files changed, 7 insertions, 2 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html
index 0c08e1464b..abf5b8f50e 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,5 +1,5 @@
<!-- title The Go Programming Language Specification -->
-<!-- subtitle Version of May 24, 2011 -->
+<!-- subtitle Version of June 7, 2011 -->
<!--
TODO
@@ -2720,7 +2720,9 @@ The right operand in a shift expression must have unsigned integer type
or be an untyped constant that can be converted to unsigned integer type.
If the left operand of a non-constant shift expression is an untyped constant,
the type of the constant is what it would be if the shift expression were
-replaced by its left operand alone.
+replaced by its left operand alone; the type is <code>int</code> if it cannot
+be determined from the context (for instance, if the shift expression is an
+operand in a comparison against an untyped constant).
</p>
<pre>
@@ -2729,6 +2731,9 @@ var i = 1&lt;&lt;s // 1 has type int
var j int32 = 1&lt;&lt;s // 1 has type int32; j == 0
var k = uint64(1&lt;&lt;s) // 1 has type uint64; k == 1&lt;&lt;33
var m int = 1.0&lt;&lt;s // legal: 1.0 has type int
+var n = 1.0&lt;&lt;s != 0 // legal: 1.0 has type int; n == false if ints are 32bits in size
+var o = 1&lt;&lt;s == 2&lt;&lt;s // legal: 1 and 2 have type int; o == true if ints are 32bits in size
+var p = 1&lt;&lt;s == 1&lt;&lt;33 // illegal if ints are 32bits in size: 1 has type int, but 1&lt;&lt;33 overflows int
var u = 1.0&lt;&lt;s // illegal: 1.0 has type float64, cannot shift
var v float32 = 1&lt;&lt;s // illegal: 1 has type float32, cannot shift
var w int64 = 1.0&lt;&lt;33 // legal: 1.0&lt;&lt;33 is a constant shift expression