From 6a9b75d91f865d30c209680e65fa2cb4b6975d06 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 13 Mar 2026 15:16:29 +0800 Subject: [PATCH] =?UTF-8?q?test(aot):=20=E6=B7=BB=E5=8A=A0=E9=97=AD?= =?UTF-8?q?=E5=8C=85=E5=92=8C=E8=87=AA=E7=B1=BB=E5=9E=8B=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 closure-002.phpt 测试闭包中 use 语法的功能 - 添加 func-self-type.phpt 测试 self 类型提示的功能 - 修改 gen_stub.php 中 self 类型处理逻辑 - 为 ClassInfo 类添加当前类名静态属性 - 更新类解析时设置当前类名信息 --- bin/gen_stub.php | 4 +++- tests/aot/closure-002.phpt | 38 +++++++++++++++++++++++++++++++++++ tests/aot/func-self-type.phpt | 23 +++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/aot/closure-002.phpt create mode 100644 tests/aot/func-self-type.phpt diff --git a/bin/gen_stub.php b/bin/gen_stub.php index fda459b4..9f8ba4a7 100755 --- a/bin/gen_stub.php +++ b/bin/gen_stub.php @@ -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 = []; diff --git a/tests/aot/closure-002.phpt b/tests/aot/closure-002.phpt new file mode 100644 index 00000000..a934cf0b --- /dev/null +++ b/tests/aot/closure-002.phpt @@ -0,0 +1,38 @@ +--TEST-- +closure 001 +--FILE-- + +--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) +} + diff --git a/tests/aot/func-self-type.phpt b/tests/aot/func-self-type.phpt new file mode 100644 index 00000000..cb25a448 --- /dev/null +++ b/tests/aot/func-self-type.phpt @@ -0,0 +1,23 @@ +--TEST-- +static calls +--FILE-- +pipe($stream2); + } +} +?> +--EXPECT-- +string(10) "Foo\Stream" \ No newline at end of file