Skip to content

Commit 272e0ea

Browse files
committed
go/parser: require label after goto
Change-Id: I0209f9d1870a2932dfbd347c252e3f9af055afd3
1 parent 500675a commit 272e0ea

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/go/parser/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,7 +2050,7 @@ func (p *parser) parseBranchStmt(tok token.Token) *ast.BranchStmt {
20502050

20512051
pos := p.expect(tok)
20522052
var label *ast.Ident
2053-
if tok != token.FALLTHROUGH && p.tok == token.IDENT {
2053+
if (tok != token.FALLTHROUGH && p.tok == token.IDENT) || tok == token.GOTO {
20542054
label = p.parseIdent()
20552055
}
20562056
p.expectSemi()

src/go/parser/short_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ var invalids = []string{
204204
`package p; func (T) _[ /* ERROR "must have no type parameters" */ A, B C[A, B]](a A) B`,
205205

206206
`package p; func(*T[e, e /* ERROR "e redeclared" */ ]) _()`,
207+
208+
// go.dev/issue/70957
209+
`package p; func f() {goto; /* ERROR "expected 'IDENT', found ';'" */ }`,
210+
`package p; func f() {goto} /* ERROR "expected 'IDENT', found '}'" */ }`,
207211
}
208212

209213
func TestInvalid(t *testing.T) {

0 commit comments

Comments
 (0)