diff --git a/hphp/hack/src/parser/lowerer/desugar_expression_tree.rs b/hphp/hack/src/parser/lowerer/desugar_expression_tree.rs index 669a1063bdc8a3..7665c8da9e9fc1 100644 --- a/hphp/hack/src/parser/lowerer/desugar_expression_tree.rs +++ b/hphp/hack/src/parser/lowerer/desugar_expression_tree.rs @@ -1609,6 +1609,11 @@ impl RewriteState { )); unchanged_result } + Yield(_) => { + self.errors + .push((pos, "`yield` is not supported in expression trees.".into())); + unchanged_result + } _ => { self.errors .push((pos, "Unsupported expression tree syntax.".into())); diff --git a/hphp/hack/src/parser/lowerer/lowerer.rs b/hphp/hack/src/parser/lowerer/lowerer.rs index e4fdbfc79e8bba..1a69b422a8377c 100644 --- a/hphp/hack/src/parser/lowerer/lowerer.rs +++ b/hphp/hack/src/parser/lowerer/lowerer.rs @@ -187,7 +187,7 @@ pub struct Env<'a> { pub empty_ns_env: Arc, // Whether we have encountered an yield expression - pub found_yield: bool, + found_yield: bool, // Whether we have encountered an await expression found_await: bool, // Whether we are in the body of an async function @@ -2377,8 +2377,7 @@ fn p_prefixed_code_expr<'a>( let pos = p_pos(&c.body, env); let suspension_kind = SuspensionKind::SKSync; // Take the body and create a no argument lambda expression - let (body, yield_) = - env.reset_for_function_body(&c.body, suspension_kind, p_function_body)?; + let body = p_function_body(&c.body, env)?; let external = c.body.is_external(); let fun = ast::Fun_ { span: pos.clone(), @@ -2387,7 +2386,7 @@ fn p_prefixed_code_expr<'a>( readonly_ret: None, ret: ast::TypeHint((), None), body: ast::FuncBody { fb_ast: body }, - fun_kind: mk_fun_kind(suspension_kind, yield_), + fun_kind: mk_fun_kind(suspension_kind, false), params: vec![], ctxs: None, unsafe_ctxs: None, diff --git a/hphp/hack/test/typecheck/expression_trees/async_generator.php.exp b/hphp/hack/test/typecheck/expression_trees/async_generator.php.exp index 7018920d92dbdf..1edc5b11ce62fb 100644 --- a/hphp/hack/test/typecheck/expression_trees/async_generator.php.exp +++ b/hphp/hack/test/typecheck/expression_trees/async_generator.php.exp @@ -3,7 +3,7 @@ Internal error: Return type is not a generator (Other[0000]) ERROR: File "async_generator.php", line 6, characters 14-38: Expression trees only support simple lambdas, without features like `async`, generators or capabilities. (Parsing[1002]) ERROR: File "async_generator.php", line 6, characters 29-35: -Unsupported expression tree syntax. (Parsing[1002]) +`yield` is not supported in expression trees. (Parsing[1002]) ERROR: File "async_generator.php", line 6, characters 14-38: You cannot return a value in a generator (a generator is a function that uses `yield`) (NastCheck[3019]) ERROR: File "async_generator.php", line 6, characters 14-38: diff --git a/hphp/hack/test/typecheck/expression_trees/generator.php.exp b/hphp/hack/test/typecheck/expression_trees/generator.php.exp index f56342aa6599b3..7b5be27c9b7fce 100644 --- a/hphp/hack/test/typecheck/expression_trees/generator.php.exp +++ b/hphp/hack/test/typecheck/expression_trees/generator.php.exp @@ -3,7 +3,7 @@ Internal error: Return type is not a generator (Other[0000]) ERROR: File "generator.php", line 6, characters 14-32: Expression trees only support simple lambdas, without features like `async`, generators or capabilities. (Parsing[1002]) ERROR: File "generator.php", line 6, characters 23-29: -Unsupported expression tree syntax. (Parsing[1002]) +`yield` is not supported in expression trees. (Parsing[1002]) ERROR: File "generator.php", line 6, characters 14-32: You cannot return a value in a generator (a generator is a function that uses `yield`) (NastCheck[3019]) ERROR: File "generator.php", line 6, characters 14-32: diff --git a/hphp/hack/test/typecheck/expression_trees/nesting/await.php b/hphp/hack/test/typecheck/expression_trees/nesting/await.php new file mode 100644 index 00000000000000..b7cd81d79d3e78 --- /dev/null +++ b/hphp/hack/test/typecheck/expression_trees/nesting/await.php @@ -0,0 +1,33 @@ +> + +async function g(): Awaitable> { + return ExampleDsl`1`; +} + +async function f(): Awaitable { + ExampleDsl`${ExampleDsl`${await g()}`}`; + ExampleDsl`{ + ${await g()}; + }`; + ExampleDsl`${ + ExampleDsl`{ + 1; + ${await g()}; + }` + }`; + ExampleDsl`{ + ${ExampleDsl`${await g()}`}; + }`; + ExampleDsl`{ + ${await g()}; + ${ExampleDsl`${await g()}`}; + }`; + ExampleDsl`{ + ${ + ExampleDsl`{ + ${await g()}; + }` + }; + }`; +} diff --git a/hphp/hack/test/typecheck/expression_trees/nesting/await.php.exp b/hphp/hack/test/typecheck/expression_trees/nesting/await.php.exp new file mode 100644 index 00000000000000..4269126fcebc19 --- /dev/null +++ b/hphp/hack/test/typecheck/expression_trees/nesting/await.php.exp @@ -0,0 +1 @@ +No errors diff --git a/hphp/test/slow/expression_trees/blocks_yield.php.expectf b/hphp/test/slow/expression_trees/blocks_yield.php.expectf index 80cc13569fa5e2..89dd3bd729a860 100644 --- a/hphp/test/slow/expression_trees/blocks_yield.php.expectf +++ b/hphp/test/slow/expression_trees/blocks_yield.php.expectf @@ -1 +1 @@ -Fatal error: Expression trees only support simple lambdas, without features like `async`, generators or capabilities. in %s/blocks_yield.php on line 14 +Fatal error: `yield` is not supported in expression trees. in %s/blocks_yield.php on line 12