[vala/staging] codegen: Always assign original variable when consuming instance to destroy
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Always assign original variable when consuming instance to destroy
- Date: Mon, 8 Apr 2019 08:26:23 +0000 (UTC)
commit f3db80052c9f0031b618136d2d949b9dfc661735
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Apr 8 10:00:19 2019 +0200
codegen: Always assign original variable when consuming instance to destroy
Fixes https://gitlab.gnome.org/GNOME/vala/issues/781
codegen/valaccodebasemodule.vala | 18 +++++++++++-
tests/objects/compact-class-destructor.vala | 44 ++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7ce434783..18418a949 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4069,9 +4069,25 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
expr.target_value.value_type = expr.value_type;
if (is_compact_class_destructor_call (expr)) {
+ // FIXME This is awful https://gitlab.gnome.org/GNOME/vala/issues/781
+ CCodeExpression cexpr;
+ unowned Variable? variable = expr.symbol_reference as Variable;
+ if (variable != null) {
+ if (variable is LocalVariable) {
+ cexpr = get_local_cexpression ((LocalVariable)
variable);
+ } else if (variable is Parameter) {
+ cexpr = get_parameter_cexpression ((Parameter)
variable);
+ } else if (variable is Field) {
+ cexpr = get_cexpression (get_ccode_name (variable));
+ } else {
+ cexpr = new CCodeInvalidExpression ();
+ }
+ } else {
+ cexpr = get_cvalue (expr);
+ }
// transfer ownership here and consume given instance
var temp_value = store_temp_value (expr.target_value, expr);
- ccode.add_assignment (get_cvalue (expr), new CCodeConstant ("NULL"));
+ ccode.add_assignment (cexpr, new CCodeConstant ("NULL"));
expr.target_value = temp_value;
} else {
expr.target_value = transform_value (expr.target_value,
expr.target_type, expr);
diff --git a/tests/objects/compact-class-destructor.vala b/tests/objects/compact-class-destructor.vala
index 2d6d8a442..5f95b8b1b 100644
--- a/tests/objects/compact-class-destructor.vala
+++ b/tests/objects/compact-class-destructor.vala
@@ -9,9 +9,51 @@ class Foo {
}
}
-void main () {
+Foo faz;
+
+void bar () throws Error {
+}
+
+void field () {
+ bar ();
+
+ faz = new Foo ();
+ var res = faz.destroy ();
+
+ assert (faz == null);
+ assert (res == 42);
+}
+
+void local () {
+ bar ();
+
+ var foo = new Foo ();
+ var res = foo.destroy ();
+
+ assert (foo == null);
+ assert (res == 42);
+}
+
+void parameter (owned Foo foo) {
+ bar ();
+
+ var res = foo.destroy ();
+
+ assert (foo == null);
+ assert (res == 42);
+}
+
+void simple () {
var foo = new Foo ();
var res = foo.destroy ();
+
assert (foo == null);
assert (res == 42);
}
+
+void main () {
+ simple ();
+ field ();
+ local ();
+ parameter (new Foo ());
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]