]> 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, 27 Nov 2018 13:26:37 +0000 (14:26 +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 61ad4bbb8ac76e82e1972d388487e123a4703d2a..919f958423aea77780a5d065d087abce428eb818 100644 (file)
@@ -348,6 +348,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 904311d54261a2a8c441011efa980d33ead825a3..3674b5c45a6af2e50d73c265ddc4e54940c381be 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.has_type_arguments ()) {
                        Report.warning (_data_type.source_reference, "Type argument list has no effect");
                }