From 44761a8f84d6444f74938c73a94a4255933eedb7 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 12 Jun 2015 14:29:43 -0700 Subject: [PATCH] go/types: remove unused scope parameter from NewSignature Change-Id: I93c4185d7eeafde43b6b512b6e574d3332401c09 Reviewed-on: https://go-review.googlesource.com/10994 Reviewed-by: Alan Donovan --- go/gccgoimporter/parser.go | 4 ++-- go/gcimporter/gcimporter.go | 2 +- go/importer/import.go | 2 +- go/types/type.go | 12 +++++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/go/gccgoimporter/parser.go b/go/gccgoimporter/parser.go index 76608ca1..5bd1858f 100644 --- a/go/gccgoimporter/parser.go +++ b/go/gccgoimporter/parser.go @@ -406,7 +406,7 @@ func (p *parser) parseNamedType(n int) types.Type { results := p.parseResultList(pkg) p.expect(';') - sig := types.NewSignature(nil, receiver, params, results, isVariadic) + sig := types.NewSignature(receiver, params, results, isVariadic) nt.AddMethod(types.NewFunc(token.NoPos, pkg, name, sig)) } @@ -529,7 +529,7 @@ func (p *parser) parseResultList(pkg *types.Package) *types.Tuple { func (p *parser) parseFunctionType(pkg *types.Package) *types.Signature { params, isVariadic := p.parseParamList(pkg) results := p.parseResultList(pkg) - return types.NewSignature(pkg.Scope(), nil, params, results, isVariadic) + return types.NewSignature(nil, params, results, isVariadic) } // Func = Name FunctionType . diff --git a/go/gcimporter/gcimporter.go b/go/gcimporter/gcimporter.go index a137f207..031e8707 100644 --- a/go/gcimporter/gcimporter.go +++ b/go/gcimporter/gcimporter.go @@ -589,7 +589,7 @@ func (p *parser) parseSignature(recv *types.Var) *types.Signature { } } - return types.NewSignature(nil, recv, types.NewTuple(params...), types.NewTuple(results...), isVariadic) + return types.NewSignature(recv, types.NewTuple(params...), types.NewTuple(results...), isVariadic) } // InterfaceType = "interface" "{" [ MethodList ] "}" . diff --git a/go/importer/import.go b/go/importer/import.go index 2b6e2799..3fa37a59 100644 --- a/go/importer/import.go +++ b/go/importer/import.go @@ -382,7 +382,7 @@ func (p *importer) signature() *types.Signature { if p.int() != 0 { recv = p.param() } - return types.NewSignature(nil, recv, p.tuple(), p.tuple(), p.int() != 0) + return types.NewSignature(recv, p.tuple(), p.tuple(), p.int() != 0) } func (p *importer) param() *types.Var { diff --git a/go/types/type.go b/go/types/type.go index 4b4e5f68..3d1af20a 100644 --- a/go/types/type.go +++ b/go/types/type.go @@ -196,7 +196,11 @@ func (t *Tuple) At(i int) *Var { return t.vars[i] } // A Signature represents a (non-builtin) function or method type. type Signature struct { - scope *Scope // function scope, always present + // We need to keep the scope in Signature (rather than passing it around + // and store it in the Func Object) because when type-checking a function + // literal we call the general type checker which returns a general Type. + // We then unpack the *Signature and use the scope for the literal body. + scope *Scope // function scope, present for package-local signatures recv *Var // nil if not a method params *Tuple // (incoming) parameters from left to right; or nil results *Tuple // (outgoing) results from left to right; or nil @@ -207,9 +211,7 @@ type Signature struct { // and results, either of which may be nil. If variadic is set, the function // is variadic, it must have at least one parameter, and the last parameter // must be of unnamed slice type. -func NewSignature(scope *Scope, recv *Var, params, results *Tuple, variadic bool) *Signature { - // TODO(gri) Should we rely on the correct (non-nil) incoming scope - // or should this function allocate and populate a scope? +func NewSignature(recv *Var, params, results *Tuple, variadic bool) *Signature { if variadic { n := params.Len() if n == 0 { @@ -219,7 +221,7 @@ func NewSignature(scope *Scope, recv *Var, params, results *Tuple, variadic bool panic("types.NewSignature: variadic parameter must be of unnamed slice type") } } - return &Signature{scope, recv, params, results, variadic} + return &Signature{nil, recv, params, results, variadic} } // Recv returns the receiver of signature s (if a method), or nil if a