]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Type check for errors require an error expression
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 27 Nov 2018 13:24:03 +0000 (14:24 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 4 Dec 2018 12:17:04 +0000 (13:17 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/362

tests/Makefile.am
tests/errors/invalid-type-check.test [new file with mode: 0644]
vala/valatypecheck.vala

index b049a9566a968d599723d9e55c5eb698ccae2b6e..e2d6ca276f5c9cf62cca771b28b0026ab5fe8739 100644 (file)
@@ -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 (file)
index 0000000..b57f6b6
--- /dev/null
@@ -0,0 +1,12 @@
+Invalid Code
+
+errordomain FooError {
+       FAIL;
+}
+
+void main () {
+       Object? e = null;
+
+       if (e is FooError) {
+       }
+}
index cb0469a6fcffb6d35011ee3a59e8ff98e163b631..3ea9e7732225d463f14a80e6c7f765f3f4326dc0 100644 (file)
@@ -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");
                }