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



commit 3399db491d83c3466853b33de4c2e219ea0326b4
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 ca9d63e7c..7ab1b2d84 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1706,6 +1706,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 ();
@@ -1729,6 +1739,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]