summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-03-14 09:16:51 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-03-17 19:40:19 +0100
commitd19187f3b5f7bdc99bba2c9a856f51af9e8cd520 (patch)
tree256fad50ce9d950f75bbf17e968950d43d61c00a
parent2caef4facc1da5c390b94fa11ae52f51d6fc8d6d (diff)
downloadvala-d19187f3b5f7bdc99bba2c9a856f51af9e8cd520.tar.gz
vala: Report error for yield statements without async context
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/semantic/yield-statement-requires-async-context.test5
-rw-r--r--vala/valayieldstatement.vala15
3 files changed, 21 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 41481e7e8..f0000a94b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -715,6 +715,7 @@ TESTS = \
semantic/yield-call-requires-async-method.test \
semantic/yield-creation-requires-async-context.test \
semantic/yield-creation-requires-async-method.test \
+ semantic/yield-statement-requires-async-context.test \
$(NULL)
NON_NULL_TESTS = \
diff --git a/tests/semantic/yield-statement-requires-async-context.test b/tests/semantic/yield-statement-requires-async-context.test
new file mode 100644
index 000000000..8dd03950b
--- /dev/null
+++ b/tests/semantic/yield-statement-requires-async-context.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+ yield;
+}
diff --git a/vala/valayieldstatement.vala b/vala/valayieldstatement.vala
index 795de2761..91d8e7f9f 100644
--- a/vala/valayieldstatement.vala
+++ b/vala/valayieldstatement.vala
@@ -35,6 +35,21 @@ public class Vala.YieldStatement : CodeNode, Statement {
this.source_reference = source_reference;
}
+ public override bool check (CodeContext context) {
+ if (checked) {
+ return !error;
+ }
+
+ checked = true;
+
+ if (context.analyzer.current_method == null || !context.analyzer.current_method.coroutine) {
+ error = true;
+ Report.error (source_reference, "yield statement not available outside async method");
+ }
+
+ return !error;
+ }
+
public override void emit (CodeGenerator codegen) {
codegen.visit_yield_statement (this);
}