test(aot): 添加闭包和自类型测试用例

- 添加 closure-002.phpt 测试闭包中 use 语法的功能
- 添加 func-self-type.phpt 测试 self 类型提示的功能
- 修改 gen_stub.php 中 self 类型处理逻辑
- 为 ClassInfo 类添加当前类名静态属性
- 更新类解析时设置当前类名信息
pull/1/head
韩天峰 6 months ago
parent dd46d6fa5f
commit 6a9b75d91f
  1. 4
      bin/gen_stub.php
  2. 38
      tests/aot/closure-002.phpt
  3. 23
      tests/aot/func-self-type.phpt

@ -228,7 +228,7 @@ class SimpleType {
}
if ($node->toLowerString() === 'self') {
throw new Exception('The exact class name must be used instead of "self"');
return new SimpleType(ClassInfo::$currentClassName, false);
}
assert($node->isFullyQualified());
@ -3455,6 +3455,7 @@ class AttributeInfo {
class ClassInfo {
static public ?self $currentClass = null;
static public ?string $currentClassName = null;
public /* readonly */ Name $name;
private int $flags;
public string $type;
@ -4444,6 +4445,7 @@ class FileInfo {
if ($stmt instanceof Stmt\ClassLike) {
$className = $stmt->namespacedName;
ClassInfo::$currentClassName = $className->toString();
$constInfos = [];
$propertyInfos = [];
$methodInfos = [];

@ -0,0 +1,38 @@
--TEST--
closure 001
--FILE--
<?php
function main()
{
$a = 100;
$b = [1, 2, 3];
$fn = function ($x) use ($a, &$b) {
var_dump($a);
var_dump($b);
var_dump($x);
$b = [4, 5, 6];
};
$fn(1000);
var_dump($b);
}
?>
--EXPECT--
int(100)
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
int(1000)
array(3) {
[0]=>
int(4)
[1]=>
int(5)
[2]=>
int(6)
}

@ -0,0 +1,23 @@
--TEST--
static calls
--FILE--
<?php
namespace Foo {
class Stream
{
public function pipe(self $stream): void
{
var_dump(get_class($stream));
}
}
}
namespace {
function main() {
$stream1 = new Foo\Stream();
$stream2 = new Foo\Stream();
$stream1->pipe($stream2);
}
}
?>
--EXPECT--
string(10) "Foo\Stream"
Loading…
Cancel
Save