]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Report error when using yield expressions outside async methods
authorJürg Billeter <j@bitron.ch>
Mon, 14 Sep 2009 10:00:10 +0000 (12:00 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 14 Sep 2009 10:00:10 +0000 (12:00 +0200)
vala/valamethodcall.vala

index ba2b6d94743845831215d0c9d97b1390ddb5a7e8..d9e9681bca3ed141dfc926e89d439f785bbe8bd3 100644 (file)
@@ -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;