Skip to content

Commit 0d40138

Browse files
authored
Merge pull request #427 from visualfc/initgop
add InitThisGopPkgEx for map overload name to position
2 parents 4d251e7 + 4bce01e commit 0d40138

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

import.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ func isGopCommon(name string) bool {
9797

9898
// InitThisGopPkg initializes a Go+ package.
9999
func InitThisGopPkg(pkg *types.Package) {
100+
InitThisGopPkgEx(pkg, nil)
101+
}
102+
103+
// InitThisGopPkg initializes a Go+ package. pos map overload name to postion.
104+
func InitThisGopPkgEx(pkg *types.Package, pos map[string]token.Pos) {
100105
scope := pkg.Scope()
101106
gopos := make([]string, 0, 4)
102107
overloads := make(map[omthd][]types.Object)
@@ -156,15 +161,15 @@ func InitThisGopPkg(pkg *types.Package) {
156161
}
157162
}
158163
if len(fns) > 0 {
159-
newOverload(pkg, scope, m, fns)
164+
newOverload(pkg, scope, m, fns, pos)
160165
}
161166
delete(overloads, m)
162167
}
163168
}
164169
for key, items := range overloads {
165170
off := len(key.name) + 2
166171
fns := overloadFuncs(off, items)
167-
newOverload(pkg, scope, key, fns)
172+
newOverload(pkg, scope, key, fns, pos)
168173
}
169174
for name, items := range onameds {
170175
off := len(name) + 2
@@ -310,19 +315,19 @@ func checkOverloads(scope *types.Scope, gopoName string) (ret []string, exists b
310315
return
311316
}
312317

313-
func newOverload(pkg *types.Package, scope *types.Scope, m omthd, fns []types.Object) {
318+
func newOverload(pkg *types.Package, scope *types.Scope, m omthd, fns []types.Object, pos map[string]token.Pos) {
314319
if m.typ == nil {
315320
if debugImport {
316321
log.Println("==> NewOverloadFunc", m.name)
317322
}
318-
o := NewOverloadFunc(token.NoPos, pkg, m.name, fns...)
323+
o := NewOverloadFunc(pos[m.name], pkg, m.name, fns...)
319324
scope.Insert(o)
320325
checkGoptsx(pkg, scope, m.name, o)
321326
} else {
322327
if debugImport {
323328
log.Println("==> NewOverloadMethod", m.typ.Obj().Name(), m.name)
324329
}
325-
NewOverloadMethod(m.typ, token.NoPos, pkg, m.name, fns...)
330+
NewOverloadMethod(m.typ, pos[m.typ.Obj().Name()+"."+m.name], pkg, m.name, fns...)
326331
}
327332
}
328333

0 commit comments

Comments
 (0)