mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-11-27 23:11:20 +08:00
When variable cannot set, point to the variable in the stack trace.
This fixes #255.
This commit is contained in:
parent
53593c3ab7
commit
a33ecb2da4
|
@ -135,8 +135,8 @@ func TestCommand_Assignment(t *testing.T) {
|
|||
// Assignment errors when the RHS errors.
|
||||
That("x = [][1]").Throws(ErrorWithType(errs.OutOfRange{}), "[][1]"),
|
||||
// Assignment errors itself.
|
||||
That("true = 1").Throws(vars.ErrSetReadOnlyVar, "true = 1"),
|
||||
That("@true = 1").Throws(vars.ErrSetReadOnlyVar, "@true = 1"),
|
||||
That("true = 1").Throws(vars.ErrSetReadOnlyVar, "true"),
|
||||
That("@true = 1").Throws(vars.ErrSetReadOnlyVar, "@true"),
|
||||
// Arity mismatch.
|
||||
That("x = 1 2").Throws(
|
||||
errs.ArityMismatch{
|
||||
|
|
|
@ -124,7 +124,7 @@ func (op *assignOp) exec(fm *Frame) Exception {
|
|||
for i, variable := range variables {
|
||||
err := variable.Set(values[i])
|
||||
if err != nil {
|
||||
return fm.errorp(op, err)
|
||||
return fm.errorp(op.lhs.lvalues[i], err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -137,18 +137,18 @@ func (op *assignOp) exec(fm *Frame) Exception {
|
|||
for i := 0; i < rest; i++ {
|
||||
err := variables[i].Set(values[i])
|
||||
if err != nil {
|
||||
return fm.errorp(op, err)
|
||||
return fm.errorp(op.lhs.lvalues[i], err)
|
||||
}
|
||||
}
|
||||
restOff := len(values) - len(variables)
|
||||
err := variables[rest].Set(vals.MakeList(values[rest : rest+restOff+1]...))
|
||||
if err != nil {
|
||||
return fm.errorp(op, err)
|
||||
return fm.errorp(op.lhs.lvalues[rest], err)
|
||||
}
|
||||
for i := rest + 1; i < len(variables); i++ {
|
||||
err := variables[i].Set(values[i+restOff])
|
||||
if err != nil {
|
||||
return fm.errorp(op, err)
|
||||
return fm.errorp(op.lhs.lvalues[i], err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,6 @@ func TestNs(t *testing.T) {
|
|||
|
||||
func TestBuiltinFunctionsReadOnly(t *testing.T) {
|
||||
Test(t,
|
||||
That("return~ = { }").Throws(vars.ErrSetReadOnlyVar, "return~ = { }"),
|
||||
That("return~ = { }").Throws(vars.ErrSetReadOnlyVar, "return~"),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestBuiltinPwd(t *testing.T) {
|
|||
|
||||
Test(t,
|
||||
That(`pwd=dir1 put $pwd; put $pwd`).Puts(dir1, tmpHome),
|
||||
That(`pwd=(float64 1) put $pwd`).Throws(vars.ErrPathMustBeString, "pwd=(float64 1)"),
|
||||
That(`pwd=(float64 1) put $pwd`).Throws(vars.ErrPathMustBeString, "pwd"),
|
||||
)
|
||||
|
||||
// We could separate these two test variants into separate unit test
|
||||
|
|
Loading…
Reference in New Issue
Block a user