mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: report type parameter error for methods only once
Move switch to enable method type parameters entirely to the parser, by adding the mode AllowMethodTypeParams. Ensure that the error messages are consistent. Remove unnecessary code in the type checker. Fixes #50317. Change-Id: I4f3958722400bdb919efa4c494b85cf62f4002bb Reviewed-on: https://go-review.googlesource.com/c/go/+/376054 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
b9cae6f78f
commit
042548b1fd
14 changed files with 43 additions and 45 deletions
|
|
@ -760,7 +760,13 @@ func (p *parser) funcDeclOrNil() *FuncDecl {
|
|||
}
|
||||
|
||||
f.Name = p.name()
|
||||
f.TParamList, f.Type = p.funcType("")
|
||||
|
||||
context := ""
|
||||
if f.Recv != nil && p.mode&AllowMethodTypeParams == 0 {
|
||||
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()
|
||||
}
|
||||
|
|
@ -1415,7 +1421,7 @@ func (p *parser) funcType(context string) ([]*Field, *FuncType) {
|
|||
if p.allowGenerics() && p.got(_Lbrack) {
|
||||
if context != "" {
|
||||
// accept but complain
|
||||
p.syntaxErrorAt(typ.pos, context+" cannot have type parameters")
|
||||
p.syntaxErrorAt(typ.pos, context+" must have no type parameters")
|
||||
}
|
||||
if p.tok == _Rbrack {
|
||||
p.syntaxError("empty type parameter list")
|
||||
|
|
@ -1823,7 +1829,7 @@ func (p *parser) methodDecl() *Field {
|
|||
// TODO(gri) Record list as type parameter list with f.Type
|
||||
// if we want to type-check the generic method.
|
||||
// For now, report an error so this is not a silent event.
|
||||
p.errorAt(pos, "interface method cannot have type parameters")
|
||||
p.errorAt(pos, "interface method must have no type parameters")
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue