Skip to content

Commit

Permalink
fix: implicit import package name was not correctly generated
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Dec 11, 2019
1 parent 1ff1a50 commit 0d2c39d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions _test/foo-bar/foo-bar.go
@@ -0,0 +1,3 @@
package bar

var Name = "foo-bar"
10 changes: 10 additions & 0 deletions _test/import7.go
@@ -0,0 +1,10 @@
package main

import "github.com/containous/yaegi/_test/foo-bar"

func main() {
println(bar.Name)
}

// Output:
// foo-bar
6 changes: 4 additions & 2 deletions interp/cfg.go
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"log"
"math"
"path"
"reflect"
"regexp"
"unicode"
)

Expand All @@ -32,6 +32,8 @@ var constBltn = map[string]func(*node){
"real": realConst,
}

var identifier = regexp.MustCompile(`([\pL_][\pL_\d]*)$`)

// cfg generates a control flow graph (CFG) from AST (wiring successors in AST)
// and pre-compute frame sizes and indexes for all un-named (temporary) and named
// variables. A list of nodes of init functions is returned.
Expand Down Expand Up @@ -316,7 +318,7 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
name = n.child[0].ident
} else {
ipath = n.child[0].rval.String()
name = path.Base(ipath)
name = identifier.FindString(ipath)
}
if interp.binPkg[ipath] != nil && name != "." {
sc.sym[name] = &symbol{kind: pkgSym, typ: &itype{cat: binPkgT, path: ipath}}
Expand Down
3 changes: 1 addition & 2 deletions interp/gta.go
@@ -1,7 +1,6 @@
package interp

import (
"path"
"reflect"
)

Expand Down Expand Up @@ -126,7 +125,7 @@ func (interp *Interpreter) gta(root *node, rpath string) ([]*node, error) {
name = n.child[0].ident
} else {
ipath = n.child[0].rval.String()
name = path.Base(ipath)
name = identifier.FindString(ipath)
}
// Try to import a binary package first, or a source package
if interp.binPkg[ipath] != nil {
Expand Down

0 comments on commit 0d2c39d

Please sign in to comment.