diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-07-20 10:37:53 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-07-21 15:39:06 +0200 |
commit | 74379748db1893b58452042a29d5addd0c601457 (patch) | |
tree | b3c5f7168084d68fb1f23676c93048024cf68b68 | |
parent | 16197143edcc3479cb04cb7034cb2a2ec4242119 (diff) | |
download | vala-74379748db1893b58452042a29d5addd0c601457.tar.gz |
vala: Improve check of expression passed to yield
Report a proper error and fix codegen cricical when a signal is given:
vala_ccode_function_add_expression: assertion 'expression != NULL' failed
See https://gitlab.gnome.org/GNOME/vala/issues/1039
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/semantic/yield-call-requires-async-method-2.test | 12 | ||||
-rw-r--r-- | vala/valamethodcall.vala | 22 |
3 files changed, 24 insertions, 11 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index d40ee5ede..8e790984b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -948,6 +948,7 @@ TESTS = \ semantic/unary-unsupported-negation.test \ semantic/yield-call-requires-async-context.test \ semantic/yield-call-requires-async-method.test \ + semantic/yield-call-requires-async-method-2.test \ semantic/yield-creation-requires-async-context.test \ semantic/yield-creation-requires-async-method.test \ semantic/yield-statement-requires-async-context.test \ diff --git a/tests/semantic/yield-call-requires-async-method-2.test b/tests/semantic/yield-call-requires-async-method-2.test new file mode 100644 index 000000000..f3d1fe67d --- /dev/null +++ b/tests/semantic/yield-call-requires-async-method-2.test @@ -0,0 +1,12 @@ +Invalid Code + +class Foo { + signal void bar (); + + void run () { + yield bar (); + } +} + +void main () { +} diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index 2416e5b9f..4da21c265 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -510,19 +510,19 @@ public class Vala.MethodCall : Expression { formal_value_type = ret_type.copy (); value_type = formal_value_type.get_actual_type (target_object_type, method_type_args, this); - if (mtype is MethodType) { - unowned Method m = ((MethodType) mtype).method_symbol; - if (is_yield_expression) { - if (!m.coroutine) { - error = true; - Report.error (source_reference, "yield expression requires async method"); - } - if (context.analyzer.current_method == null || !context.analyzer.current_method.coroutine) { - error = true; - Report.error (source_reference, "yield expression not available outside async method"); - } + if (is_yield_expression) { + if (!(mtype is MethodType) || !((MethodType) mtype).method_symbol.coroutine) { + error = true; + Report.error (source_reference, "yield expression requires async method"); + } + if (context.analyzer.current_method == null || !context.analyzer.current_method.coroutine) { + error = true; + Report.error (source_reference, "yield expression not available outside async method"); } + } + if (mtype is MethodType) { + unowned Method m = ((MethodType) mtype).method_symbol; if (m.returns_floating_reference) { value_type.floating_reference = true; } |