[vala] Report error when using yield expressions outside async methods



commit 2f6139bc7f5ac2e767c9f1a8fed92ed2bd6dc0fa
Author: Jürg Billeter <j bitron ch>
Date:   Mon Sep 14 12:00:10 2009 +0200

    Report error when using yield expressions outside async methods

 vala/valamethodcall.vala |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index ba2b6d9..d9e9681 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -419,9 +419,15 @@ public class Vala.MethodCall : Expression {
 
 		if (mtype is MethodType) {
 			var m = ((MethodType) mtype).method_symbol;
-			if (is_yield_expression && !m.coroutine) {
-				error = true;
-				Report.error (source_reference, "yield expression requires async method");
+			if (is_yield_expression) {
+				if (!m.coroutine) {
+					error = true;
+					Report.error (source_reference, "yield expression requires async method");
+				}
+				if (analyzer.current_method == null || !analyzer.current_method.coroutine) {
+					error = true;
+					Report.error (source_reference, "yield expression not available outside async method");
+				}
 			}
 			foreach (DataType error_type in m.get_error_types ()) {
 				may_throw = true;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]