Commit df480036 authored by Bryan C. Mills's avatar Bryan C. Mills

spec: clarify “Constant expressions” for untyped operands

This change addresses the grammatical complexity described in
https://groups.google.com/forum/#!topic/golang-dev/RmP-LMC3g58.

Change-Id: Ib292b4ca9c880c7c1c8c992e7c033a0f8f951f2c
Reviewed-on: https://go-review.googlesource.com/106855Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent 4410934c
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of February 18, 2018",
"Subtitle": "Version of May 9, 2018",
"Path": "/ref/spec"
}-->
......@@ -4160,11 +4160,6 @@ operands and are evaluated at compile time.
Untyped boolean, numeric, and string constants may be used as operands
wherever it is legal to use an operand of boolean, numeric, or string type,
respectively.
Except for shift operations, if the operands of a binary operation are
different kinds of untyped constants, the operation and, for non-boolean operations, the result use
the kind that appears later in this list: integer, rune, floating-point, complex.
For example, an untyped integer constant divided by an
untyped complex constant yields an untyped complex constant.
</p>
<p>
......@@ -4174,9 +4169,17 @@ an untyped boolean constant. If the left operand of a constant
result is an integer constant; otherwise it is a constant of the same
type as the left operand, which must be of
<a href="#Numeric_types">integer type</a>.
Applying all other operators to untyped constants results in an untyped
constant of the same kind (that is, a boolean, integer, floating-point,
complex, or string constant).
</p>
<p>
Any other operation on untyped constants results in an untyped constant of the
same kind; that is, a boolean, integer, floating-point, complex, or string
constant.
If the untyped operands of a binary operation (other than a shift) are of
different kinds, the result is of the operand's kind that appears later in this
list: integer, rune, floating-point, complex.
For example, an untyped integer constant divided by an
untyped complex constant yields an untyped complex constant.
</p>
<pre>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment