mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Fix panic in completion of non-existing namespace variable.
This fixes #1209.
This commit is contained in:
parent
363b712f66
commit
9991b08fe0
|
@ -74,7 +74,11 @@ func (ev *Evaler) PurelyEvalPrimary(pn *parse.Primary) interface{} {
|
|||
fm := &Frame{Evaler: ev, local: ev.Global(), up: new(Ns)}
|
||||
ref := resolveVarRef(fm, qname, nil)
|
||||
if ref != nil {
|
||||
return deref(fm, ref).Get()
|
||||
variable := deref(fm, ref)
|
||||
if variable == nil {
|
||||
return nil
|
||||
}
|
||||
return variable.Get()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -30,6 +30,10 @@ func TestPurelyEvalCompound(t *testing.T) {
|
|||
{code: "foo$x", upto: 3, wantValue: "foo"},
|
||||
{code: "~", wantValue: home},
|
||||
{code: "~/foo", wantValue: home + "/foo"},
|
||||
{code: "$ns:x", wantValue: "foo"},
|
||||
|
||||
{code: "$bad", wantErr: ErrImpure},
|
||||
{code: "$ns:bad", wantErr: ErrImpure},
|
||||
|
||||
{code: "[abc]", wantErr: ErrImpure},
|
||||
{code: "$y", wantErr: ErrImpure},
|
||||
|
@ -38,10 +42,13 @@ func TestPurelyEvalCompound(t *testing.T) {
|
|||
}
|
||||
|
||||
ev := NewEvaler()
|
||||
ev.AddGlobal(NsBuilder{
|
||||
g := NsBuilder{
|
||||
"x": vars.NewReadOnly("bar"),
|
||||
"y": vars.NewReadOnly(vals.MakeList()),
|
||||
}.Ns())
|
||||
}.
|
||||
AddNs("ns", NsBuilder{"x": vars.NewReadOnly("foo")}.Ns()).
|
||||
Ns()
|
||||
ev.AddGlobal(g)
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.code, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user