Skip to content

Commit 120cf67

Browse files
committed
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 <[email protected]>
1 parent a34fddf commit 120cf67

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

doc/go_spec.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of November 4, 2016",
3+
"Subtitle": "Version of November 18, 2016",
44
"Path": "/ref/spec"
55
}-->
66

@@ -2006,7 +2006,7 @@ <h3 id="Short_variable_declarations">Short variable declarations</h3>
20062006
<p>
20072007
Unlike regular variable declarations, a short variable declaration may <i>redeclare</i>
20082008
variables provided they were originally declared earlier in the same block
2009-
(or the parameter lists if the block is the function body) with the same type,
2009+
(or the parameter lists if the block is the function body) with the same type,
20102010
and at least one of the non-<a href="#Blank_identifier">blank</a> variables is new.
20112011
As a consequence, redeclaration can only appear in a multi-variable short declaration.
20122012
Redeclaration does not introduce a new variable; it just assigns a new value to the original.
@@ -2352,10 +2352,11 @@ <h3 id="Composite_literals">Composite literals</h3>
23522352
[][]int{{1, 2, 3}, {4, 5}} // same as [][]int{[]int{1, 2, 3}, []int{4, 5}}
23532353
[][]Point{{{0, 1}, {1, 2}}} // same as [][]Point{[]Point{Point{0, 1}, Point{1, 2}}}
23542354
map[string]Point{"orig": {0, 0}} // same as map[string]Point{"orig": Point{0, 0}}
2355-
2356-
[...]*Point{{1.5, -3.5}, {0, 0}} // same as [...]*Point{&amp;Point{1.5, -3.5}, &amp;Point{0, 0}}
2357-
23582355
map[Point]string{{0, 0}: "orig"} // same as map[Point]string{Point{0, 0}: "orig"}
2356+
2357+
type PPoint *Point
2358+
[2]*Point{{1.5, -3.5}, {}} // same as [2]*Point{&amp;Point{1.5, -3.5}, &amp;Point{}}
2359+
[2]PPoint{{1.5, -3.5}, {}} // same as [2]PPoint{PPoint(&amp;Point{1.5, -3.5}), PPoint(&amp;Point{})}
23592360
</pre>
23602361

23612362
<p>

0 commit comments

Comments
 (0)