Skip to content

Commit

Permalink
Merge pull request #304 from goplus/main
Browse files Browse the repository at this point in the history
InitGopPkg fix: import if pkg uncomplete
  • Loading branch information
xushiwei authored Nov 1, 2023
2 parents 04e1fe1 + 6691bec commit 8e1e74a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,18 @@ func NewContext() *Context {
}

// InitGopPkg initializes a Go+ packages.
func (p *Context) InitGopPkg(pkgImp *types.Package) {
func (p *Context) InitGopPkg(importer types.Importer, pkgImp *types.Package) {
pkgPath := pkgImp.Path()
if stdPkg(pkgPath) || p.chkGopImports[pkgPath] {
return
}
if !pkgImp.Complete() {
importer.Import(pkgPath)
}
initThisGopPkg(pkgImp)
p.chkGopImports[pkgPath] = true
for _, imp := range pkgImp.Imports() {
p.InitGopPkg(imp)
p.InitGopPkg(importer, imp)
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/foo/foo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@

package foo

import (
"github.com/goplus/gox/internal/bar"
)

const (
GopPackage = true // to indicate this is a Go+ package
)

func CallBar() *bar.Game {
return nil
}

// -----------------------------------------------------------------------------

type nodeSetIt struct {
Expand Down
2 changes: 1 addition & 1 deletion package.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (p *File) importPkg(this *Package, pkgPath string, src ast.Node) *PkgRef {
}
panic(e)
} else {
this.ctx.InitGopPkg(pkgImp)
this.ctx.InitGopPkg(this.imp, pkgImp)
}
pkgImport = &PkgRef{Types: pkgImp}
p.importPkgs[pkgPath] = pkgImport
Expand Down

0 comments on commit 8e1e74a

Please sign in to comment.