mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
compiler: fix import alias handling
This commit is contained in:
parent
f454112845
commit
8f8c7d2839
3 changed files with 24 additions and 3 deletions
|
@ -246,7 +246,11 @@ func (c *codegen) analyzeFuncUsage() funcUsage {
|
|||
case *ast.CallExpr:
|
||||
switch t := n.Fun.(type) {
|
||||
case *ast.Ident:
|
||||
usage[c.getIdentName("", t.Name)] = true
|
||||
var pkgPath string
|
||||
if !isMain {
|
||||
pkgPath = pkg.Path()
|
||||
}
|
||||
usage[c.getIdentName(pkgPath, t.Name)] = true
|
||||
case *ast.SelectorExpr:
|
||||
name, _ := c.getFuncNameFromSelector(t)
|
||||
usage[name] = true
|
||||
|
@ -254,7 +258,7 @@ func (c *codegen) analyzeFuncUsage() funcUsage {
|
|||
case *ast.FuncDecl:
|
||||
// exported functions are always assumed to be used
|
||||
if isMain && n.Name.IsExported() {
|
||||
usage[c.getFuncNameFromDecl(pkg.Path(), n)] = true
|
||||
usage[c.getFuncNameFromDecl("", n)] = true
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
|
|
@ -1986,7 +1986,11 @@ func (c *codegen) compile(info *buildInfo, pkg *loader.PackageInfo) error {
|
|||
case *ast.FuncDecl:
|
||||
// Don't convert the function if it's not used. This will save a lot
|
||||
// of bytecode space.
|
||||
name := c.getFuncNameFromDecl(pkg.Path(), n)
|
||||
pkgPath := ""
|
||||
if pkg != c.mainPkg.Pkg { // not a main package
|
||||
pkgPath = pkg.Path()
|
||||
}
|
||||
name := c.getFuncNameFromDecl(pkgPath, n)
|
||||
if !isInitFunc(n) && !isDeployFunc(n) && funUsage.funcUsed(name) &&
|
||||
(!isInteropPath(pkg.Path()) && !canInline(pkg.Path())) {
|
||||
c.convertFuncDecl(f, n, pkg)
|
||||
|
|
|
@ -48,3 +48,16 @@ func TestMultipleDirFileImport(t *testing.T) {
|
|||
`
|
||||
eval(t, src, big.NewInt(1))
|
||||
}
|
||||
|
||||
func TestImportNameSameAsOwn(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/foo"
|
||||
func get3() int { return 3 }
|
||||
func Main() int {
|
||||
return get3()
|
||||
}
|
||||
func unused() int {
|
||||
return foo.Bar()
|
||||
}`
|
||||
eval(t, src, big.NewInt(3))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue