From c595bba6249ef92c03904e9987fc70a0176df1f3 Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Mon, 22 Oct 2018 19:45:47 +0200 Subject: [PATCH] Fix class function parameter bug --- source/functions.php | 4 ++-- source/macros.yay | 4 ++-- tests/specs/async.spec | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/functions.php b/source/functions.php index 8bbf477..d397675 100644 --- a/source/functions.php +++ b/source/functions.php @@ -4,7 +4,7 @@ use Yay\Ast; -function closure($ast) { +function compile($ast, $isClosure = true) { if (function_exists("\\Amp\\resolve")) { $append = new Ast("amp1"); $append->push(new Ast()); @@ -40,7 +40,7 @@ function closure($ast) { continue; } - if (isset($defined[$name]) || isset($pushed[$name])) { + if (($isClosure && isset($defined[$name])) || isset($pushed[$name])) { continue; } diff --git a/source/macros.yay b/source/macros.yay index e71b839..b8870b1 100644 --- a/source/macros.yay +++ b/source/macros.yay @@ -41,7 +41,7 @@ $(macro :recursion) { _() as amp2 )) } >> function($ast) { - return \Pre\Async\closure($ast); + return \Pre\Async\compile($ast, $isClosure = false); } >> {$$(trim( $(scope ? { $$(functionModifiers($(functionModifiers))) function $(function)($(functionArguments ... (, ) { $$(functionArgument($(functionArgument))) })): \Amp\Promise @@ -88,7 +88,7 @@ $(macro :recursion) { _() as amp2 )) } >> function($ast) { - return \Pre\Async\closure($ast); + return \Pre\Async\compile($ast, $isClosure = true); } >> {$$(trim( $(scope ? { [$(scope ... (, ) { $(var) = $(var) ?? null}), "fn" => function ($(functionArguments ... (, ) { $$(functionArgument($(functionArgument))) })) use ($(scope ... (, ) { &$(var) })): \Amp\Promise { diff --git a/tests/specs/async.spec b/tests/specs/async.spec index 6ae8580..2225521 100644 --- a/tests/specs/async.spec +++ b/tests/specs/async.spec @@ -23,9 +23,9 @@ class AsyncClass await \Amp\File\get("path/to/file"); } - async public function second() + async public function second($terminator = "!") { - return "boo!"; + return "boo{$terminator}"; } async public static function complex(): string @@ -45,10 +45,10 @@ class AsyncClass }); } - public function second(): \Amp\Promise + public function second($terminator = "!"): \Amp\Promise { - return \Amp\call(function () { - return "boo!"; + return \Amp\call(function () use (&$terminator) { + return "boo{$terminator}"; yield; }); }