From 06dc5db75d4c2548c0187f34ce79389678be7ca0 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 22 Jan 2026 16:16:17 -0800 Subject: cmd/compile, go/*: move method type parameter checks from parsers to type checkers The parsers (cmd/compile/internal/syntax and go/parser) always accepted type parameters on methods for parser robustness but reported an error. With this change, the parsers accept the type parameters on methods, and then the type checkers (cmd/compile/internal/types2 and go/types) complain about them. Add test case for method type parameters when running the parsers only. Adjust some existing test cases as needed. This change is a necessary first step towards implementing generic methods but does not enable them. For #77273. Change-Id: I291fcf0aef0c917c74b32131c88b9e4ed71c5060 Reviewed-on: https://go-review.googlesource.com/c/go/+/738441 Reviewed-by: Mark Freeman LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/syntax/parser.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/cmd/compile/internal/syntax/parser.go') diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go index 8278685943..aade7b9fd3 100644 --- a/src/cmd/compile/internal/syntax/parser.go +++ b/src/cmd/compile/internal/syntax/parser.go @@ -797,9 +797,9 @@ func (p *parser) funcDeclOrNil() *FuncDecl { f.pos = p.pos() f.Pragma = p.takePragma() - var context string + hasRecv := false if p.got(_Lparen) { - context = "method" + hasRecv = true rcvr := p.paramList(nil, nil, _Rparen, false, false) switch len(rcvr) { case 0: @@ -814,13 +814,13 @@ func (p *parser) funcDeclOrNil() *FuncDecl { if p.tok == _Name { f.Name = p.name() - f.TParamList, f.Type = p.funcType(context) + f.TParamList, f.Type = p.funcType("") } else { f.Name = NewName(p.pos(), "_") f.Type = new(FuncType) f.Type.pos = p.pos() msg := "expected name or (" - if context != "" { + if hasRecv { msg = "expected name" } p.syntaxError(msg) -- cgit v1.3-5-g9baa