]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: add comment and test for #15550
authorMatthew Dempsky <mdempsky@google.com>
Wed, 1 Feb 2017 23:13:48 +0000 (15:13 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 2 Feb 2017 04:25:23 +0000 (04:25 +0000)
When switching to the new parser, I changed cmd/compile to handle iota
per an intuitive interpretation of how nested constant declarations
should work (which also matches go/types).

Note: if we end up deciding that the current spec wording is
intentional (i.e., confirming gccgo's current behavior), the test will
need to be updated to expect 4 instead of 1.

Updates #15550.

Change-Id: I441f5f13209f172b73ef75031f2a9daa5e985277
Reviewed-on: https://go-review.googlesource.com/36122
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/noder.go
test/fixedbugs/issue15550.go [new file with mode: 0644]

index 912652110cb86ab5e6ebd3a020655d47a2090a0a..482578d10ae2ac187cff7aff75b6dca8495f156f 100644 (file)
@@ -204,6 +204,9 @@ func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
        return variter(names, typ, exprs)
 }
 
+// constState tracks state between constant specifiers within a
+// declaration group. This state is kept separate from noder so nested
+// constant declarations are handled correctly (e.g., issue 15550).
 type constState struct {
        group  *syntax.Group
        typ    *Node
diff --git a/test/fixedbugs/issue15550.go b/test/fixedbugs/issue15550.go
new file mode 100644 (file)
index 0000000..f2853fc
--- /dev/null
@@ -0,0 +1,28 @@
+// run
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "unsafe"
+
+const (
+       _ = unsafe.Sizeof(func() int {
+               const (
+                       _ = 1
+                       _
+                       _
+               )
+               return 0
+       }())
+
+       y = iota
+)
+
+func main() {
+       if y != 1 {
+               panic(y)
+       }
+}