[vala/0.42] vala: Type check for errors require an error expression



commit abffaa62d026cd859ba89c22566e15abfcc1cdcd
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Nov 27 14:24:03 2018 +0100

    vala: Type check for errors require an error expression
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/362

 tests/Makefile.am                    |  1 +
 tests/errors/invalid-type-check.test | 12 ++++++++++++
 vala/valatypecheck.vala              |  6 ++++++
 3 files changed, 19 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b049a9566..e2d6ca276 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -346,6 +346,7 @@ TESTS = \
        errors/catch-error-code.vala \
        errors/errors.vala \
        errors/errordomain.vala \
+       errors/invalid-type-check.test \
        errors/method-throws.vala \
        errors/bug567181.vala \
        errors/bug579101.vala \
diff --git a/tests/errors/invalid-type-check.test b/tests/errors/invalid-type-check.test
new file mode 100644
index 000000000..b57f6b62b
--- /dev/null
+++ b/tests/errors/invalid-type-check.test
@@ -0,0 +1,12 @@
+Invalid Code
+
+errordomain FooError {
+       FAIL;
+}
+
+void main () {
+       Object? e = null;
+
+       if (e is FooError) {
+       }
+}
diff --git a/vala/valatypecheck.vala b/vala/valatypecheck.vala
index cb0469a6f..3ea9e7732 100644
--- a/vala/valatypecheck.vala
+++ b/vala/valatypecheck.vala
@@ -116,6 +116,12 @@ public class Vala.TypeCheck : Expression {
                        return false;
                }
 
+               if (type_reference is ErrorType && !(expression.value_type is ErrorType)) {
+                       Report.error (expression.source_reference, "`%s' must be an error".printf 
(expression.to_string ()));
+                       error = true;
+                       return false;
+               }
+
                if (context.profile == Profile.GOBJECT && type_reference.get_type_arguments ().size > 0) {
                        Report.warning (_data_type.source_reference, "Type argument list has no effect");
                }


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