mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
go/parser: require label after goto
Fixes #70957 Change-Id: Ied7cf29ea3e02bb71ddce8a19ddd381ce5991ed1 GitHub-Last-Rev: 310bd1537b7a36758f3fbf8db476fa68e1a11599 GitHub-Pull-Request: golang/go#70958 Reviewed-on: https://go-review.googlesource.com/c/go/+/638395 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
2f036e1475
commit
bdef177831
9
src/cmd/compile/internal/syntax/testdata/issue70957.go
vendored
Normal file
9
src/cmd/compile/internal/syntax/testdata/issue70957.go
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2024 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 p
|
||||||
|
|
||||||
|
func f() { goto /* ERROR syntax error: unexpected semicolon, expected name */ ;}
|
||||||
|
|
||||||
|
func f() { goto } // ERROR syntax error: unexpected }, expected name
|
@ -2066,7 +2066,7 @@ func (p *parser) parseBranchStmt(tok token.Token) *ast.BranchStmt {
|
|||||||
|
|
||||||
pos := p.expect(tok)
|
pos := p.expect(tok)
|
||||||
var label *ast.Ident
|
var label *ast.Ident
|
||||||
if tok != token.FALLTHROUGH && p.tok == token.IDENT {
|
if tok == token.GOTO || ((tok == token.CONTINUE || tok == token.BREAK) && p.tok == token.IDENT) {
|
||||||
label = p.parseIdent()
|
label = p.parseIdent()
|
||||||
}
|
}
|
||||||
p.expectSemi()
|
p.expectSemi()
|
||||||
|
@ -212,6 +212,10 @@ var invalids = []string{
|
|||||||
`package p; func (T) _[ /* ERROR "must have no type parameters" */ A, B C[A, B]](a A) B`,
|
`package p; func (T) _[ /* ERROR "must have no type parameters" */ A, B C[A, B]](a A) B`,
|
||||||
|
|
||||||
`package p; func(*T[e, e /* ERROR "e redeclared" */ ]) _()`,
|
`package p; func(*T[e, e /* ERROR "e redeclared" */ ]) _()`,
|
||||||
|
|
||||||
|
// go.dev/issue/70957
|
||||||
|
`package p; func f() {goto; /* ERROR "expected 'IDENT', found ';'" */ }`,
|
||||||
|
`package p; func f() {goto} /* ERROR "expected 'IDENT', found '}'" */ }`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalid(t *testing.T) {
|
func TestInvalid(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user