[vala/staging] vala: Switch context if with-variable is not owned by with-statement ifself
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Switch context if with-variable is not owned by with-statement ifself
- Date: Thu, 6 Aug 2020 17:08:40 +0000 (UTC)
commit b2746b9c3a2edc17ae7d27b30123fe0aeec52f82
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Aug 6 11:09:52 2020 +0200
vala: Switch context if with-variable is not owned by with-statement ifself
See https://gitlab.gnome.org/GNOME/vala/issues/1043
tests/Makefile.am | 1 +
tests/objects/with-nested-method.vala | 24 ++++++++++++++++++++++++
vala/valamemberaccess.vala | 9 ++++++++-
3 files changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 984266210..8c857cb81 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 \
diff --git a/tests/objects/with-nested-method.vala b/tests/objects/with-nested-method.vala
new file mode 100644
index 000000000..c3796ac4f
--- /dev/null
+++ b/tests/objects/with-nested-method.vala
@@ -0,0 +1,24 @@
+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);
+ }
+ }
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 454d856b9..d61e2f3fe 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -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;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]