mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
spec: examples of untyped boolean, string constants
This is a spec correction, not a language change. The implementations have behaved like this for years (and there are tests to that effect), and elsewhere in the spec true and false are defined to be untyped boolean constants. R=golang-dev, r CC=golang-dev https://golang.org/cl/5477047
This commit is contained in:
parent
6a47bb4974
commit
ef1c535727
1 changed files with 6 additions and 3 deletions
|
@ -3408,7 +3408,7 @@ untyped complex constant yields an untyped complex constant.
|
|||
|
||||
<p>
|
||||
A constant <a href="#Comparison_operators">comparison</a> always yields
|
||||
a constant of type <code>bool</code>. If the left operand of a constant
|
||||
an untyped boolean constant. If the left operand of a constant
|
||||
<a href="#Operators">shift expression</a> is an untyped constant, the
|
||||
result is an integer constant; otherwise it is a constant of the same
|
||||
type as the left operand, which must be of integer type
|
||||
|
@ -3427,8 +3427,11 @@ const d = 1 << 3.0 // d == 8 (untyped integer constant)
|
|||
const e = 1.0 << 3 // e == 8 (untyped integer constant)
|
||||
const f = int32(1) << 33 // f == 0 (type int32)
|
||||
const g = float64(2) >> 1 // illegal (float64(2) is a typed floating-point constant)
|
||||
const h = "foo" > "bar" // h == true (type bool)
|
||||
const j = 'w' + 1 // j == 'x' (untyped character constant)
|
||||
const h = "foo" > "bar" // h == true (untyped boolean constant)
|
||||
const j = true // j == true (untyped boolean constant)
|
||||
const k = 'w' + 1 // k == 'x' (untyped character constant)
|
||||
const l = "hi" // l == "hi" (untyped string constant)
|
||||
const m = string(k) // m == "x" (type string)
|
||||
const Σ = 1 - 0.707 // (untyped complex constant)
|
||||
const Δ = Σ + 2.0e-4 // (untyped complex constant)
|
||||
const Φ = iota*1i - 1/1i // (untyped complex constant)
|
||||
|
|
Loading…
Reference in a new issue