Warn about deprecated syntax features in imported modules.

This fixes #1072.
This commit is contained in:
Qi Xiao 2020-07-15 00:04:03 +01:00
parent 45b12127f6
commit e5e0446c5a
3 changed files with 17 additions and 2 deletions

View File

@ -283,7 +283,7 @@ func source(fm *Frame, fname string) error {
return err
}
src := parse.Source{Name: fname, Code: code, IsFile: true}
tree, err := parse.Parse(src)
tree, err := parse.ParseWithDeprecation(src, fm.ports[2].File)
if err != nil {
return err
}

View File

@ -299,7 +299,7 @@ func loadModuleFile(fm *Frame, r diag.Ranger, spec, path string) (Ns, error) {
}
func evalModule(fm *Frame, r diag.Ranger, key string, src parse.Source) (Ns, error) {
tree, err := parse.Parse(src)
tree, err := parse.ParseWithDeprecation(src, fm.ports[2].File)
if err != nil {
return nil, err
}

View File

@ -6,6 +6,7 @@ import (
"testing"
"github.com/elves/elvish/pkg/eval/errs"
"github.com/elves/elvish/pkg/prog"
"github.com/elves/elvish/pkg/util"
)
@ -160,3 +161,17 @@ func TestUse(t *testing.T) {
That("use a b c").DoesNotCompile(),
)
}
// Regression test for #1072
func TestUse_WarnsAboutDeprecatedSyntax(t *testing.T) {
restore := prog.SetShowDeprecations(true)
defer restore()
libdir, cleanup := util.InTestDir()
defer cleanup()
mustWriteFile("dep.elv", []byte("a = \\\n1"), 0600)
TestWithSetup(t, func(ev *Evaler) { ev.SetLibDir(libdir) },
// Importing module triggers check for deprecated syntax features
That("use dep").PrintsStderrWith("is deprecated"),
)
}