Skip to content

Commit

Permalink
Support arrow functions returning by reference (ref #2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Nov 7, 2019
1 parent 37dda44 commit 96e69bb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,9 @@ public function isReference($stackPtr)
true
);

if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION
|| $this->tokens[$tokenBefore]['code'] === T_FN
) {
// Function returns a reference.
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ $a = $a instanceof $b;
$a = $a instanceof $b;
$a = ($a)instanceof$b;

fn&($x) => $x;

// phpcs:set Squiz.WhiteSpace.OperatorSpacing ignoreSpacingBeforeAssignments false
$a = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ $a = $a instanceof $b;
$a = $a instanceof $b;
$a = ($a) instanceof $b;

fn&($x) => $x;

// phpcs:set Squiz.WhiteSpace.OperatorSpacing ignoreSpacingBeforeAssignments false
$a = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getErrorList($testFile='OperatorSpacingUnitTest.inc')
246 => 1,
265 => 2,
266 => 2,
269 => 2,
271 => 2,
];
break;
case 'OperatorSpacingUnitTest.js':
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/File/IsReferenceTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ functionCall( $something , &new Foobar() );

/* testUseByReference */
$closure = function() use (&$var){};

/* testArrowFunctionReturnByReference */
fn&($x) => $x;
4 changes: 4 additions & 0 deletions tests/Core/File/IsReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ public function dataIsReference()
'/* testUseByReference */',
true,
],
[
'/* testArrowFunctionReturnByReference */',
true,
],
];

}//end dataIsReference()
Expand Down

0 comments on commit 96e69bb

Please sign in to comment.