Imported `type` is not visible in child scope
ipsusila opened this issue · 3 comments
ipsusila commented
vm
is initialized using the following method:
//Host golang code
env := vm.NewEnv()
core.Import(env)
packages.DefineImport(env)
and when executing the following Anko script:
var time = import('time')
//work as expected
d1 = new(time.Duration)
println(d1)
func foo() {
//work as expected
println(time.Now())
//error: "no namespace called: time"
d2 = new(time.Duration)
println(d2)
}
//call foo()
foo()
error happened when trying to create instance of time.Duration
(variable d2
) inside the function foo
. Temporary workaround is adding import
statement inside the function, but it won't be available inside its child scope, e.g. the following Anko script won't work due to similar reason:
var time = import('time')
//work as expected
d1 = new(time.Duration)
println(d1)
func foo() {
var time = import('time') //temporary workaround
//work as expected
d2 = new(time.Duration)
println(d2)
if d2 != nil {
//error: "no namespace called: time"
d3 = new(time.Duration)
println(d2)
}
}
//call foo()
foo()
MichaelS11 commented
Thank you for finding this issue. Welcome to test on new PR #310 or can wait for merge.
MichaelS11 commented
@ipsusila Please test and close if fixed.
ipsusila commented
@MichaelS11 Thank you. I've tested the latest commit and now it is working as expected.