1
0
mirror of https://github.com/golang/go synced 2024-09-24 01:20:13 -06:00
Commit Graph

594 Commits

Author SHA1 Message Date
Robert Griesemer
c0bd4f33cc spec: pick up a few corrections missed in prior commit
This CL picks up a couple of minor fixes that were present
in https://go-review.googlesource.com/#/c/36213/6..5 but
accidentally got dropped in https://go-review.googlesource.com/#/c/36213/
because I submitted from the wrong client.

Change-Id: I3ad0d20457152ea9a116cbb65a23eb0dc3a8525e
Reviewed-on: https://go-review.googlesource.com/36471
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-02-07 00:03:00 +00:00
Robert Griesemer
56c9b51b93 spec: introduce alias declarations and type definitions
To avoid confusion caused by the term "named type" (which now just
means a type with a name, but formerly meant a type declared with
a non-alias type declaration), a type declaration now comes in two
forms: alias declarations and type definitions. Both declare a type
name, but type definitions also define new types.

Replace the use of "named type" with "defined type" elsewhere in
the spec.

For #18130.

Change-Id: I49f5ddacefce90354eb65ee5fbf10ba737221995
Reviewed-on: https://go-review.googlesource.com/36213
Reviewed-by: Rob Pike <r@golang.org>
2017-02-06 23:51:47 +00:00
Robert Griesemer
f8b4123613 [dev.typealias] spec: use term 'embedded field' rather than 'anonymous field'
First steps towards defining type aliases in the spec.
This is a nomenclature clarification, not a language change.

The spec used all three terms 'embedded type', 'anonymous field',
and 'embedded field'. Users where using the terms inconsistently.

The notion of an 'anonymous' field was always misleading since they
always had a de-facto name. With type aliases that name becomes even
more important because we may have different names for the same type.

Use the term 'embedded field' consistently and remove competing
terminology.

For #18130.

Change-Id: I2083bbc85788cab0b2e2cb1ff58b2f979491f001
Reviewed-on: https://go-review.googlesource.com/35108
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2017-01-31 17:12:17 +00:00
Robert Griesemer
b01f612a69 spec: add subtitles to section on "for" statements
This matches what we already do for switch statements and makes
this large section more visibly organized. No other changes besides
introducing the titles.

Fixes #4486.

