diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go index 5a8d9875a6..edec5a7d5b 100644 --- a/src/go/parser/parser.go +++ b/src/go/parser/parser.go @@ -2785,16 +2785,16 @@ func (p *parser) parseFuncDecl() *ast.FuncDecl { pos := p.expect(token.FUNC) scope := ast.NewScope(p.topScope) // function scope - mode := typeParamsOk | variadicOk + mode := typeParamsOk var recv *ast.FieldList if p.tok == token.LPAREN { _, recv = p.parseParameters(scope, 0, "receiver") - mode &^= typeParamsOk + mode = 0 } ident := p.parseIdent() - tparams, params := p.parseParameters(scope, mode|methodTypeParamsOk, "method") // context string only used in methods + tparams, params := p.parseParameters(scope, mode|methodTypeParamsOk|variadicOk, "method") // context string only used in methods results := p.parseResult(scope, true) var body *ast.BlockStmt diff --git a/src/go/types/NOTES b/src/go/types/NOTES index 102a920f94..2b54fcc658 100644 --- a/src/go/types/NOTES +++ b/src/go/types/NOTES @@ -1,5 +1,5 @@ This file works as a sort of notebook/implementation log. It replaces my notebook based approach -so we have a better track record. I only switched to this file recently, hence it is incomplete. +so we have a better track record. I only switched to this file in Nov 2019, hence it is incomplete. ---------------------------------------------------------------------------------------------------- TODO @@ -81,4 +81,3 @@ DESIGN/IMPLEMENTATION - 1/7/2020: The current implementation permits empty type parameter lists as in: "func f(type)(x int)" but we cannot call such a function as "f()(1)"; the empty type argument list causes problems. We should either disallow empty type parameter lists or document this well. - diff --git a/src/go/types/call.go b/src/go/types/call.go index 4f89802fa8..a3c3bff19b 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -526,7 +526,8 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { } x.mode = value x.typ = &Signature{ - params: NewTuple(append([]*Var{NewVar(token.NoPos, check.pkg, "", x.typ)}, params...)...), + tparams: sig.tparams, + params: NewTuple(append([]*Var{NewVar(token.NoPos, check.pkg, "_", x.typ)}, params...)...), results: sig.results, variadic: sig.variadic, } diff --git a/src/go/types/eval_test.go b/src/go/types/eval_test.go index d940bf0e80..33dfbefe19 100644 --- a/src/go/types/eval_test.go +++ b/src/go/types/eval_test.go @@ -155,9 +155,9 @@ func TestEvalPos(t *testing.T) { import "io" type R = io.Reader func _() { - /* interface{R}.Read => , func(interface{io.Reader}, p []byte) (n int, err error) */ + /* interface{R}.Read => , func(_ interface{io.Reader}, p []byte) (n int, err error) */ _ = func() { - /* interface{io.Writer}.Write => , func(interface{io.Writer}, p []byte) (n int, err error) */ + /* interface{io.Writer}.Write => , func(_ interface{io.Writer}, p []byte) (n int, err error) */ type io interface {} // must not shadow io in line above } type R interface {} // must not shadow R in first line of this function body diff --git a/src/go/types/testdata/typeparams.go2 b/src/go/types/testdata/typeparams.go2 index 98c5c18927..796d69506c 100644 --- a/src/go/types/testdata/typeparams.go2 +++ b/src/go/types/testdata/typeparams.go2 @@ -137,8 +137,8 @@ type T struct {} func (T) m1() {} // Experimental: We allow method type parameters. -// func (T) m2( /* ERROR method must have no type parameters */ type)() {} -// func (T) m3( /* ERROR method must have no type parameters */ type P)() {} +func (T) m2(type)() {} +func (T) m3(type P)() {} // type inference across parameterized types