]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: const name and label name may match
authorRobert Griesemer <gri@golang.org>
Fri, 18 Dec 2015 22:21:41 +0000 (14:21 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 21 Dec 2015 20:21:28 +0000 (20:21 +0000)
Fixes #13684.

Change-Id: I3977119b6eb1d6b7dc2ea1e7d6656a8f0d421bc1
Reviewed-on: https://go-review.googlesource.com/18060
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/compile/internal/gc/parser.go
test/fixedbugs/issue13684.go [new file with mode: 0644]

index c3f131fe7641ad16b229be8874b131199027c27c..3279f4c6b074713d821efad025dce10a2f9e974e 100644 (file)
@@ -667,9 +667,9 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
                        // labelname ':' stmt
                        if labelOk {
                                // If we have a labelname, it was parsed by operand
-                               // (calling p.name()) and given an ONAME, ONONAME, OTYPE, or OPACK node.
+                               // (calling p.name()) and given an ONAME, ONONAME, OTYPE, OPACK, or OLITERAL node.
                                switch lhs.Op {
-                               case ONAME, ONONAME, OTYPE, OPACK:
+                               case ONAME, ONONAME, OTYPE, OPACK, OLITERAL:
                                        lhs = newname(lhs.Sym)
                                default:
                                        p.syntax_error("expecting semicolon or newline or }")
diff --git a/test/fixedbugs/issue13684.go b/test/fixedbugs/issue13684.go
new file mode 100644 (file)
index 0000000..eda92a3
--- /dev/null
@@ -0,0 +1,17 @@
+// run
+
+// Copyright 2015 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.
+
+// Verify that a label name matching a constant name
+// is permitted.
+
+package main
+
+const labelname = 1
+
+func main() {
+       goto labelname
+labelname:
+}