Change-Id: I73f274e4fdd27c6cfeaed79090b4553e57a9c479
Reviewed-on: https://go-review.googlesource.com/33410
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-11-18 20:26:11 +00:00
Robert Griesemer
0eb26fa8ba spec: remove => (alias) operator from Operators and Delimiters section
(Revert of https://go-review.googlesource.com/#/c/32310/)

For #16339.
Fixes #17975.

Change-Id: I36062703c423a81ea1c5b00f4429a4faf00b3782
Reviewed-on: https://go-review.googlesource.com/33365
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-11-18 17:45:45 +00:00
Robert Griesemer
120cf676ca spec: clarify type elision rules for composite literals
- organize examples better
- add an example illustrating behavior if element type is a named pointer type
- both compilers and go/types (per https://go-review.googlesource.com/33358)
  follow this now

See the issue for detailed discussion.

Fixes #17954.

Change-Id: I8d90507ff2347d9493813f75b73233819880d2b4
Reviewed-on: https://go-review.googlesource.com/33361
Reviewed-by: Rob Pike <r@golang.org>
2016-11-18 17:25:07 +00:00
Robert Griesemer
87f4e36ce7 Revert "spec: add new language for alias declarations"
This reverts commit aff37662d1.

Reason: Decision to back out current alias implementation.
https://github.com/golang/go/issues/16339#issuecomment-258527920

Fixes #16339.
Fixes #17746.
Fixes #17784.

Change-Id: I5737b830d7f6fb79cf36f26403b4ad8533ba1dfe
Reviewed-on: https://go-review.googlesource.com/32813
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2016-11-04 19:57:23 +00:00
Robert Griesemer
7fd6b925e3 spec: update operator and delimiter section
Follow-up on https://go-review.googlesource.com/30601.

Change-Id: I51b603a6c4877b571e83cd7c4e78a8988cc831ca
Reviewed-on: https://go-review.googlesource.com/32310
Reviewed-by: Rob Pike <r@golang.org>
2016-10-28 17:05:48 +00:00
Robert Griesemer
aff37662d1 spec: add new language for alias declarations
For #16339.

Change-Id: I7d912ea634bbfacfc0217f97dccb270fde06f16b
Reviewed-on: https://go-review.googlesource.com/30601
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-27 17:48:02 +00:00
Robert Griesemer
023bb034e9 spec: slightly more realistic example for type assertions
For #17428.

Change-Id: Ia902b50cf0c40e3c2167fb573a39d328331c38c7
Reviewed-on: https://go-review.googlesource.com/31449
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-10-19 17:16:55 +00:00
Robert Griesemer
8fbfdad281 spec: require 16 bit minimum exponent in constants rather than 32
A 16bit binary exponent permits a constant range covering roughly the range
from 7e-9865 to 7e9863 which is more than enough for any practical and
hypothetical constant arithmetic.

Furthermore, until recently cmd/compile could not handle very large exponents
correctly anyway; i.e., the chance that any real programs (but for tests that
explore corner cases) are affected are close to zero.

Finally, restricting the minimum supported range significantly reduces the
implementation complexity in an area that hardly matters in reality for new
or alternative spec-compliant implementations that don't or cannot rely on
pre-existing arbitratry precision arithmetic packages that support a 32bit
exponent range.

This is technically a language change but for the reasons mentioned above
this is unlikely to affect any real programs, and certainly not programs
compiled with the gc or gccgo compilers as they currently support up to
32bit exponents.

Fixes #13572.

Change-Id: I970f919c57fc82c0175844364cf48ea335f17d39
Reviewed-on: https://go-review.googlesource.com/17711
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-18 22:36:50 +00:00
Robert Griesemer
5567b87891 spec: fix examples for predeclared function complex
Fixes #17398.

Change-Id: Iac7899031c1bfbadc4f84e5b374eaf1f01dff8c8
Reviewed-on: https://go-review.googlesource.com/31190
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-10-14 19:58:27 +00:00
Robert Griesemer
a016ecfdcb spec: clarify acceptable indices in array/slice composite literals
This simply documents the status quo accepted by cmd/compile, gccgo,
and go/types. The new language matches the language used for indices
of index expressions for arrays and slices.

Fixes #16679.

Change-Id: I65447889fbda9d222f2a9e6c10334d1b38c555f0
Reviewed-on: https://go-review.googlesource.com/30474
Reviewed-by: Rob Pike <r@golang.org>
2016-10-06 20:37:39 +00:00
Robert Griesemer
5c7a005266 spec: ignore struct tags when converting structs
This is a backwards-compatible language change.

Per the proposal (#16085), the rules for conversions are relaxed
such that struct tags in any of the structs involved in the conversion
are ignored (recursively).

Because this is loosening the existing rules, code that compiled so
far will continue to compile.

For #16085.
Fixes #6858.

Change-Id: I0feef651582db5f23046a2331fc3f179ae577c45
Reviewed-on: https://go-review.googlesource.com/24190
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-04 17:07:37 +00:00
Robert Griesemer
f8555ea6fd spec: update language on type switches to match implementations
See the issue below for details.

Fixes #16794.

Change-Id: I7e338089fd80ddcb634fa80bfc658dee2772361c
Reviewed-on: https://go-review.googlesource.com/27356
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-09-01 04:37:16 +00:00
Robert Griesemer
a656390b69 spec: clarify text on init functions
For #16874.

Change-Id: I2e13f582297606e506d805755a6cfc1f3d4306a2
Reviewed-on: https://go-review.googlesource.com/27817
Reviewed-by: Rob Pike <r@golang.org>
2016-08-26 06:10:32 +00:00
Robert Griesemer
507051d694 spec: complete list of special comma-ok forms
The enumerations didn't include the syntactic form where the lhs is
full variable declaration with type specification, as in:

var x, ok T = ...

Fixes #15782.

Change-Id: I0f7bafc37dc9dcf62cdb0894a0d157074ccd4b3e
Reviewed-on: https://go-review.googlesource.com/27670
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2016-08-24 21:24:28 +00:00
Robert Griesemer
3b967be421 spec: undo spec date change introduced by prior commit
I accidentally included a modified spec in
https://go-review.googlesource.com/27290 .
Remove that change.

Change-Id: Icb62fe829072860e9eb74865d21e06f30efcfd26
Reviewed-on: https://go-review.googlesource.com/27357
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-08-18 20:24:45 +00:00
Robert Griesemer
fd8028dec9 go/types: fix scope extents for range and type switch variables
The changes match the existing compilers, and assume an adjusted
spec (per issue #16794).

Fixes #15686.

Change-Id: I72677ce75888c41a8f3c2963117a2f2d5501c42b
Reviewed-on: https://go-review.googlesource.com/27290
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-18 20:07:05 +00:00
Robert Griesemer
3d81d4adc9 spec: document that duplicate types are invalid in type switches
Both compilers and also go/types don't permit duplicate types in
type switches; i.e., this spec change is documenting a status quo
that has existed for some time.

Furthermore, duplicate nils are not accepted by gccgo or go/types;
and more recently started causing a compiler error in gc. Permitting
them is inconsistent with the existing status quo.

Rather than making it an implementation restriction (as we have for
expression switches), this is a hard requirement since it was enforced
from the beginning (except for duplicate nils); it is also a well
specified requirement that does not pose a significant burden for
an implementation.

Fixes #15896.

Change-Id: If12db5bafa87598b323ea84418cb05421e657dd8
Reviewed-on: https://go-review.googlesource.com/23584
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-05-31 23:53:43 +00:00
Robert Griesemer
0436a89a2c spec: be more explicit about equivalence of empty string and absent field tags
Note that the spec already makes that point with a comment in the very first
example for struct field tags. This change is simply stating this explicitly
in the actual spec prose.

- gccgo and go/types already follow this rule
- the current reflect package API doesn't distinguish between absent tags
  and empty tags (i.e., there is no discoverable difference)

Fixes #15412.

Change-Id: I92f9c283064137b4c8651630cee0343720717a02
Reviewed-on: https://go-review.googlesource.com/22391
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2016-04-25 19:21:40 +00:00
Robert Griesemer
5213cd7000 spec: fix incorrect comment in shift example
- adjusted example code
- fixed comments

Fixes #14785.

Change-Id: Ia757dc93b0a69b8408559885ece7f3685a37daaa
Reviewed-on: https://go-review.googlesource.com/22353
Reviewed-by: Rob Pike <r@golang.org>
2016-04-21 20:58:54 +00:00
Robert Griesemer
b5ddbb90bf spec: refine rules about terminating statements
Per a suggestion from mdempsky.

Both gc and gccgo consider a statement list as terminating if the
last _non_empty_ statement is terminating; i.e., trailing semis are
ok. Only gotype followed the current stricter rule in the spec.

This change adjusts the spec to match gc and gccgo behavior. In
support of this change, the spec has a matching rule for fallthrough,
which in valid positions may be followed by trailing semis as well.

For details and examples, see the issue below.

Fixes #14422.

Change-Id: Ie17c282e216fc40ecb54623445c17be111e17ade
Reviewed-on: https://go-review.googlesource.com/19981
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-04-19 17:34:12 +00:00
Robert Griesemer
5583e8a421 spec: fix EBNF for slice syntax
The () parentheses grouped wrongly. Removed them completely in
favor of separate 2- and 3-index slice alternatives which is
clearer.

Fixes #14477.

Change-Id: I0b7521ac912130d9ea8740b8793b3b88e2609418
Reviewed-on: https://go-review.googlesource.com/19853
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-02-23 19:18:25 +00:00
Robert Griesemer
212bdd95e0 spec: New year, new spec update (to refer to Unicode 8.0).
Slightly rephrased sentence to emphasize the contents of the
Unicode categories w/o repeating the full category name each
time.

Fixes #13414.

Change-Id: Icd32ff1547fa81e866c5937a631c3344bb6087c6
Reviewed-on: https://go-review.googlesource.com/18265
Reviewed-by: Rob Pike <r@golang.org>
2016-01-05 22:39:26 +00:00
Shenghou Ma
ca9876dd2f doc: fix typo
Fixes #13780.

Change-Id: I629e2ba79b74d693e04c3747812c9a686cae5335
Reviewed-on: https://go-review.googlesource.com/18218
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-01 05:00:12 +00:00
Robert Griesemer
57c81ef257 spec: be clearer about which parameter section can be variadic
Fixes #13595.

Change-Id: I870ddc97ea25b7f6f7a1bb1a78e5e4874fba1ddc
Reviewed-on: https://go-review.googlesource.com/17871
Reviewed-by: Rob Pike <r@golang.org>
2015-12-15 21:58:04 +00:00
Robert Griesemer
7305b55e98 spec: clarify examples for struct field tags
Fixes #13420.

Change-Id: Id64ebd0527881450fdaffbb66d8b1831a6b7c43c
Reviewed-on: https://go-review.googlesource.com/17263
Reviewed-by: Rob Pike <r@golang.org>
2015-11-30 22:24:13 +00:00
Robert Griesemer
09e900eb33 spec: clarify that iota is incremented even if not used in a const spec
Slightly modified an example.

Fixes #13371.

Change-Id: I25d260d4200086a0ef9725950132b760657610c5
Reviewed-on: https://go-review.googlesource.com/17209
Reviewed-by: Rob Pike <r@golang.org>
2015-11-26 17:10:22 +00:00
Matthew Dempsky
ff85f86877 spec: remove "untyped bool" oxymorons
The proper term is "untyped boolean".

Change-Id: Id871164190a03c64a8a8987b1ad5d8653a21d96e
Reviewed-on: https://go-review.googlesource.com/16135
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-10-20 22:08:17 +00:00
Robert Griesemer
55ecda4ffd spec: clarify numeric conversions where IEEE-754 produces -0.0
The spec defines precise numeric constants which do not overflow.
Consequently, +/-Inf and NaN values were excluded. The case was not
clear for -0.0 but they are mostly of interest to determine the sign
of infinities which don't exist.

That said, the conversion rules explicitly say that T(x) (for a numeric
x and floating-point type T) is the value after rounding per IEEE-754.
The result is constant if x is constant. Rounding per IEEE-754 can
produce a -0.0 which we cannot represent as a constant.

Thus, the spec is inconsistent. Attempt to fix the inconsistency by
adjusting the rounding rule rather than letting -0.0 into the language.

For more details, see the issue below.

Open to discussion.

Fixes #12576.

Change-Id: Ibe3c676372ab16d9229f1f9daaf316f761e074ee
Reviewed-on: https://go-review.googlesource.com/14727
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-10-20 18:16:57 +00:00
Robert Griesemer
c720875b76 spec: minor adjustment of prose in composite literal section
The prose discussing composite literals referred to the composite
literal type with 'LiteralType', denoting the literal type's EBNF
production explicitly. Changed 'LiteralType' to 'literal type' to
remove the literal (no pun intended) connection and instead mean
the underlying type. Seems a simpler and more readable change
than referring to the underlying type everywhere explicitly.

Fixes #12717.

Change-Id: I225df95f9ece2664b19068525ea8bda5ca05a44a
Reviewed-on: https://go-review.googlesource.com/14851
Reviewed-by: Rob Pike <r@golang.org>
2015-09-23 21:26:10 +00:00
Robert Griesemer
3b0224282c spec: fix composite literal syntax to match prose
Fixes #12578.

Change-Id: I257d70a67609463e24936bc1739285da154be2fe
Reviewed-on: https://go-review.googlesource.com/14531
Reviewed-by: Rob Pike <r@golang.org>
2015-09-12 00:45:55 +00:00
Robert Griesemer
98aa82287f spec: clarify semantics of built-in functions 'complex', 'real', and 'imag'
For #11669, #11540, #11945, #11946, #11947.

Change-Id: Ifb0053c498cee9f3473c396f9338d82bd856c110
Reviewed-on: https://go-review.googlesource.com/12860
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-08-05 21:09:49 +00:00
Robert Griesemer
3dd3ab41ac spec: better organization of arithmetic operator section
First step towards cleaning up the operator section - no language
changes. Specifically:

- Grouped arithmetic operations by types (integer, floating-point,
  string), with corresponding h4 headings.

- Changed Operator precedence title from h3 to h4.

- Moved Integer Overflow section after integer operations and changed
  its title from h3 to h4.

This puts things that belong together closer. No heading id's were
lost (in case of references from outside the spec).

Change-Id: I6b349ba8d86a6ae29b596beb297cc45c81e69399
Reviewed-on: https://go-review.googlesource.com/13143
Reviewed-by: Rob Pike <r@golang.org>
2015-08-05 17:05:07 +00:00
Robert Griesemer
05614bfcfa spec: fix inconsistency of visibility rules for method names
Inconsistency identified by Anmol Sethi (anmol@aubble.com).

Fixes #10341.

Change-Id: I1a1f5b22aad29b56280f81026feaa37a61b3e0a9
Reviewed-on: https://go-review.googlesource.com/13132
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-05 17:03:36 +00:00
Robert Griesemer
85789daac3 spec: clarify that short variable declarations can redeclare parameters
Fixes #9837.

Change-Id: Ia513c7e5db221eee8e3ab0affa6d3688d2099fd9
Reviewed-on: https://go-review.googlesource.com/13130
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-05 17:01:05 +00:00
Robert Griesemer
87c8707e6f spec: clarify sentence about non-constant shifts
Fixes #10514.

Change-Id: Iae95a304d3ebb1ed82567aa234e05dc434db984f
Reviewed-on: https://go-review.googlesource.com/13098
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-05 17:00:11 +00:00
Robert Griesemer
02d74485e4 spec: fixed various example code snippets
Per suggestions by Peter Olsen (https://github.com/pto).

Fixes #11964.

Change-Id: Iae261ac14f75abf848f5601f59d7fe6e95b6805a
Reviewed-on: https://go-review.googlesource.com/13006
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-31 20:38:44 +00:00
Robert Griesemer
2d9378c7f6 spec: document existing expression switch restrictions
The spec didn't specify several aspects of expression switches:

- The switch expression is evaluated exactly once.

- Switch expressions evaluating to an untyped value are converted
  to the respective default type before use.

- An (untyped) nil value is not permitted as expression switch
  value. (We could permit it relatively easily, but gc doesn't,
  and disallowing it is in symmetry with the rules for var decls
  without explicit type and untyped initializer expressions.)

- The comparison x == t between each case expression x and
  switch expression value t must be valid.

- (Some) duplicate constant case expressions are not permitted.

This change also clarifies the following issues:

 4524: mult. equal int const switch case values should be illegal
                                         -> spec issue fixed
 6398: switch w/ no value uses bool rather than untyped bool
                                         -> spec issue fixed
11578: allows duplicate switch cases     -> go/types bug
11667: int overflow in switch expression -> go/types bug
11668: use of untyped nil in switch      -> not a gc bug

Fixes #4524.
Fixes #6398.
Fixes #11668.

Change-Id: Iae4ab3e714575a5d11c92c9b8fbf027aa706b370
Reviewed-on: https://go-review.googlesource.com/12711
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-07-30 23:11:20 +00:00
Robert Griesemer
37a097519f spec: be precise about rune/string literals and comments
See #10248 for details.

Fixes #10248.

Change-Id: I373545b2dca5d1da1c7149eb0a8f6c6dd8071a4c
Reviewed-on: https://go-review.googlesource.com/10503
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-07-23 17:34:17 +00:00
Paolo Martini
3549178e55 doc: fix typo
The document `doc/go_spec.html` uses "preceeding" instead of the word
"preceding" in one place.

Fixed another occurrence in `src/go/types/typexpr.go`.

Change-Id: Ic67f62026b5c9d002c5c5632299f14ecac8b02ae
Reviewed-on: https://go-review.googlesource.com/12354
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-17 22:33:51 +00:00
Rob Pike
a4ec50bd0b spec: fix bare & in HTML
No need to update the date; this is not a spec change.

Change-Id: I10a31234ed985c59e5d9b5328664a36661cef31e
Reviewed-on: https://go-review.googlesource.com/11531
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-06-26 02:51:30 +00:00
Robert Griesemer
d8c6dac7ca spec: clarify effect of rounding of constant expressions
Not a language change.

Fixes #11350.

Change-Id: I9b905f17d1ef2722cab4bae38a037270165c7d95
Reviewed-on: https://go-review.googlesource.com/11369
Reviewed-by: Rob Pike <r@golang.org>
2015-06-23 22:19:38 +00:00
Robert Griesemer
637d59859d spec: clarify meaning of x op= y
Suggested by mdempsky (see also issue #11161).

Change-Id: I1ab28febe19b7a092029499015073ce8749b4d99
Reviewed-on: https://go-review.googlesource.com/10960
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-11 22:41:07 +00:00
Robert Griesemer
310fb9e808 spec: removed TODOs (invisible html comment) in favor of issues
- no "visible" change to spec but for updated date
- retired several outdated TODO items
- filed non-urgent issues 10953, 10954, 10955 for current TODOs

Change-Id: If87ad0fb546c6955a6d4b5801e06e5c7d5695ea2
Reviewed-on: https://go-review.googlesource.com/10382
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-26 21:04:10 +00:00
Robert Griesemer
f9ec929aaf spec: fix typo
Fixes #10893.

Change-Id: I8afeb55acda1e1c8e181379dbaf443716d63ded1
Reviewed-on: https://go-review.googlesource.com/10201
Reviewed-by: Rob Pike <r@golang.org>
2015-05-18 18:29:37 +00:00
Matthew Dempsky
abb818bc03 spec: fix binary expression grammar rule
The spec explains later in the "Operator precedence" section that *
has a higher precedence than +, but the current production rule
requires that "1 + 2 * 3" be parsed as "(1 + 2) * 3", instead of the
intended "1 + (2 * 3)".

The new production rule better matches cmd/internal/gc/go.y's grammar:

    expr:
            uexpr
    |       expr LOROR expr
    |       expr LANDAND expr
    |       ...

Fixes #10151.

Change-Id: I13c9635d6ddf1263cafe7cc63e68f3e5779e24ba
Reviewed-on: https://go-review.googlesource.com/9163
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-05-13 17:40:38 +00:00
Robert Griesemer
7727dee445 spec: extend type omission rules for composite literal element values
to map element keys

Composite literals containing element values that are themselves composite
literals may leave away the element's literal types if they are identical
to the enclosing composite literal's element type.

(http://golang.org/ref/spec#Composite_literals)

When we made this change, we forgot to apply the analogous rule to map
literal keys. This change generalizes that rule. Added more examples,
including one showing the recursive application of the elision rules.

This is a fully backward-compatible language change. It was discussed
some time back.

Fixes #8589.

To be submitted once all compilers accept the extension.

Change-Id: I4d45b64b5970f0d5501572945d5a097e64a9458b
Reviewed-on: https://go-review.googlesource.com/2591
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-03-20 23:06:28 +00:00
Shenghou Ma
c0abdd9f29 doc/go_spec: fix typo
Fixes #9445

Change-Id: If7abd4d4d41cdfd5cf677f03533c930c8b965a01
Reviewed-on: https://go-review.googlesource.com/2128
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-12-26 08:16:29 +00:00
Brad Fitzpatrick
5f029deb39 doc: fix comment type typo
Fixes #9418

Change-Id: I044fa1d26d972f012f00388a84c4d0f143cf4f63
Reviewed-on: https://go-review.googlesource.com/1970
Reviewed-by: Robert Griesemer <gri@golang.org>
2014-12-22 18:00:07 +00:00
David Symonds
583b29cb18 spec: add comment marker for consistency.
LGTM=r
R=gri, r
CC=golang-codereviews
https://golang.org/cl/185830043
2014-12-04 09:29:29 +11:00
Robert Griesemer
40818cfe1c spec: method selectors don't auto-deref named pointer types
Language clarification.

The existing rules for selector expressions imply
automatic dereferencing of pointers to struct fields.
They also implied automatic dereferencing of selectors
denoting methods. In almost all cases, such automatic
dereferencing does indeed take place for methods but the
reason is not the selector rules but the fact that method
sets include both methods with T and *T receivers; so for
a *T actual receiver, a method expecting a formal T
receiver, also accepts a *T (and the invocation or method
value expression is the reason for the auto-derefering).

However, the rules as stated so far implied that even in
case of a variable p of named pointer type P, a selector
expression p.f would always be shorthand for (*p).f. This
is true for field selectors f, but cannot be true for
method selectors since a named pointer type always has an
empty method set.

Named pointer types may never appear as anonymous field
types (and method receivers, for that matter), so this
only applies to variables declared of a named pointer
type. This is exceedingly rare and perhaps shouldn't be
permitted in the first place (but we cannot change that).

Amended the selector rules to make auto-deref of values
of named pointer types an exception to the general rules
and added corresponding examples with explanations.

Both gc and gccgo have a bug where they do auto-deref
pointers of named types in method selectors where they
should not:

See http://play.golang.org/p/c6VhjcIVdM , line 45.

Fixes #5769.
Fixes #8989.

LGTM=r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/168790043
2014-11-11 13:19:47 -08:00
Robert Griesemer
ccc713c7ca spec: permit parentheses around builtin function names
Not a language change.

This is simply documenting the status quo which permits
builtin function names to be parenthesized in calls; e.g.,
both

        len(s)
and
        (((len)))(s)

are accepted by all compilers and go/types.

Changed the grammar by merging the details of BuiltinCall
with ordinary Calls. Also renamed the Call production to
Arguments which more clearly identifies that part of the
grammar and also matches better with its counterpart on
the declaration side (Parameters).

The fact that the first argument can be a type (for builtins)
or cannot be a type (for regular function calls) is expressed
in the prose, no need to make the grammar more complicated.

Fixes #9001.

LGTM=iant, r, rsc
R=r, rsc, iant, ken, dave
CC=golang-codereviews
https://golang.org/cl/160570043
2014-10-27 16:31:15 -07:00
Robert Griesemer
5361b747b7 spec: minimal documention of unsafe.Pointer conversions
Per suggestion from rsc as a result of the dicussion of
(abandoned) CL 153110044.

Fixes #7192.

LGTM=r, rsc, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/163050043
2014-10-23 09:45:11 -07:00
Robert Griesemer
6962c15cec spec: define "variable"
Fixes #8496.

LGTM=rsc, r, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/148580043
2014-10-16 15:08:49 -07:00
Robert Griesemer
47094dcf09 spec: clarify variable declaration type rules
Not a language change.

Several inaccuracies were fixed:

1) A variable declaration may declare more than just one
variable.

2) Variable initialization follows the rules of assignments,
including n:1 assignments. The existing wording implied a 1:1
or n:n rule and generally was somewhat unspecific.

3) The rules for variable declarations with no types and
untyped initialization expressions had minor holes (issue 8088).

4) Clarified the special cases of assignments of untyped values
(we don't just have untyped constants, but also untyped bools,
e.g. from comparisons). The new wording is more direct.

To that end, introduced the notion of an untyped constant's
"default type" so that the same concept doesn't have to be
repeatedly introduced.

Fixes #8088.

LGTM=iant, r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/142320043
2014-09-30 11:44:29 -07:00
Robert Griesemer
259f0ffade spec: specify variable initialization order explicitly
The existing spec rules on package initialization were
contradictory: They specified that 1) dependent variables
are initialized in dependency order, and 2) independent
variables are initialized in declaration order. This 2nd
rule cannot be satisfied in general. For instance, for

var (
        c = b + 2
        a = 0
        b = 1
)

because of its dependency on b, c must be initialized after b,
leading to the partial order b, c. Because a is independent of
b but is declared before b, we end up with the order: a, b, c.
But a is also independent of c and is declared after c, so the
order b, c, a should also be valid in contradiction to a, b, c.

The new rules are given in form of an algorithm which outlines
initialization order explicitly.

gccgo and go/types already follow these rules.

Fixes #8485.

LGTM=iant, r, rsc
R=r, rsc, iant, ken, gordon.klaus, adonovan
CC=golang-codereviews
https://golang.org/cl/142880043
2014-09-29 12:44:50 -07:00
Robert Griesemer
2fa3e43fae spec: clarify scope and re-use of iteration variables
Fixes #7834.

LGTM=iant, rsc, r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/148940044
2014-09-25 12:52:05 -07:00
Robert Griesemer
bb29c5a1ed spec: clarify embedding of interfaces
Fixes #7886.

LGTM=iant, r, rsc
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/149010043
2014-09-25 12:49:42 -07:00
Rob Pike
651bb8e026 spec: add dropped comma
The proposed text in the last CL had a comma that was missing from the submitted spec.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/150720043
2014-09-19 14:13:51 -07:00
Robert Griesemer
b4eb22d764 spec: clarify panic behavior when deferring nil functions
Fixes #8107.

LGTM=iant, rsc, r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/145960043
2014-09-19 13:32:07 -07:00
Robin Eklind
f82097f5cf spec: Add link to rune literals from string literals when talking about escape sequences.
LGTM=gri
R=golang-codereviews, gobot, gri
CC=golang-codereviews
https://golang.org/cl/140750043
2014-09-03 10:44:33 -07:00
Robin Eklind
cac006ae5a spec: Fix indentation and remove trailing white space characters.
LGTM=gri
R=golang-codereviews, bradfitz, gri
CC=golang-codereviews
https://golang.org/cl/133330043
2014-08-30 10:27:01 -07:00
Robert Griesemer
f852034eb0 spec: move Method expr/value section near selectors
Preparation for fixing issue 5769 (method selectors
do not auto-dereference): The actual fix may require
some cleanups in all these sections, and syntactically,
method expressions and method values are selector
expressions. Moving them next to each other so that
it's easy to see the actual changes (next CL).

No content changes besides the section moves.

LGTM=iant, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/132300043
2014-08-28 08:53:25 -07:00
Robert Griesemer
c0fca138d1 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 #8189.

LGTM=iant, r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/112320045
2014-08-05 11:31:32 -07:00
Andrew Gerrand
43ad89d627 doc: drop scheme from links that are known to support HTTPS
golang.org now serves HTTPS with a valid cert, so it's reasonable
that users should click through to the HTTPS versions of *.golang.org
and other known sites.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/112650043
2014-07-25 10:28:39 +10:00
Robert Griesemer
20ae6d9bc5 spec: permit "for range x" (no index variables)
This is a fully backward-compatible language change.

There are not a lot of cases in the std library, but
there are some. Arguably this makes the syntax a bit
more regular - any trailing index variable that is _
can be left away, and there's some analogy to type
switches where the temporary can be left away.

Implementation-wise the change should be trivial as
it can be done completely syntactically. For instance,
the respective change in go/parser is a dozen lines
(see https://golang.org/cl/112970044 ).

Fixes #6102.

LGTM=iant, r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/104680043
2014-07-14 15:08:09 -07:00
Robert Griesemer
187ee2cf2b spec: receiver declaration is just a parameter declaration
This CL removes the special syntax for method receivers and
makes it just like other parameters. Instead, the crucial
receiver-specific rules (exactly one receiver, receiver type
must be of the form T or *T) are specified verbally instead
of syntactically.

This is a fully backward-compatible (and minor) syntax
relaxation. As a result, the following syntactic restrictions
(which are completely irrelevant) and which were only in place
for receivers are removed:

a) receiver types cannot be parenthesized
b) receiver parameter lists cannot have a trailing comma

