Commit graph

609 commits

Author SHA1 Message Date
Josh Bleecher Snyder 1c268431f4 spec: allow conversion from slice to array ptr
Implementation follows in subsequent changes.

Updates #395

Change-Id: Ic97ee822805e4c236fdd9d224e776cb2ae62c817
Reviewed-on: https://go-review.googlesource.com/c/go/+/216424
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-04-20 23:47:34 +00:00
Robert Griesemer 63b0a0a5b8 spec: fix rendering of >=
Follow-up on https://golang.org/cl/297249.

Change-Id: Ib4df91df530e4e7d7dd8c54d89c834cee55031f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/302370
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-17 00:18:28 +00:00
nobishino 13a0f7b502 spec: clarify that signed integers>=0 are permitted as shift counts
In Go1.13 and above, signed integers are permitted as shift counts as long as they are >=0.
However, the comments in the "Arithmetic operators" section says shift operators accept "unsigned integer" as of right operands. Replacing this with "integer>=0" resolves the misunderstanding that shift
operators permit only unsigned integers.

Reference: Go1.13 Release Notes: https://golang.org/doc/go1.13

Change-Id: Icd3c7734d539ab702590e992a618c9251c653c37
GitHub-Last-Rev: 4f263a48d3
GitHub-Pull-Request: golang/go#44664
Reviewed-on: https://go-review.googlesource.com/c/go/+/297249
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Robert Griesemer <gri@golang.org>
2021-03-16 19:51:31 +00:00
DQNEO 084b07d6f6 spec: improve sentence structure for passing a slice
Change-Id: I453d06da2f596eb0b99905aec46a05547d73c62c
Reviewed-on: https://go-review.googlesource.com/c/go/+/290872
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Robert Griesemer <gri@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2021-02-24 05:23:32 +00:00
Robert Griesemer 078f08f0ee spec: every type has a method set (minor clarification)
The spec states that a type "may" have a method set associated with it.
Yet every type has a method set, which may be empty. This is clarified
later in the same paragraph. Be clear in the first sentence as well.

Per the suggestion from https://github.com/DQNEO.

Fixes #44318.

Change-Id: I6097b1c7062853e404b7fead56d18a7f9c576fc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/292853
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-20 00:01:22 +00:00
DQNEO 26ceae85a8 spec: More precise wording in section on function calls.
A caller is not always in a function.

For example, a call can appear in top level declarations.

e.g. var x = f()

Change-Id: I29c4c3b7663249434fb2b8a6d0003267c77268cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/290849
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-02-11 17:55:50 +00:00
task4233 fca94ab3ab spec: improve the example in Type assertions section
The example, var v, ok T1 = x.(T), can be interpreted as type T1 interface{} or type T = bool; type T1 = T.
Separating the example would help understanding for readers.

Change-Id: I179f4564e67f4d503815d29307df2cebb50c82f9
GitHub-Last-Rev: b34fffb6bb
GitHub-Pull-Request: golang/go#44040
Reviewed-on: https://go-review.googlesource.com/c/go/+/288472
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-02-02 16:35:53 +00:00
Robert Griesemer 2b9b2720b8 spec: split shift examples into groups for 32- and 64-bit ints
In the current (pre-CL) version of the spec, the 2nd last shift
example appears to be using the array declared in the last example.
On a 32-bit platform, that array would have length 0, which would
lead to a panic in the 2nd last example. Also, if this code were
inside a function, it wouldn't compile (array declared after use).

Use an explicitly declared array for that specific shift example.
Also, split out all cases that produce different results for 32-
vs 64-bit ints.

Fixes #41835.

Change-Id: Ie45114224509e4999197226f91f7f6f934449abb
Reviewed-on: https://go-review.googlesource.com/c/go/+/260398
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30 16:20:05 +00:00
Robert Griesemer 23cc16cdd2 spec: better variable name for operator example
Suggested by @yaxinlx.

Fixes #41612.

Change-Id: I98b9968a95d090ee3c67ff02678e1874e6d98c33
Reviewed-on: https://go-review.googlesource.com/c/go/+/257159
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-09-24 20:41:14 +00:00
yah01 ee55dd6b64 spec: add missing space in EBNF
Fixes #36520

