From: Jürg Billeter Date: Mon, 14 Sep 2009 10:00:10 +0000 (+0200) Subject: Report error when using yield expressions outside async methods X-Git-Tag: 0.7.6~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f6139bc7f5ac2e767c9f1a8fed92ed2bd6dc0fa;p=thirdparty%2Fvala.git Report error when using yield expressions outside async methods --- diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index ba2b6d947..d9e9681bc 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;