Merge branch 'master' of git.code-galaxy.net:aot/compiler

pull/48/head
韩天峰 2 weeks ago
commit 23e88efb6a
  1. 8
      src/Generator/AnonClassGenerator.php
  2. 17
      tests/compiler/anon_class/005.phpt

@ -177,6 +177,14 @@ trait AnonClassGenerator
$class = $this->classStack[count($this->classStack) - 1] ?? null;
if ($class !== null && $this->compiler->shouldAddMixedReturnToEmbeddedClassMethod($class, $node)) {
$node->returnType = new Identifier('mixed');
// An implicit fallthrough returns null in PHP. Once the
// compatibility return type is made explicit, PHP requires
// an explicit value on that path as well.
if ($node->stmts !== null) {
$node->stmts[] = new Node\Stmt\Return_(
new Node\Expr\ConstFetch(new Name('null')),
);
}
}
}
return null;

@ -14,16 +14,23 @@ namespace AnonymousClassSupport {
function accepts(Subject $value): bool {
return true;
}
class Visitor {
public function inspect(object $value) {
return null;
}
}
}
namespace AnonymousClassConsumer {
use AnonymousClassSupport\Marker as ImportedMarker;
use AnonymousClassSupport\Subject as ImportedSubject;
use AnonymousClassSupport\Visitor as ImportedVisitor;
use const AnonymousClassSupport\FLAG as IMPORTED_FLAG;
use function AnonymousClassSupport\accepts as imported_accepts;
function main(): void {
$visitor = new class('ready') {
$visitor = new class('ready') extends ImportedVisitor {
public function __construct(private readonly string $state) {}
public function accepts(object $value): bool {
@ -33,9 +40,16 @@ namespace AnonymousClassConsumer {
&& imported_accepts($value)
&& $this->state === 'ready';
}
public function inspect(object $value) {
if ($value instanceof ImportedSubject) {
return 'subject';
}
}
};
var_dump($visitor->accepts(new ImportedSubject()));
var_dump($visitor->inspect(new \stdClass()));
}
}
@ -47,3 +61,4 @@ namespace {
?>
--EXPECT--
bool(true)
NULL

Loading…
Cancel
Save