Change-Id: I698ab235f82f7c81caa09318c954847cf3833153
GitHub-Last-Rev: 368a1dc788
GitHub-Pull-Request: golang/go#36559
Reviewed-on: https://go-review.googlesource.com/c/go/+/214821
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-01-15 05:32:51 +00:00
Rob Pike cae9a9fd65 doc: fix up some HTML issues in go_spec.html
The HTML linter 'tidy' reports:

	go_spec.html:2556: Warning: unescaped & which should be written as &amp;
	go_spec.html:3293: Warning: unescaped & or unknown entity "&s1"
	go_spec.html:3293: Warning: unescaped & or unknown entity "&a"
	go_spec.html:3294: Warning: unescaped & or unknown entity "&s2"
	go_spec.html:3294: Warning: unescaped & or unknown entity "&a"
	go_spec.html:2045: Warning: trimming empty <p>
	go_spec.html:4526: Warning: trimming empty <ul>
	go_spec.html:4533: Warning: trimming empty <ul>
	go_spec.html:4539: Warning: trimming empty <ul>

This CL fixes all but the <ul> ones, which I think should be fixed
but are defended by a comment.

Change-Id: I0ca88f5e80755024801877ab1298025ecf8f10c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/214457
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2020-01-14 22:24:11 +00:00
Robert Griesemer 9ead772a92 spec: uniformly format empty interfaces as "interface{}"
Fixes #36526.

Change-Id: Ic51a287579f139422cc1a7b2fb82d6732114b031
Reviewed-on: https://go-review.googlesource.com/c/go/+/214597
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-01-13 21:49:46 +00:00
Alberto Donizetti 7d30af8e17 spec: reword claim about the grammar being regular
Since the word "regular" has a precise meaning in the context of
formal languages, the Introduction sentence claiming that Go's grammar
is "compact and regular" may mislead readers.

Reword it using Rob's suggestion.

Fixes #36037

Change-Id: I00c1a5714bdab8878d9a77b36d67dae67d63da0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/211277
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2019-12-13 20:41:04 +00:00
Robert Griesemer 6fcc2d85be spec: clarify that shift count must be non-negative
Fixes #34056.

Change-Id: I2c9b7a20d19f458df5dcc376e29bee6be1f09f7a
Reviewed-on: https://go-review.googlesource.com/c/go/+/193277
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-04 16:01:24 +00:00
Robert Griesemer bc405df391 spec: allow embedding overlapping interfaces
Updates #6977.

Change-Id: I6eda4be550e7c7ea1e1bac3222850002d90a81a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/190378
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-08-26 16:39:30 +00:00
Robert Griesemer 39d4178735 spec: add an example of a trivially invalid interface
In preparation for the forthcoming spec changes for #6977.
While at it, modernize existing File example that dates
back all the way to commit 18c5b488a3.

Change-Id: Id10e4df0513e3de15bd58867222923eefa9473ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/187978
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-07-31 05:45:43 +00:00
Robert Griesemer 1e3ffb0c90 spec: clarify that slice a expression shares underlying array with operand
The spec was not very precise as to what happens with respect to sharing
if a sliced operand is (a pointer to) an array. Added a small clarification
and a supporting example.

Fixes #31689.

Change-Id: Ic49351bec2033abd3f5428154ec3e9a7c2c9eaa5
Reviewed-on: https://go-review.googlesource.com/c/go/+/177139
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2019-05-14 22:30:48 +00:00
Robert Griesemer eebb9db0ef spec: clarify the difference between &T{} and new(T)
Add a small paragraph and example pointing out
the difference for the case where T is a slice
or map. This is a common error for Go novices.

Fixes #29425.

Change-Id: Icdb59f25361e9f6a09b190fbfcc9ae0c7d90077b
Reviewed-on: https://go-review.googlesource.com/c/go/+/176338
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-05-13 21:24:51 +00:00
Robert Griesemer 451cf3e2cd spec: clarify language on package-level variable initialization
The very first paragraph on "Package initialization" stated that
"variables are initialized in declaration order, but after any
variables they might depend on". This phrasing was easily
misread as "declaration order is the first sorting criteria"
and then contradicted what the subsequent paragraphs spelled
out in precise detail.

Instead, variable initialization proceeds by repeatedly determining
a set of ready to initialize variables, and then selecting from that
set the variable declared earliest. That is, declaration order is the
second sorting criteria.

