Skip to content

Commit 271a897

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 271a897

File tree

7 files changed

+80
-6
lines changed

7 files changed

+80
-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.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static zend_class_entry *zend_test_ns_foo_class;
7070
static zend_class_entry *zend_test_ns_unlikely_compile_error_class;
7171
static zend_class_entry *zend_test_ns_not_unlikely_compile_error_class;
7272
static zend_class_entry *zend_test_ns2_foo_class;
73+
static zend_class_entry *zend_test_ns2_foo_with_used_prop_class;
7374
static zend_class_entry *zend_test_ns2_ns_foo_class;
7475
static zend_class_entry *zend_test_unit_enum;
7576
static zend_class_entry *zend_test_string_enum;
@@ -1572,6 +1573,7 @@ PHP_MINIT_FUNCTION(zend_test)
15721573
zend_test_ns_unlikely_compile_error_class = register_class_ZendTestNS_UnlikelyCompileError();
15731574
zend_test_ns_not_unlikely_compile_error_class = register_class_ZendTestNS_NotUnlikelyCompileError();
15741575
zend_test_ns2_foo_class = register_class_ZendTestNS2_Foo();
1576+
zend_test_ns2_foo_with_used_prop_class = register_class_ZendTestNS2_FooWithUsedProp();
15751577
zend_test_ns2_ns_foo_class = register_class_ZendTestNS2_ZendSubNS_Foo();
15761578

15771579
zend_test_unit_enum = register_class_ZendTestUnitEnum();

ext/zend_test/test.stub.php

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

379379
namespace ZendTestNS2 {
380380

381+
use ZendTestNS\UnlikelyCompileError;
382+
use ZendTestNS\{NotUnlikelyCompileError};
383+
381384
/** @var string */
382385
const ZEND_CONSTANT_A = "namespaced";
383386

@@ -387,6 +390,10 @@ class Foo {
387390
public function method(): void {}
388391
}
389392

393+
class FooWithUsedProp {
394+
public UnlikelyCompileError $prop;
395+
}
396+
390397
function namespaced_func(): bool {}
391398

392399
/** @deprecated */

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: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
gen_stub.php: use statements in stub files
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
$rp = new ReflectionProperty(ZendTestNS2\FooWithUsedProp::class, 'prop');
9+
$type = $rp->getType();
10+
11+
var_dump($type->getName());
12+
var_dump($type->allowsNull());
13+
var_dump($type->isBuiltin());
14+
15+
?>
16+
--EXPECT--
17+
string(31) "ZendTestNS\UnlikelyCompileError"
18+
bool(false)
19+
bool(false)

0 commit comments

Comments
 (0)