Skip to content

Commit 029343e

Browse files
committed
gen_stub: support use statements in stub files
Stmt\Use_ and Stmt\GroupUse nodes were not handled in handleStatements(), causing an "Unexpected node" exception when use statements appeared in stub files. Since NameResolver resolves all names to their fully qualified form before handleStatements() runs, these nodes can simply be skipped.
1 parent 4b4ba03 commit 029343e

File tree

6 files changed

+69
-6
lines changed

6 files changed

+69
-6
lines changed

build/gen_stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,6 +4261,11 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri
42614261
continue;
42624262
}
42634263

4264+
if ($stmt instanceof Stmt\Use_ || $stmt instanceof Stmt\GroupUse) {
4265+
// use statements are resolved by NameResolver before this point
4266+
continue;
4267+
}
4268+
42644269
if ($stmt instanceof Stmt\Const_) {
42654270
foreach ($stmt->consts as $const) {
42664271
$this->constInfos[] = parseConstLike(

ext/zend_test/test.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,20 @@ public function method(): ?NotUnlikelyCompileError {}
380380

381381
namespace ZendTestNS2 {
382382

383+
use ZendTestNS\Foo as FooAlias;
384+
use ZendTestNS\UnlikelyCompileError;
385+
use ZendTestNS\{NotUnlikelyCompileError};
386+
383387
/** @var string */
384388
const ZEND_CONSTANT_A = "namespaced";
385389

386390
class Foo {
387391
public ZendSubNS\Foo $foo;
388392
public ZendSubNS\Foo&\ZendTestNS\Bar $intersectionProp;
389393
public ZendSubNS\Foo|\ZendTestNS\Bar $unionProp;
394+
public FooAlias $fooAlias;
395+
public UnlikelyCompileError $unlProp;
396+
public NotUnlikelyCompileError $notUnlProp;
390397

391398
public function method(): void {}
392399
}

ext/zend_test/test_arginfo.h

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/test_decl.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/test_legacy_arginfo.h

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/tests/gen_stub_test_01.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ object(ZendTestNS2\Foo)#%d (%d) {
2222
uninitialized(ZendTestNS2\ZendSubNS\Foo&ZendTestNS\Bar)
2323
["unionProp"]=>
2424
uninitialized(ZendTestNS2\ZendSubNS\Foo|ZendTestNS\Bar)
25+
["fooAlias"]=>
26+
uninitialized(ZendTestNS\Foo)
27+
["unlProp"]=>
28+
uninitialized(ZendTestNS\UnlikelyCompileError)
29+
["notUnlProp"]=>
30+
uninitialized(ZendTestNS\NotUnlikelyCompileError)
2531
}
2632
object(ZendTestNS2\Foo)#%d (%d) {
2733
["foo"]=>
@@ -31,6 +37,12 @@ object(ZendTestNS2\Foo)#%d (%d) {
3137
uninitialized(ZendTestNS2\ZendSubNS\Foo&ZendTestNS\Bar)
3238
["unionProp"]=>
3339
uninitialized(ZendTestNS2\ZendSubNS\Foo|ZendTestNS\Bar)
40+
["fooAlias"]=>
41+
uninitialized(ZendTestNS\Foo)
42+
["unlProp"]=>
43+
uninitialized(ZendTestNS\UnlikelyCompileError)
44+
["notUnlProp"]=>
45+
uninitialized(ZendTestNS\NotUnlikelyCompileError)
3446
}
3547
object(ZendTestNS\UnlikelyCompileError)#%d (%d) {
3648
}

0 commit comments

Comments
 (0)