Skip to content

Commit 7a158af

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 e60f880 commit 7a158af

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
@@ -4387,6 +4387,11 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri
43874387
}
43884388
}
43894389

4390+
if ($stmt instanceof Stmt\Use_ || $stmt instanceof Stmt\GroupUse) {
4391+
// use statements are resolved by NameResolver before this point
4392+
continue;
4393+
}
4394+
43904395
throw new Exception("Unexpected node {$stmt->getType()}");
43914396
}
43924397
if (!empty($conds)) {

ext/zend_test/test.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,18 @@ public function method(): ?NotUnlikelyCompileError {}
378378

379379
namespace ZendTestNS2 {
380380

381+
use ZendTestNS\Foo as FooAlias;
382+
use ZendTestNS\UnlikelyCompileError;
383+
use ZendTestNS\{NotUnlikelyCompileError};
384+
381385
/** @var string */
382386
const ZEND_CONSTANT_A = "namespaced";
383387

384388
class Foo {
385389
public ZendSubNS\Foo $foo;
390+
public FooAlias $fooAlias;
391+
public UnlikelyCompileError $unlProp;
392+
public NotUnlikelyCompileError $notUnlProp;
386393

387394
public function method(): void {}
388395
}

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
@@ -18,11 +18,23 @@ var_dump($foo);
1818
object(ZendTestNS2\Foo)#%d (%d) {
1919
["foo"]=>
2020
uninitialized(ZendTestNS2\ZendSubNS\Foo)
21+
["fooAlias"]=>
22+
uninitialized(ZendTestNS\Foo)
23+
["unlProp"]=>
24+
uninitialized(ZendTestNS\UnlikelyCompileError)
25+
["notUnlProp"]=>
26+
uninitialized(ZendTestNS\NotUnlikelyCompileError)
2127
}
2228
object(ZendTestNS2\Foo)#%d (%d) {
2329
["foo"]=>
2430
object(ZendTestNS2\ZendSubNS\Foo)#%d (%d) {
2531
}
32+
["fooAlias"]=>
33+
uninitialized(ZendTestNS\Foo)
34+
["unlProp"]=>
35+
uninitialized(ZendTestNS\UnlikelyCompileError)
36+
["notUnlProp"]=>
37+
uninitialized(ZendTestNS\NotUnlikelyCompileError)
2638
}
2739
object(ZendTestNS\UnlikelyCompileError)#%d (%d) {
2840
}

0 commit comments

Comments
 (0)