Commit a1ea7697 authored by Rico Tzschichholz's avatar Rico Tzschichholz

vala: Switch context if with-variable is not owned by with-statement ifself

See #1043
parent eea1aa38
......@@ -527,6 +527,7 @@ TESTS = \
objects/with-expression.vala \
objects/with-instance.vala \
objects/with-nested.vala \
objects/with-nested-method.vala \
errors/catch-error-code.vala \
errors/catch-in-finally.vala \
errors/default-gtype.vala \
......
class Foo {
public int foo () {
return 23;
}
}
class Bar {
public int foo () {
return 42;
}
}
void main () {
var foo = new Foo ();
var bar = new Bar ();
with (foo) {
assert (foo () == 23);
with (bar) {
assert (foo () == 42);
}
}
}
......@@ -292,7 +292,14 @@ public class Vala.MemberAccess : Expression {
symbol_reference = variable_type.get_member (member_name);
if (symbol_reference != null) {
inner = new MemberAccess (null, w.with_variable.name, source_reference);
inner.check (context);
if (w.with_variable.parent_symbol == w.body) {
inner.check (context);
} else {
var old_symbol = context.analyzer.current_symbol;
context.analyzer.current_symbol = w.parent_symbol;
inner.check (context);
context.analyzer.current_symbol = old_symbol;
}
may_access_instance_members = true;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment