]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Report a warning for unhandled errors in destructors
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 24 Apr 2021 07:11:27 +0000 (09:11 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 24 Apr 2021 07:14:58 +0000 (09:14 +0200)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1176

tests/Makefile.am
tests/errors/unhandled.vala [new file with mode: 0644]
vala/valadestructor.vala

index f409da1afb62c673349cf96460aa51db08aefccf..684546e44868796e2cd6b20b79c3bb246027307b 100644 (file)
@@ -613,6 +613,7 @@ TESTS = \
        errors/invalid-type-check.test \
        errors/loops.vala \
        errors/method-throws.vala \
+       errors/unhandled.vala \
        errors/bug567181.vala \
        errors/bug579101.vala \
        errors/bug596228.vala \
diff --git a/tests/errors/unhandled.vala b/tests/errors/unhandled.vala
new file mode 100644 (file)
index 0000000..1a3768a
--- /dev/null
@@ -0,0 +1,45 @@
+public errordomain FooError {
+       FAIL
+}
+
+public class Foo : Object {
+       public string bar {
+               get {
+                       throw new FooError.FAIL ("property getter");
+               }
+               set {
+                       throw new FooError.FAIL ("property setter");
+               }
+       }
+
+       public Foo () {
+               throw new FooError.FAIL ("creation method");
+       }
+
+       construct {
+               throw new FooError.FAIL ("constructor");
+       }
+
+       class construct {
+               throw new FooError.FAIL ("class constructor");
+       }
+
+       static construct {
+               throw new FooError.FAIL ("static constructor");
+       }
+
+       ~Foo () {
+               throw new FooError.FAIL ("destructor");
+       }
+
+       class ~Foo () {
+               throw new FooError.FAIL ("class destructor");
+       }
+
+       public void foo () {
+               throw new FooError.FAIL ("method");
+       }
+}
+
+void main () {
+}
index f363fee1b81b9cca0396053199faeb55bf96a7a4..d036801d59ccf91e396882040c845b7715c959e4 100644 (file)
@@ -78,6 +78,16 @@ public class Vala.Destructor : Subroutine {
                        body.check (context);
                }
 
+               if (body != null && !body.error) {
+                       var body_errors = new ArrayList<DataType> ();
+                       body.get_error_types (body_errors);
+                       foreach (DataType body_error_type in body_errors) {
+                               if (!((ErrorType) body_error_type).dynamic_error) {
+                                       Report.warning (body_error_type.source_reference, "unhandled error `%s'", body_error_type.to_string());
+                               }
+                       }
+               }
+
                context.analyzer.current_symbol = old_symbol;
 
                return !error;