[vala/wip/issue/781] 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/wip/issue/781] codegen: Always assign original variable when consuming instance to destroy
- Date: Mon, 8 Apr 2019 08:10:26 +0000 (UTC)
commit c6afcf7840995adf1f05d4ee5d31c560414b8c54
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 | 35 ++++++++++++++++++++++++++++-
2 files changed, 51 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..3a2a6c194 100644
--- a/tests/objects/compact-class-destructor.vala
+++ b/tests/objects/compact-class-destructor.vala
@@ -9,9 +9,42 @@ 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 main () {
+ field ();
+ local ();
+ parameter (new Foo ());
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]