The result of this CL is a simplication of the spec and the
implementation, with no impact on existing (or future) code.

Noteworthy:

- gc already permits a trailing comma at the end of a receiver
  declaration:

  func (recv T,) m() {}

  This is technically a bug with the current spec; this CL will
  legalize this notation.

- gccgo produces a misleading error when a trailing comma is used:

  error: method has multiple receivers

  (even though there's only one receiver)

- Compilers and type-checkers won't need to report errors anymore
  if receiver types are parenthesized.

Fixes #4496.

LGTM=iant, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/101500044
2014-06-24 16:25:09 -07:00
Robert Griesemer
94849d5a78 spec: clarify that break/continue do not work across function boundaries
Also made it extra clear for goto statements (even though label scopes
are already limited to the function defining a label).

Fixes #8040.

LGTM=r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/99550043
2014-05-28 08:43:47 -07:00
Robert Griesemer
2c83f1eaf9 spec: explicitly disallow blank methods in interface types
The spec was unclear about whether blank methods should be
permitted in interface types. gccgo permits at most one, gc
crashes if there are more than one, go/types permits at most
one.

Discussion:

Since method sets of non-interface types never contain methods
with blank names (blank methods are never declared), it is impossible
to satisfy an interface with a blank method.

It is possible to declare variables of assignable interface types
(but not necessarily identical types) containing blank methods, and
assign those variables to each other, but the values of those
variables can only be nil.

There appear to be two "reasonable" alternatives:

1) Permit at most one blank method (since method names must be unique),
and consider it part of the interface. This is what appears to happen
now, with corner-case bugs. Such interfaces can never be implemented.

2) Permit arbitrary many blank methods but ignore them. This appears
to be closer to the handling of blank identifiers in declarations.
However, an interface type literal is not a declaration (it's a type
literal). Also, for struct types, blank identifiers are not ignored;
so the analogy with declarations is flawed.

Both these alternatives don't seem to add any benefit and are likely
(if only slightly) more complicated to explain and implement than
disallowing blank methods in interfaces altogether.

Fixes #6604.

LGTM=r, rsc, iant
R=r, rsc, ken, iant
CC=golang-codereviews
https://golang.org/cl/99410046
2014-05-22 12:23:25 -07:00
Robert Griesemer
c00043b5d8 spec: specify order of init() calls
The spec did not specify the order in which
init() functions are called. Specify that
they are called in source order since we have
now also specified the initialization order
of independent variables.

While technically a language change, no
existing code could have relied on this,
so this should not break anything.

Per suggestion from rsc.

LGTM=r, iant
R=rsc, iant, r, ken
CC=golang-codereviews
https://golang.org/cl/98420046
2014-05-20 17:46:08 -07:00
Robert Griesemer
a43669843b spec: clarify section on package initialization
- split description of package initialization and
  program execution
- better grouping of concerns in section on package
  initialization
- more explicit definition of what constitues a
  dependency
