From: Rico Tzschichholz Date: Tue, 27 Nov 2018 13:24:03 +0000 (+0100) Subject: vala: Type check for errors require an error expression X-Git-Tag: 0.43.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2682b111fd69228b6a91b64065b3b26c684f3b3;p=thirdparty%2Fvala.git vala: Type check for errors require an error expression Fixes https://gitlab.gnome.org/GNOME/vala/issues/362 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 61ad4bbb8..919f95842 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 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 904311d54..3674b5c45 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.has_type_arguments ()) { Report.warning (_data_type.source_reference, "Type argument list has no effect"); }