File tree Expand file tree Collapse file tree 5 files changed +113
-2
lines changed
Expand file tree Collapse file tree 5 files changed +113
-2
lines changed Original file line number Diff line number Diff line change @@ -1373,9 +1373,13 @@ public function getTypeAliases(): array
13731373
13741374 $ typeAliasImportTags = $ resolvedPhpDoc ->getTypeAliasImportTags ();
13751375 $ typeAliasTags = $ resolvedPhpDoc ->getTypeAliasTags ();
1376+ $ localAliases = array_map (static fn (TypeAliasTag $ typeAliasTag ): TypeAlias => $ typeAliasTag ->getTypeAlias (), $ typeAliasTags );
13761377
13771378 // prevent circular imports
13781379 if (array_key_exists ($ this ->getName (), self ::$ resolvingTypeAliasImports )) {
1380+ if ($ localAliases !== []) {
1381+ return $ this ->typeAliases = $ localAliases ;
1382+ }
13791383 throw new CircularTypeAliasDefinitionException ();
13801384 }
13811385
@@ -1406,8 +1410,6 @@ public function getTypeAliases(): array
14061410
14071411 unset(self ::$ resolvingTypeAliasImports [$ this ->getName ()]);
14081412
1409- $ localAliases = array_map (static fn (TypeAliasTag $ typeAliasTag ): TypeAlias => $ typeAliasTag ->getTypeAlias (), $ typeAliasTags );
1410-
14111413 $ this ->typeAliases = array_filter (
14121414 array_merge ($ importedAliases , $ localAliases ),
14131415 static fn (?TypeAlias $ typeAlias ): bool => $ typeAlias !== null ,
Original file line number Diff line number Diff line change @@ -3900,4 +3900,21 @@ public function testBug6120(): void
39003900 $ this ->analyse ([__DIR__ . '/data/bug-6120.php ' ], []);
39013901 }
39023902
3903+ public function testBug11463 (): void
3904+ {
3905+ $ this ->checkThisOnly = false ;
3906+ $ this ->checkNullables = true ;
3907+ $ this ->checkUnionTypes = true ;
3908+ $ this ->analyse ([__DIR__ . '/../PhpDoc/data/bug-11463.php ' ], [
3909+ [
3910+ "Parameter #1 \$bar of method Bug11463\FooType::foo() expects 'bar', 'bla' given. " ,
3911+ 32 ,
3912+ ],
3913+ [
3914+ "Parameter #1 \$foo of method Bug11463\BarType::bar() expects 'foo', 'bla' given. " ,
3915+ 35 ,
3916+ ],
3917+ ]);
3918+ }
3919+
39033920}
Original file line number Diff line number Diff line change @@ -487,4 +487,14 @@ public function testBug9708(): void
487487 $ this ->analyse ([__DIR__ . '/data/bug-9708.php ' ], []);
488488 }
489489
490+ public function testBug11463 (): void
491+ {
492+ $ this ->analyse ([__DIR__ . '/data/bug-11463.php ' ], []);
493+ }
494+
495+ public function testBug11463b (): void
496+ {
497+ $ this ->analyse ([__DIR__ . '/data/bug-11463b.php ' ], []);
498+ }
499+
490500}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug11463 ;
4+
5+ /**
6+ * @phpstan-type Foo 'foo'
7+ *
8+ * @phpstan-import-type Bar from BarType
9+ */
10+ class FooType
11+ {
12+ /**
13+ * @param Bar $bar
14+ */
15+ public function foo (string $ bar ): void {}
16+ }
17+
18+ /**
19+ * @phpstan-import-type Foo from FooType
20+ *
21+ * @phpstan-type Bar 'bar'
22+ */
23+ class BarType {
24+ /**
25+ * @param Foo $foo
26+ */
27+ public function bar ($ foo ): string { return $ foo ; }
28+ }
29+
30+ function doFoo (FooType $ foo , BarType $ bar ): void {
31+ $ foo ->foo ('bar ' );
32+ $ foo ->foo ('bla ' );
33+
34+ $ bar ->bar ('foo ' );
35+ $ bar ->bar ('bla ' );
36+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug11463b ;
4+
5+ /**
6+ * @phpstan-type Foo 'foo'
7+ *
8+ * @phpstan-import-type Bar from BarType
9+ * @phpstan-import-type Baz from BazType
10+ */
11+ class FooType
12+ {
13+ /**
14+ * @param Bar $bar
15+ */
16+ public function foo (string $ bar ): void {}
17+
18+ /**
19+ * @param Baz $bar
20+ */
21+ public function baz (string $ bar ): void {}
22+ }
23+
24+ /**
25+ * @phpstan-import-type Foo from FooType
26+ *
27+ * @phpstan-type Bar 'bar'
28+ * @phpstan-import-type Baz from BazType
29+ */
30+ class BarType {
31+ /**
32+ * @param Foo $foo
33+ */
34+ public function bar ($ foo ): string { return $ foo ; }
35+
36+ /**
37+ * @param Baz $bar
38+ */
39+ public function baz (string $ bar ): void {}
40+ }
41+
42+ /**
43+ * @phpstan-type Baz 'baz'
44+ */
45+ class BazType {
46+ }
You can’t perform that action at this time.
0 commit comments