[vala/0.40] vala: Improve check of expression passed to yield
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] vala: Improve check of expression passed to yield
- Date: Thu, 30 Jul 2020 11:02:58 +0000 (UTC)
commit 7a2529e63510a0fffa2827a7a11364ec173fca78
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Jul 20 10:37:53 2020 +0200
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
tests/Makefile.am | 1 +
.../yield-call-requires-async-method-2.test | 12 ++++++++++++
vala/valamethodcall.vala | 21 +++++++++++----------
3 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9de3eb472..ff8d228b1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -838,6 +838,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 \
$(NULL)
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 958254ee5..69dba11ce 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -475,20 +475,21 @@ 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 (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");
+ }
+ }
+
bool may_throw = false;
if (mtype is MethodType) {
var 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 (m != null && m.coroutine && !is_yield_expression && ((MemberAccess)
call).member_name != "end") {
// .begin call of async method, no error can happen here
} else {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]