Fix a bug for continuations-from-closures that need a local $this
If a continuation in a closure needed a $this variable, hhir would fail to initialize it, resulting in reads reporting null. This didn't come up much, because usually we dont need a variable; we can typically use This or BareThis. Its only cases where $this might be passed by reference, or there are dynamic variables that actually require a local $this.
Esse commit está contido em:
@@ -1026,7 +1026,7 @@ void HhbcTranslator::emitCreateCont(bool getArgs,
|
||||
mapContParams(params, origFunc, genFunc)) {
|
||||
static auto const thisStr = StringData::GetStaticString("this");
|
||||
Id thisId = kInvalidId;
|
||||
const bool fillThis = origFunc->isNonClosureMethod() &&
|
||||
const bool fillThis = origFunc->isMethod() &&
|
||||
!origFunc->isStatic() &&
|
||||
((thisId = genFunc->lookupVarId(thisStr)) != kInvalidId) &&
|
||||
(origFunc->lookupVarId(thisStr) == kInvalidId);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
class X {
|
||||
function gen($fn) {
|
||||
return function() use ($fn) {
|
||||
yield $fn($this);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function test() {
|
||||
$x = new X;
|
||||
$f = $x->gen(function($x) { var_dump(get_class($x)); });
|
||||
foreach ($f() as $e) {
|
||||
var_dump($e);
|
||||
}
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
function fiz($x) { return false; }
|
||||
@@ -0,0 +1,2 @@
|
||||
string(1) "X"
|
||||
NULL
|
||||
Referência em uma Nova Issue
Bloquear um usuário