mirror of
https://github.com/golang/go.git
synced 2024-09-29 06:17:11 +00:00
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>
This commit is contained in:
parent
a34fddf46c
commit
120cf676ca
@ -1,6 +1,6 @@
|
||||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Version of November 4, 2016",
|
||||
"Subtitle": "Version of November 18, 2016",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
@ -2006,7 +2006,7 @@ _, y, _ := coord(p) // coord() returns three values; only interested in y coord
|
||||
<p>
|
||||
Unlike regular variable declarations, a short variable declaration may <i>redeclare</i>
|
||||
variables provided they were originally declared earlier in the same block
|
||||
(or the parameter lists if the block is the function body) with the same type,
|
||||
(or the parameter lists if the block is the function body) with the same type,
|
||||
and at least one of the non-<a href="#Blank_identifier">blank</a> variables is new.
|
||||
As a consequence, redeclaration can only appear in a multi-variable short declaration.
|
||||
Redeclaration does not introduce a new variable; it just assigns a new value to the original.
|
||||
@ -2352,10 +2352,11 @@ the <code>&T</code> when the element or key type is <code>*T</code>.
|
||||
[][]int{{1, 2, 3}, {4, 5}} // same as [][]int{[]int{1, 2, 3}, []int{4, 5}}
|
||||
[][]Point{{{0, 1}, {1, 2}}} // same as [][]Point{[]Point{Point{0, 1}, Point{1, 2}}}
|
||||
map[string]Point{"orig": {0, 0}} // same as map[string]Point{"orig": Point{0, 0}}
|
||||
|
||||
[...]*Point{{1.5, -3.5}, {0, 0}} // same as [...]*Point{&Point{1.5, -3.5}, &Point{0, 0}}
|
||||
|
||||
map[Point]string{{0, 0}: "orig"} // same as map[Point]string{Point{0, 0}: "orig"}
|
||||
|
||||
type PPoint *Point
|
||||
[2]*Point{{1.5, -3.5}, {}} // same as [2]*Point{&Point{1.5, -3.5}, &Point{}}
|
||||
[2]PPoint{{1.5, -3.5}, {}} // same as [2]PPoint{PPoint(&Point{1.5, -3.5}), PPoint(&Point{})}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
|
Loading…
Reference in New Issue
Block a user