Perform lookups from obj locals with right sb

When object fields are evaluated the locals from the object
are added to the environment. These locals should have the same
environment as the field, in particular they should be
at the same inheritance level. Instead they were evaluated as if
they were on the level from which original field lookup was performed,
resulting in subtle and hard to debug issues.
This commit is contained in:
Stanisław Barzowski 2019-05-10 12:59:38 +02:00
parent 83ed0b939f
commit 591b119591
7 changed files with 34 additions and 1 deletions

3
testdata/obj_local_right_level.golden vendored Normal file
View File

@ -0,0 +1,3 @@
{
"bar": 1
}

View File

@ -0,0 +1,6 @@
{
bar: 0
} + {
local foo = super.bar + 1,
bar: foo
} + {} + {} + {}

View File

@ -0,0 +1,4 @@
{
"answer": "right",
"bar": "right"
}

View File

@ -0,0 +1,7 @@
{
local foo = self.bar,
bar: "wrong",
answer: foo
} + {
bar: "right"
}

View File

@ -0,0 +1,4 @@
{
"answer": "right",
"bar": "wrong2"
}

View File

@ -0,0 +1,9 @@
{
bar: "right",
} + {
local foo = super.bar,
bar: "wrong1",
answer: foo,
} + {
bar: "wrong2"
}

View File

@ -648,7 +648,7 @@ func objectIndex(i *interpreter, trace TraceElement, sb selfBinding, fieldName s
}
fieldSelfBinding := selfBinding{self: sb.self, superDepth: foundAt}
fieldUpValues := prepareFieldUpvalues(sb, upValues, locals)
fieldUpValues := prepareFieldUpvalues(fieldSelfBinding, upValues, locals)
return field.field.evaluate(i, trace, fieldSelfBinding, fieldUpValues, fieldName)
}