1
0
mirror of https://github.com/golang/go synced 2024-11-22 21:50:03 -07:00

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 <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Robert Griesemer 2015-12-18 14:21:41 -08:00
parent 97f854cd7b
commit d6a203ecab
2 changed files with 19 additions and 2 deletions

View File

@ -667,9 +667,9 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
// labelname ':' stmt // labelname ':' stmt
if labelOk { if labelOk {
// If we have a labelname, it was parsed by operand // 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 { switch lhs.Op {
case ONAME, ONONAME, OTYPE, OPACK: case ONAME, ONONAME, OTYPE, OPACK, OLITERAL:
lhs = newname(lhs.Sym) lhs = newname(lhs.Sym)
default: default:
p.syntax_error("expecting semicolon or newline or }") p.syntax_error("expecting semicolon or newline or }")

View File

@ -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:
}