From: Robert Griesemer Date: Fri, 18 Nov 2016 00:39:11 +0000 (-0800) Subject: spec: clarify type elision rules for composite literals X-Git-Tag: go1.8beta1~102 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=120cf676caff29296de2dd16a2997463eb6e1579;p=gostls13.git 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 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 934bf5db85..41bac695de 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -2006,7 +2006,7 @@ _, y, _ := coord(p) // coord() returns three values; only interested in y coord

Unlike regular variable declarations, a short variable declaration may redeclare 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-blank 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 &T when the element or key type is *T. [][]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{})}