Skip to content

Commit b7a66be

Browse files
griesemergopherbot
authored andcommitted
cmd/compile/internal/syntax: set up dummy name and type if func name is missing
We do the same elsewhere (e.g. in parser.name when a name is missing). This ensures functions have a (dummy) name and a non-nil type. Avoids a crash in the type-checker (verified manually). A test was added here (rather than the type checker) because type- checker tests are shared between types2 and go/types and error recovery in this case is different. Fixes #63835. Change-Id: I1460fc88d23d80b8d8c181c774d6b0a56ca06317 Reviewed-on: https://go-review.googlesource.com/c/go/+/538059 Reviewed-by: Matthew Dempsky <[email protected]> TryBot-Bypass: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
1 parent 25a59de commit b7a66be

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/cmd/compile/internal/syntax/parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ func (p *parser) funcDeclOrNil() *FuncDecl {
798798
f.Name = p.name()
799799
f.TParamList, f.Type = p.funcType(context)
800800
} else {
801+
f.Name = NewName(p.pos(), "_")
802+
f.Type = new(FuncType)
803+
f.Type.pos = p.pos()
801804
msg := "expected name or ("
802805
if context != "" {
803806
msg = "expected name"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
func (x string) /* ERROR syntax error: unexpected \[, expected name */ []byte {
8+
return []byte(x)
9+
}

0 commit comments

Comments
 (0)