Skip to content

Commit

Permalink
Fix class function parameter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Oct 22, 2018
1 parent 2a6f9d6 commit c595bba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions source/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -40,7 +40,7 @@ function closure($ast) {
continue;
}

if (isset($defined[$name]) || isset($pushed[$name])) {
if (($isClosure && isset($defined[$name])) || isset($pushed[$name])) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions source/macros.yay
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions tests/specs/async.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
});
}
Expand Down

0 comments on commit c595bba

Please sign in to comment.