Fix use of the builtin module via explicit "builtin".

Some of the variables are added after the Evaler is created, but that change was
not synchronized back to the copy of the builtin module that is imported with
"use builtin".

This fixes #1414.
This commit is contained in:
Qi Xiao 2021-10-28 22:28:13 +01:00
parent d71e52cbd7
commit c1dce661b7
2 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,17 @@
package eval_test
import (
"testing"
. "src.elv.sh/pkg/eval"
. "src.elv.sh/pkg/eval/evaltest"
"src.elv.sh/pkg/eval/vals"
)
func TestExplicitBuiltinModule(t *testing.T) {
TestWithSetup(t, func(ev *Evaler) { ev.Args = vals.MakeList("a", "b") },
That("all $args").Puts("a", "b"),
// Regression test for #1414
That("use builtin; all $builtin:args").Puts("a", "b"),
)
}

View File

@ -154,8 +154,8 @@ func NewEvaler() *Evaler {
deprecations: newDeprecationRegistry(),
modules: map[string]*Ns{"builtin": builtin},
BundledModules: map[string]string{},
modules: make(map[string]*Ns),
BundledModules: make(map[string]string),
valuePrefix: defaultValuePrefix,
notifyBgJobSuccess: defaultNotifyBgJobSuccess,
@ -180,6 +180,9 @@ func NewEvaler() *Evaler {
vars.FromGet(func() interface{} { return strconv.Itoa(ev.getNumBgJobs()) })).
AddVar("args", vars.FromGet(func() interface{} { return ev.Args })))
// Install the "builtin" module after extension is complete.
ev.modules["builtin"] = ev.builtin
return ev
}