Also, for the purpose of variable initialization, declarations
introducing blank (_) variables are considered like any other
variables (their initialization expressions may have side-effects
and affect initialization order), even though blank identifiers
are not "declared".

This CL adds clarifying language regarding these two issues
and the supporting example.

Both gccgo and go/types implement this behavior. cmd/compile
has a long-standing issue (#22326).

The spec also did not state in which order multiple variables
initialized by a single (multi-value) initialization expression are
handled. This CL adds a clarifying paragraph: If any such variable
is initialized, all that declaration's variables are initialized at
the same time.

This behavior matches user expectation: We are not expecting to
observe partially initialized sets of variables in declarations
such as "var a, b, c = f()".

It also matches existing cmd/compile and go/types (but not gccgo)
behavior.

Finally, cmd/compile, gccgo, and go/types produce different
initialization orders in (esoteric) cases where hidden (not
detected with existing rules) dependencies exist. Added a
sentence and example clarifying how much leeway compilers have
in those situations. The goal is to preserve the ability to
use static initialization while at the same time maintain
the relative initialization order of variables with detected
dependencies.

Fixes   #31292.
Updates #22326.

Change-Id: I0a369abff8cfce27afc975998db875f5c580caa2
Reviewed-on: https://go-review.googlesource.com/c/go/+/175980
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-05-13 20:57:02 +00:00
Robert Griesemer 1024b25d0c spec: clarify wording on passing slice arguments to variadic functions
Per discussion on #30769.

Fixes #30769.

Change-Id: I620dbac936de1a0b5deec03926dd11d690a918e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/167380
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Rob Pike <r@golang.org>
2019-03-14 00:32:43 +00:00
Robert Griesemer a083648165 spec: document new Go2 number literals
This CL documents the new binary and octal integer literals,
hexadecimal floats, generalized imaginary literals and digit
separators for all number literals in the spec.

Added empty lines between abutting paragraphs in some places
(a more thorough cleanup can be done in a separate CL).

A minor detail: A single 0 was considered an octal zero per the
syntax (decimal integer literals always started with a non-zero
digit). The new octal literal syntax allows 0o and 0O prefixes
and when keeping the respective octal_lit syntax symmetric with
all the others (binary_lit, hex_lit), a single 0 is not automatically
part of it anymore. Rather than complicating the new octal_lit syntax
to include 0 as before, it is simpler (and more natural) to accept
a single 0 as part of a decimal_lit. This is purely a notational
change.

R=Go1.13

Updates #12711.
Updates #19308.
Updates #28493.
Updates #29008.

Change-Id: Ib9fdc6e781f6031cceeed37aaed9d05c7141adec
Reviewed-on: https://go-review.googlesource.com/c/go/+/161098
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-12 16:13:39 +00:00
Robert Griesemer a10b4cff91 spec: document signed integer shift counts
Updates #19113.

Change-Id: I4726f51c5061c33979cdd061f6d4616fa97edb9a
Reviewed-on: https://go-review.googlesource.com/c/161201
Reviewed-by: Rob Pike <r@golang.org>
2019-02-17 04:46:20 +00:00
Russ Cox b7ba523355 doc/go_spec: tweak wording to avoid 'explicit assignment' misreading
This text changed in CL 139099 to add "explicit" in front of "conversion".
But now "explicit conversion or assignment" reads like it might mean
"explicit [conversion or assignment]" when what is meant is
"[explicit conversion] or assignment". To make clear that explicit does
not apply to assignment, use "assignment or explicit conversion".

Change-Id: I8ff7a5b3ecd9f562793502fa6808242f22264f28
Reviewed-on: https://go-review.googlesource.com/c/149340
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-11-16 17:50:06 +00:00
Robert Griesemer de578dcdd6 spec: be clearer about definition of string length
Adjusted spec to explicitly define the string length as the
number of bytes of the string; the prose now matches the prose
for arrays. Made analogous change for slices.

Fixes #28736.

Change-Id: I47cab321c87de0a4c482f5466b819b2cc8993fd1
Reviewed-on: https://go-review.googlesource.com/c/149077
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-11-13 00:42:32 +00:00
Robert Griesemer 1e38ecdbbe spec: refer to "run-time panic" rather than "exception" (cleanup)
Fixes #28341.

Change-Id: If8ae844c9b5e843ce9229c0a555f7006426baed7
Reviewed-on: https://go-review.googlesource.com/c/144260
Reviewed-by: Rob Pike <r@golang.org>
2018-10-23 23:03:59 +00:00
Robert Griesemer bb3e211777 spec: clarify rules for receiver base types
The spec currently provides a syntactic rule for receiver base types,
and a strict reading of those rules prohibits the use of type aliases
referring to pointer types as receiver types.

This strict interpretation breaks an assumed rule for aliases, which
is that a type literal can always be replaced by an alias denoting
that literal.

Furthermore, cmd/compile always accepted this new formulation of the
receiver type rules and so this change will simply validate what has
been implemented all along.

Fixes #27995.

Change-Id: I032289c926a4f070d6f7795431d86635fe64d907
Reviewed-on: https://go-review.googlesource.com/c/142757
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-10-17 20:03:35 +00:00
Robert Griesemer 26d22609c3 spec: distinguish between explicit and implicit conversions (clarification)
The spec used the term "conversion" somewhat indiscriminately for
explicit conversions that appear literally in the source, and implicit
conversions that are implied by the context of an expression.
Be clearer about it by defining the terms.

Also, state that integer to string conversions of the form string(x)
are never implicit. This clarifies situations where implicit conversions
might require an integer to change to a string (but don't and never have
done so). See line 3948.

Fixes #26313.

Change-Id: I8939466df6b5950933ae7c987662ef9f88827fda
Reviewed-on: https://go-review.googlesource.com/c/139099
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-08 17:47:49 +00:00
Robert Griesemer 206fd7886b spec: be more precise about the moment deferred functions are executed
Fixes #27802.

Change-Id: I7ea9f7279300a55b0cb851893edc591a6f84e324
Reviewed-on: https://go-review.googlesource.com/136758
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-24 21:15:27 +00:00
Dina Garmash 8a2b5f1f39 doc: fix os.Pipe() call in the example.
Short variable declarations example passes an fd argument to os.Pipe call.
However, os.Pipe() takes no arguments and returns 2 Files and an error:
https://golang.org/src/os/pipe_linux.go?s=319:360#L1

Fixes: #27384

Change-Id: I0a709f51e0878c57185d901b899d209f001dfcce
Reviewed-on: https://go-review.googlesource.com/132284
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-08-31 06:39:16 +00:00
Suriyaa Sundararuban 1041ac8781 doc: use HTTPS for links
Change-Id: I9d2d25df067ca573589db5ff18296a5ec33866be
Reviewed-on: https://go-review.googlesource.com/118595
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-13 13:45:01 +00:00
Bryan C. Mills df48003618 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/106855
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-05-09 20:36:22 +00:00
Andrew Bonventre 7974f0815e Revert "doc: remove non-prime from list of primes in spec"
This reverts commit 4b06d9d727.

Reason for revert: It's a reference to a legendary article
from the Journal of Irreproducible Results.

Updates golang/go#24451

Change-Id: I0288177f4e286bd6ace5774f2e5e0acb02370305
Reviewed-on: https://go-review.googlesource.com/101495
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2018-03-19 21:51:23 +00:00
Andrew Bonventre 4b06d9d727 doc: remove non-prime from list of primes in spec
Fixes golang/go#24451

Change-Id: Id9b4cbd1a1ff032f1cc4606e9734ddcc64892ae5
Reviewed-on: https://go-review.googlesource.com/101457
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2018-03-19 18:26:12 +00:00
Yazen2017 a4e950ec9e doc: improve clarity of map index examples
The fourth example for map indexing states you have a map of type [K]V
and attempts to read in a variable of type T.  Further, the example
is meant to showcase the boolean return variable saying whether the
map contained a key, but overrides to type T.  This will not compile.

Changed last updated date to February 18

Fixes: #23895

Change-Id: I63c52adbcd989afd4855e329e6c727f4c01f7881
Reviewed-on: https://go-review.googlesource.com/94906
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-02-19 05:48:39 +00:00
Robert Griesemer 851e98f0ee spec: remove need for separate Function production (cleanup)
The EBNF production

	Function = Signature FunctionBody .

was used in FunctionDecl, MethodDecl, and FunctionLit, but only
for the latter it shortened the syntax slightly.

This change "inlines" Function which simplifies FunctionDecl and
MethodDecl and gets rid of the Function production.

This has no impact on the specified language. Also, the Function
production is never referred to by the prose, so it's safe to
remove it from the spec.

Finally, neither go/ast nor go/parser have a representation of
this production via a corresponding node or parse function, so
no possibly valuable documentation is lost, either.

Change-Id: Ia2875d31c6ec2d2079081ef481e50bad4f43c694
Reviewed-on: https://go-review.googlesource.com/91515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-02-02 00:22:16 +00:00
Robert Griesemer 9b49ac0366 spec: consistently use "defined type" and "type name" (cleanup)
When we introduced the notion of alias type declarations, we renamed
"named type" to "defined type" to avoid confusion with types denoted
by aliases and thus are also types with names, or "named types".

Some of the old uses of "named types" remained; this change removes
them.

Now the spec consistently uses the terms:

- "defined type"  for a type declared via a type definition
- "type name"     for any name denoting an (alias or defined) type
- "alias"         for a type name declared in an alias declaration

New prose is encouraged to avoid the term "named type" to counter-
act further confusion.

Fixes #23474.

Change-Id: I5fb59f1208baf958da79cf51ed3eb1411cd18e03
Reviewed-on: https://go-review.googlesource.com/89115
Reviewed-by: Rob Pike <r@golang.org>
2018-01-23 17:39:18 +00:00
Robert Griesemer 18d527b3f0 spec: mention that special case for integer division is due to overflow
Fixes #23443.

Change-Id: If60c39b582ee5308e9fa902f93c1b6ae7890346c
Reviewed-on: https://go-review.googlesource.com/87975
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-01-17 18:59:44 +00:00
Robert Griesemer c13e0e8cee spec: remove example explaining that type B0 and B0 are identical
Every few months we get a new error report claiming that there
is a typo in the spec related to this specific example. Clearly,
the fact that two types with the same identifier are identical
seems exceedingly obvious to readers; thus the example seems not
worth the trouble. Removing it.

For #9226.
For #22202.
For #22495.
For #23096.
For #23409.

There may be more.

Change-Id: I003ba79dc460ffb028a4ecb5f29efd60f2551912
Reviewed-on: https://go-review.googlesource.com/87417
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-01-11 21:04:11 +00:00
Robert Griesemer 8c916a2f6d spec: use consistent quoting style in prose
Fixes #23389.

Change-Id: Id6e86eebe44809db12a0e14014c474bf4fbf5108
Reviewed-on: https://go-review.googlesource.com/87035
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-01-09 23:31:06 +00:00
Robert Griesemer 4de1d1d5cd spec: consistently use "element" rather than "value" for map entry values
The spec refers to a map's key and element types; thus the respective
values are "keys" and "elements". Also, a map value is the value of
the entire map.

Similar fix for channels, where appropriate.

Fixes #23254.

Change-Id: I6f03ea6d86586c7b0b3e84f0c2e9446b8109fa53
Reviewed-on: https://go-review.googlesource.com/85999
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2018-01-04 20:17:19 +00:00
Robert Griesemer f3f507b2d8 spec: provide some (minimal) intuition for the notion of "terminating statement"
Fixes #23215.

Change-Id: Ib20825bf08915b4daaabbfd91f168e24973c512d
Reviewed-on: https://go-review.googlesource.com/85215
Reviewed-by: Rob Pike <r@golang.org>
2017-12-22 21:13:38 +00:00
griesemer f2d52519e1 spec: match syntax for method expressions with implementations
A method expression is of the form T.m where T is a type and m
is a method of that type. The spec restricted T essentially to
a type name. Both cmd/compile and go/types accepted any type
syntactically, and a method expression was really just a form
of a selector expression x.f where x denotes a type.

This CL removes the spec syntax restriction from MethodExpr
to match the actual implementation. It also moves MethodExpr
from Operand to PrimaryExpr, because that's what it is.

It still keeps the separate notion of MethodExpr even though
it looks just like a selector expresion, since a MethodExpr
must start with a type rather than a value, and the spec's
syntax expresses this bit of semantics via distinct productions
(e.g., conversions look like calls but also must start with
a type).

Fixes #9060.

Change-Id: Idd84655b5b4f85d7ee53ebf749f73f0414a05f4a
Reviewed-on: https://go-review.googlesource.com/73233
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-25 22:49:03 +00:00
griesemer 0c5b00d0cd spec: remove sentence discussing existing implementations
Fixes #22282.

Change-Id: I4097e9cbd590ab6c8b1511a3b752c6ac98ac819b
Reviewed-on: https://go-review.googlesource.com/72792
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-10-23 21:39:03 +00:00
griesemer 85177f4276 spec: remove vestiges referring to iotas being incremented
https://golang.org/cl/71750 specifies iota values as indices,
thus making them independent from nested constant declarations.
This CL removes some of the comments in the examples that were
still referring to the old notion of iotas being incremented
and reset.

As an aside, please note that the spec still permits the use
of iota in a nested function (like before). Specifically, the
following cases are permitted by the spec (as before):

1) const _ = len([iota]int{})
2) const _ = unsafe.Sizeof(func(){ _ = iota })

For #15550.

Change-Id: I9e5fec75daf7b628b1e08d970512397e9c348923
Reviewed-on: https://go-review.googlesource.com/71912
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-10-19 22:22:55 +00:00
griesemer 52dd39965e spec: clarify that each block has its own version of iota
Issue #15550 is clearly an esoteric case but the spec was silent
about it and we had diverging implementations. By making `iota`
and index that is relative to the respective constant declaration,
nested const declarations won't affect outer values of `iota`.

cmd/compile and go/types already follow this semantics.

Fixes #15550.

Change-Id: If138189e3ea4373f8ba50ac6fb1d219b481f8698
Reviewed-on: https://go-review.googlesource.com/71750
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-19 15:30:37 +00:00
griesemer ada6557593 spec: simplify paragraph on certain range expressions over arrays
Fixes #22258.

Change-Id: I43e68f1cf3163e1a041ebff2734ff2cb7943f695
Reviewed-on: https://go-review.googlesource.com/71431
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-19 00:29:56 +00:00
griesemer ddc64def0f spec: explicitly state the import path for package unsafe
Nowhere in the spec did we mention the import path for package
unsafe. Now we do.

Fixes #22308.

Change-Id: Ifd42c873188e898c597cdee4284e7a9d234a9282
Reviewed-on: https://go-review.googlesource.com/71373
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-10-17 23:30:58 +00:00
griesemer 4a2391e7c9 spec: state which predeclared types are defined or alias types (clarification)
When we introduced the distinction between "defined" and "alias" types
we retained the notion of a "named" type (any type with a name). The
predeclared types (which all have names) simply remained named types.

This CL clarifies the spec by stating excplicitly which predeclared
types are defined types (or at least "act" like defined types), and
which ones are alias types.

Fixes #21785.

Change-Id: Ia8ae133509eb5d738e6757b3442c9992355e3535
Reviewed-on: https://go-review.googlesource.com/64591
Reviewed-by: Russ Cox <rsc@golang.org>
2017-09-19 14:33:25 +00:00
griesemer 9690d245d5 spec: clarify context type for certain non-constant shifts
The spec is not conclusive about whether a non-constant shift of
certain untyped constant left operands is valid when the shift
expression appears as an index in an index or slice expression,
or as a size in a `make` function call.

Despite identical spec rules in all these cases, cmd/compile accepts

	make([]byte, 1.0 << s)

but pronounces an error for

	a[1.0 << s]

(go/types accepts both).

This change clarifies the spec by explicitly stating that an
untyped constant left operand in a non-constant shift (1.0 in
the above examples) will be given type `int` in these contexts.

A separate issue #21693 addresses the cmd/compile bug.

Fixes #14844.

Change-Id: I4b52125e487a607fae377fcbed55463cdce9836c
Reviewed-on: https://go-review.googlesource.com/60230
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-01 15:46:24 +00:00
griesemer 2ac43d5be2 doc: minor clarification regarding the sharing of underlying arrays
The last sentence in the section on slice expressions could be read
as if it might apply to strings. Changed the sentence a bit to
emphasize its applicability to slices only. See also the issue for
more background.

Fixes #19220.

Change-Id: I8551f34230e4ed93f951e7b871cc81f54a5874a9
Reviewed-on: https://go-review.googlesource.com/59890
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-30 15:24:12 +00:00