[vala/0.52] codegen: Add missing "_return" label and "_inner_error*_" declaration in dtors



commit 82b3a9013001cebc8b64d6dfce20a413f319c431
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Apr 24 09:11:27 2021 +0200

    codegen: Add missing "_return" label and "_inner_error*_" declaration in dtors

 codegen/valagtypemodule.vala   | 20 ++++++++++++++++++++
 tests/objects/destructors.vala |  8 ++++++++
 2 files changed, 28 insertions(+)
---
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 1a0e0d1b3..1fea214bb 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1710,6 +1710,16 @@ public class Vala.GTypeModule : GErrorModule {
 
                if (cl.static_destructor != null) {
                        cl.static_destructor.body.emit (this);
+
+                       if (current_method_inner_error) {
+                               ccode.add_declaration ("GError*", new CCodeVariableDeclarator.zero 
("_inner_error%d_".printf (current_inner_error_id), new CCodeConstant ("NULL")));
+                       }
+
+                       if (current_method_return) {
+                               // support return statements in destructors
+                               ccode.add_label ("_return");
+                               ccode.add_statement (new CCodeEmptyStatement ());
+                       }
                }
 
                pop_context ();
@@ -1733,6 +1743,16 @@ public class Vala.GTypeModule : GErrorModule {
 
                if (cl.class_destructor != null) {
                        cl.class_destructor.body.emit (this);
+
+                       if (current_method_inner_error) {
+                               ccode.add_declaration ("GError*", new CCodeVariableDeclarator.zero 
("_inner_error%d_".printf (current_inner_error_id), new CCodeConstant ("NULL")));
+                       }
+
+                       if (current_method_return) {
+                               // support return statements in destructors
+                               ccode.add_label ("_return");
+                               ccode.add_statement (new CCodeEmptyStatement ());
+                       }
                }
 
                pop_context ();
diff --git a/tests/objects/destructors.vala b/tests/objects/destructors.vala
index 7a99f83fd..3745b3cca 100644
--- a/tests/objects/destructors.vala
+++ b/tests/objects/destructors.vala
@@ -34,6 +34,14 @@ class Manam : Object {
                }
                assert_not_reached ();
        }
+
+       class ~Manam () {
+               bool b = true;
+               if (b) {
+                       return;
+               }
+               assert_not_reached ();
+       }
 }
 
 void main () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]