From 83cbca56577e1c8a961fb7bd88a10769ad6d57fd Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 21 Aug 2009 14:18:08 -0700 Subject: [PATCH] rewrite type rules for expressions and add shift examples DELTA=48 (22 added, 0 deleted, 26 changed) OCL=33657 CL=33668 --- doc/go_spec.html | 62 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 861546c9475..18357766d11 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -351,7 +351,7 @@ integer literals.

String literals

-String literals represent ideal string values. Ideal strings don't +String literals represent ideal string values. Ideal strings do not have a named type but they are compatible with type stringType identity and compatibility). There are two forms: raw string literals and interpreted string @@ -1037,7 +1037,7 @@ the zero value for the channel's type. After at least one such zero value has b received, closed(c) returns true.

-

General properties of types and values

+

Properties of types and values

Two types may be identical, compatible, or incompatible. @@ -1215,6 +1215,8 @@ Function values are equal if they refer to the same function.

  • Channel and map values are equal if they were created by the same call to makeMaking slices, maps, and channels). +When comparing two values of channel type, the channel value types +must be compatible but the channel direction is ignored.
  • Interface values may be compared if they have compatible static types. @@ -2391,30 +2393,50 @@ unary_op = "+" | "-" | "!" | "^" | "*" | "&" | "<-" .

    -The operand types in binary operations must be compatible, with the following exceptions: +Comparisons are discussed elsewhere +(§Comparison compatibility). +For other binary operators, the +operand types must be identical +(§Properties of types and values) +unless the operation involves +channels, shifts, or ideal constants.

    - +
    +var s uint = 33;
    +var i = 1<<s;          // 1 has type int
    +var j = int32(1<<s);   // 1 has type int32; j == 0
    +var u = uint64(1<<s);  // 1 has type uint64; u == 1<<33
    +var f = float(1<<s);   // illegal: 1 has type float, cannot shift
    +var g = float(1<<33);  // legal; 1<<33 is a constant shift operation; g == 1<<33
    +

    Unary operators have the highest precedence.