- removed language about constant dependencies -
  they are computed at compile-time and not
  initialized at run-time
- clarified that independent variables are initialized
  in declaration order (rather than reference order)

Note that the last clarification is what distinguishes
gc and gccgo at the moment: gc uses reference order
(i.e., order in which variables are referenced in
initialization expressions), while gccgo uses declaration
order for independent variables.

Not a language change. But adopting this CL will
clarify what constitutes a dependency.

Fixes #6703.

LGTM=adonovan, r, iant, rsc
R=r, rsc, iant, ken, adonovan
CC=golang-codereviews
https://golang.org/cl/99020043
2014-05-20 13:51:39 -07:00
Rob Pike
4d36ad7791 doc/go_spec.html: fix broken anchor tag
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/99420045
2014-05-20 11:57:58 -07:00
Robert Griesemer
7f1d62dcef spec: clarify when a program exits
Fixes #8023.

LGTM=rsc
R=r, iant, ken, rsc
CC=golang-codereviews
https://golang.org/cl/98340043
2014-05-19 08:54:19 -07:00
Ian Lance Taylor
2a627da326 spec: clarify that newlines are kept in raw string literals
Fixes #8007.

LGTM=r
R=gri, r
CC=golang-codereviews
https://golang.org/cl/91510044
2014-05-16 12:20:03 -07:00
Robert Griesemer
61d8a33719 spec: more precise description of select statement
- use previously defined terms (with links) throughout
- specify evaluation order more precisely (in particular,
  the evaluation time of rhs expressions in receive cases
  was not specified)
- added extra example case

Not a language change.

Description matches observed behavior of code compiled
with gc and gccgo.

Fixes #7669.

LGTM=iant, r, rsc
R=r, rsc, iant, ken, josharian
CC=golang-codereviews
https://golang.org/cl/91230043
2014-05-14 11:47:19 -07:00
Robert Griesemer
97aa90d251 spec: several clarifications to language on channels
- A channel may be used between any number of goroutines,
  not just two.
- Replace "passing a value" (which is not further defined)
  by "sending and receiving a value".
- Made syntax production more symmetric.
- Talk about unbuffered channels before buffered channels.
- Clarify what the comma,ok receive values mean (issue 7785).

Not a language change.

Fixes #7785.

LGTM=rsc, r, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/94030045
2014-05-07 10:40:39 -07:00
Robert Griesemer
dbe5f88804 spec: remove evaluation order inconsistency
This is a clarification of what happens already.
Not a language change.

Fixes #7137.

LGTM=iant, r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/96000044
2014-05-07 08:50:52 -07:00
Robert Griesemer
6f3b84a757 spec: clarify type properties
If the underlying type of a type T is a boolean, numeric,
or string type, then T is also a boolean, numeric, or
string type, respectively.

Not a language change.

Fixes #7551.

LGTM=iant, rsc, robert.hencke, r
R=r, rsc, iant, ken, robert.hencke
CC=golang-codereviews
https://golang.org/cl/100130044
2014-05-07 08:42:08 -07:00
Dmitriy Vyukov
2e1ddeb136 doc: replace absolute links to golang.org with relative links
Currently tip.golang.org leads to golang.org and
local godoc also leads to golang.org (when you don't have internet connectivity).

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/100200043
2014-05-07 18:49:13 +04:00
Robert Griesemer
6ffd235161 spec: clarify when constant slice indices must be in range
This documents the status quo for most implementations,
with one exception: gc generates a run-time error for
constant but out-of-range indices when slicing a constant
string. See issue 7200 for a detailed discussion.

LGTM=r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/72160044
2014-03-06 17:11:13 -08:00
Robert Griesemer
a766277742 spec: clarify value passed for final parameter of variadic functions
NOT A LANGUAGE CHANGE.

Fixes #7073.

LGTM=r
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/68840045
2014-03-06 10:35:05 -08:00
Robert Griesemer
8d77d2c8f0 spec: be more precise about underlying types of predeclared types
The underlying type of the predeclared type error is not itself,
but the interface it is defined as.

Fixes #7444.

LGTM=r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/71790044
2014-03-05 19:37:44 -08:00
Robert Griesemer
c97778f430 spec: shadowed return parameters may be disallowed
This documents the implemented behavior of both
gc and gccgo as an implementation restriction.

NOT A LANGUAGE CHANGE.

Fixes #5425.

LGTM=rsc, r, iant
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/71430043
2014-03-05 11:59:53 -08:00
Robert Griesemer
871698136d spec: clarify what is considered a function call for len/cap special case
gccgo considers built-in function calls returning a constant not as function call (issue 7386)
go/types considers any call (regular or built-in) as a function call

The wording and examples clarify that only "function calls" that are issued
at run-time (and thus do not result in a constant result) are considered
function calls in this case.

gc is inconsistent (issue 7385)
gccgo already interprets the spec accordingly and issue 7386 is moot.
go/types considers all calls (constant or not) as function calls (issue 7457).

Fixes #7387.
Fixes #7386.

LGTM=r, rsc, iant
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/66860046
2014-03-03 20:07:34 -08:00
Robert Griesemer
a36b5b99cc spec: slightly rephrased wording on parsing ambiguity for composite literals
Fixes #4482.

LGTM=r
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/69020045
2014-02-27 08:57:30 -08:00
Rob Pike
e6863e7d5b spec: libraries and implementation are now at Unicode 6.3
LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/68760043
2014-02-25 14:15:49 -08:00
Robert Griesemer
ab26623182 spec: clarify default "true" condition/tag in for/switch statements
An absent condition/tag in for and switch statements is equivalent
to the predeclared constant true; not simply the expression true
(which might lead to a locally defined true).

Not a language change.

Fixes #7404.

LGTM=iant, r
R=r, iant, rsc, ken
CC=golang-codereviews
https://golang.org/cl/68150046
2014-02-25 09:13:37 -08:00
Rob Pike
227fe5f64e spec: tighten the wording around . imports
Make it clear that if you do a . import, you cannot use a qualified identifier.

R=gri
CC=golang-codereviews
https://golang.org/cl/52390043
2014-01-14 15:16:01 -08:00
Rob Pike
82e2db70f6 spec: s/and/or/ for correctness and parallelism
No change to the meaning, just bad writing found by
Doug McIlroy.
Let's start the new year off with a bang.

R=golang-codereviews, bradfitz, dave
CC=golang-codereviews
https://golang.org/cl/47110044
2014-01-04 10:52:59 -08:00
Emil Hessman
13141315ad spec: Fix broken type identity link
Fixes #7003.

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/47780043
2014-01-03 22:48:03 -08:00
Mihai Borobocea
8183ed19b9 spec: example shows wrong value for complex constant
Looks like a typo.
Fixes #7011.

R=golang-codereviews, r, bradfitz
CC=golang-codereviews
https://golang.org/cl/45350043
2013-12-30 13:29:56 -08:00
Robert Griesemer
f57bf7a556 spec: clarify rules for blank identifiers
This documents the status quo more precisely.
Not a language change.

Fixes #6006.

R=r, rsc, iant, ken
CC=golang-dev
https://golang.org/cl/14415043
2013-11-12 21:06:54 -05:00
Robert Griesemer
15da997c7e spec: clarify re-use of underlying arrays in slice operations
Please note the slight rewording for append: The spec now
requires that append reuses the underlying array if it is
sufficiently large. Per majority sentiment.

This is technically a language change but the current
implementation always worked this way.

Fixes #5818.
Fixes #5180.

R=rsc, iant, r, ken, minux.ma, dan.kortschak, rogpeppe, go.peter.90
CC=golang-dev
https://golang.org/cl/14419054
2013-10-16 16:16:54 -07:00
Robert Griesemer
e121de2f01 spec: unsafe.Pointers are pointers
But they cannot be dereferenced.
See also issue 6116.

Fixes #6358.

R=r, rsc, iant, ken
CC=golang-dev
https://golang.org/cl/14374046
2013-10-07 10:43:28 -07:00
Andrew Gerrand
48ba6fe553 doc: move spec and memory model back to /ref/
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14364043
2013-10-04 09:45:06 +10:00
Robert Griesemer
4cc71e3363 spec: added additional links, added missing 'label'
No semantic spec changes.

R=r
CC=golang-dev
https://golang.org/cl/14363043
2013-10-03 16:38:22 -07:00
Robert Hencke
58d18e25af spec: fix small typo in comment for example
R=golang-dev, mirtchovski, r
CC=golang-dev
https://golang.org/cl/14227043
2013-10-03 12:46:02 -07:00
Rob Pike
cec0954dd0 spec: add example for continue to label
Make the break example slightly more interesting
Update #5725
Effective Go will be updated in a separate CL.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13368054
2013-09-17 07:41:11 +10:00