mirror of https://github.com/golang/go.git
go/parser, go/types: minor cleanups around type parameters
Change-Id: Ic2faf89a29193d1d50bb5bdccce0fda2301785ed
This commit is contained in:
parent
2c0e53f518
commit
b5ecc31064
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue