From fb4ddde169b7b80b6bd1ddb73b20d420e7b39160 Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Thu, 20 Feb 2020 14:19:10 +0100 Subject: [PATCH] vala: Bail ThrowStatement.get_error_types() if error is set This caused criticals when error_expression is not correct. --- tests/Makefile.am | 1 + tests/semantic/throw-unknown-error-type.test | 14 ++++++++++++++ vala/valathrowstatement.vala | 3 +++ 3 files changed, 18 insertions(+) create mode 100644 tests/semantic/throw-unknown-error-type.test diff --git a/tests/Makefile.am b/tests/Makefile.am index d4e365353..9d54c2ea0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -874,6 +874,7 @@ TESTS = \ semantic/switch-label-not-constant.test \ semantic/switch-type-unsupported.test \ semantic/throw-no-error-type.test \ + semantic/throw-unknown-error-type.test \ semantic/type-argument-ownership-mismatch.test \ semantic/unary-unsupported-complement.test \ semantic/unary-unsupported-increment.test \ diff --git a/tests/semantic/throw-unknown-error-type.test b/tests/semantic/throw-unknown-error-type.test new file mode 100644 index 000000000..40834e8c2 --- /dev/null +++ b/tests/semantic/throw-unknown-error-type.test @@ -0,0 +1,14 @@ +Invalid Code + +void foo () throws Error { + int bar = 1; + switch (bar) { + case 0: + break; + default: + throw new FooError.FAIL (""); + } +} + +void main () { +} diff --git a/vala/valathrowstatement.vala b/vala/valathrowstatement.vala index 9349b1818..4ba347a9b 100644 --- a/vala/valathrowstatement.vala +++ b/vala/valathrowstatement.vala @@ -73,6 +73,9 @@ public class Vala.ThrowStatement : CodeNode, Statement { } public override void get_error_types (Collection collection, SourceReference? source_reference = null) { + if (error) { + return; + } if (source_reference == null) { source_reference = this.source_reference; } -- 2.47.3