]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate addmethod tpkg parameter
authorMatthew Dempsky <mdempsky@google.com>
Tue, 30 Aug 2016 21:21:06 +0000 (14:21 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 30 Aug 2016 21:41:33 +0000 (21:41 +0000)
It's only needed for a check that can be pushed up into bimport.go,
where it makes more sense anyway.

Change-Id: I6ef381ff4f29627b0f390ce27fef08902932bea6
Reviewed-on: https://go-review.googlesource.com/28177
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/typecheck.go

index 6232f81d7fef33f6db03929af58b6040963772bd..3b9597932006759b54ea31955c06301fc5fd9f9f 100644 (file)
@@ -467,6 +467,11 @@ func (p *importer) typ() *Type {
                        p.pos()
                        sym := p.fieldSym()
 
+                       // during import unexported method names should be in the type's package
+                       if !exportname(sym.Name) && sym.Pkg != tsym.Pkg {
+                               Fatalf("imported method name %v in wrong package %s\n", sconv(sym, FmtSign), tsym.Pkg.Name)
+                       }
+
                        recv := p.paramList() // TODO(gri) do we need a full param list for the receiver?
                        params := p.paramList()
                        result := p.paramList()
@@ -475,7 +480,7 @@ func (p *importer) typ() *Type {
                        n := methodname(newname(sym), recv[0].Right)
                        n.Type = functype(recv[0], params, result)
                        checkwidth(n.Type)
-                       addmethod(sym, n.Type, tsym.Pkg, false, nointerface)
+                       addmethod(sym, n.Type, false, nointerface)
                        p.funcList = append(p.funcList, n)
                        importlist = append(importlist, n)
 
index ae5bb557aa8f5ad252651edaf874426278e003d9..3d20521d4a11fe0de0736d09c1b4a527c80524b1 100644 (file)
@@ -1153,8 +1153,7 @@ func methodname(n *Node, t *Node) *Node {
 // Add a method, declared as a function.
 // - msym is the method symbol
 // - t is function type (with receiver)
-// - tpkg is the package of the type declaring the method during import, or nil (ignored) --- for verification only
-func addmethod(msym *Sym, t *Type, tpkg *Pkg, local, nointerface bool) {
+func addmethod(msym *Sym, t *Type, local, nointerface bool) {
        // get field sym
        if msym == nil {
                Fatalf("no method symbol")
@@ -1232,11 +1231,6 @@ func addmethod(msym *Sym, t *Type, tpkg *Pkg, local, nointerface bool) {
        f := structfield(n)
        f.Nointerface = nointerface
 
-       // during import unexported method names should be in the type's package
-       if tpkg != nil && f.Sym != nil && !exportname(f.Sym.Name) && f.Sym.Pkg != tpkg {
-               Fatalf("imported method name %v in wrong package %s\n", sconv(f.Sym, FmtSign), tpkg.Name)
-       }
-
        mt.Methods().Append(f)
 }
 
index f34f4751bc6a17dfe9865cd084c7d9b6e3dd1f92..d08f52e5c542113446873ea16e05c45bf841f797 100644 (file)
@@ -3388,7 +3388,7 @@ func typecheckfunc(n *Node) {
        t.SetNname(n.Func.Nname)
        rcvr := t.Recv()
        if rcvr != nil && n.Func.Shortname != nil {
-               addmethod(n.Func.Shortname.Sym, t, nil, true, n.Func.Pragma&Nointerface != 0)
+               addmethod(n.Func.Shortname.Sym, t, true, n.Func.Pragma&Nointerface != 0)
        }
 
        for _, ln := range n.Func.Dcl {