]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Improve check of expression passed to yield
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 20 Jul 2020 08:37:53 +0000 (10:37 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 20 Jul 2020 08:37:53 +0000 (10:37 +0200)
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
tests/semantic/yield-call-requires-async-method-2.test [new file with mode: 0644]
vala/valamethodcall.vala

index d80ef2ed0217cde92e04fe7b4b8941aa807c7902..c3fb9cfdc17ed01dc08c7ed96a7431aec2cb1184 100644 (file)
@@ -981,6 +981,7 @@ TESTS = \
        semantic/with-value.vala \
        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 (file)
index 0000000..f3d1fe6
--- /dev/null
@@ -0,0 +1,12 @@
+Invalid Code
+
+class Foo {
+       signal void bar ();
+
+       void run () {
+               yield bar ();
+       }
+}
+
+void main () {
+}
index aeacb958a153d195d8f1873f3415808ad5ab204e..d7b58ac8520a05a722db7566d0b9fd156ad0d0ff 100644 (file)
@@ -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;
                        }