diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-03-14 09:16:51 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-03-17 19:40:19 +0100 |
commit | d19187f3b5f7bdc99bba2c9a856f51af9e8cd520 (patch) | |
tree | 256fad50ce9d950f75bbf17e968950d43d61c00a | |
parent | 2caef4facc1da5c390b94fa11ae52f51d6fc8d6d (diff) | |
download | vala-d19187f3b5f7bdc99bba2c9a856f51af9e8cd520.tar.gz |
vala: Report error for yield statements without async context
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/semantic/yield-statement-requires-async-context.test | 5 | ||||
-rw-r--r-- | vala/valayieldstatement.vala | 15 |
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); } |