From d6a203ecabe5965c55f036c8c0479bdcd2a51683 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 18 Dec 2015 14:21:41 -0800 Subject: [PATCH] cmd/compile: const name and label name may match Fixes #13684. Change-Id: I3977119b6eb1d6b7dc2ea1e7d6656a8f0d421bc1 Reviewed-on: https://go-review.googlesource.com/18060 Run-TryBot: Robert Griesemer Reviewed-by: Rob Pike --- src/cmd/compile/internal/gc/parser.go | 4 ++-- test/fixedbugs/issue13684.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/fixedbugs/issue13684.go diff --git a/src/cmd/compile/internal/gc/parser.go b/src/cmd/compile/internal/gc/parser.go index c3f131fe76..3279f4c6b0 100644 --- a/src/cmd/compile/internal/gc/parser.go +++ b/src/cmd/compile/internal/gc/parser.go @@ -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 index 0000000000..eda92a37e3 --- /dev/null +++ b/test/fixedbugs/issue13684.go @@ -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: +} -- 2.50.0