aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go22
-rw-r--r--src/cmd/compile/internal/syntax/testdata/issue56022.go10
2 files changed, 21 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index b31b712f1d..d80b269557 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -767,7 +767,9 @@ func (p *parser) funcDeclOrNil() *FuncDecl {
f.pos = p.pos()
f.Pragma = p.takePragma()
+ var context string
if p.got(_Lparen) {
+ context = "method"
rcvr := p.paramList(nil, nil, _Rparen, false)
switch len(rcvr) {
case 0:
@@ -780,19 +782,17 @@ func (p *parser) funcDeclOrNil() *FuncDecl {
}
}
- if p.tok != _Name {
- p.syntaxError("expected name or (")
+ if p.tok == _Name {
+ f.Name = p.name()
+ f.TParamList, f.Type = p.funcType(context)
+ } else {
+ msg := "expected name or ("
+ if context != "" {
+ msg = "expected name"
+ }
+ p.syntaxError(msg)
p.advance(_Lbrace, _Semi)
- return nil
- }
-
- f.Name = p.name()
-
- context := ""
- if f.Recv != nil {
- context = "method" // don't permit (method) type parameters in funcType
}
- f.TParamList, f.Type = p.funcType(context)
if p.tok == _Lbrace {
f.Body = p.funcBody()
diff --git a/src/cmd/compile/internal/syntax/testdata/issue56022.go b/src/cmd/compile/internal/syntax/testdata/issue56022.go
new file mode 100644
index 0000000000..d28d35cd8e
--- /dev/null
+++ b/src/cmd/compile/internal/syntax/testdata/issue56022.go
@@ -0,0 +1,10 @@
+// Copyright 2022 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 /* ERROR unexpected {, expected name or \($ */ {}
+func (T) /* ERROR unexpected {, expected name$ */ {}
+func (T) /* ERROR unexpected \(, expected name$ */ () {}
+func (T) /* ERROR unexpected \(, expected name$ */ ()