Skip to content

Commit 5626b41

Browse files
authored
Merge branch refs/heads/1.12.x into 2.1.x
2 parents bed30a7 + d06f792 commit 5626b41

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

src/Analyser/MutatingScope.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5685,7 +5685,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
56855685
continue;
56865686
}
56875687

5688-
$ancestorMapping[$typeName] = $templateType->getName();
5688+
$ancestorMapping[$typeName] = $templateType;
56895689
}
56905690

56915691
$resolvedTypeMap = [];
@@ -5694,12 +5694,17 @@ private function exactInstantiation(New_ $node, string $className): ?Type
56945694
continue;
56955695
}
56965696

5697-
if (!array_key_exists($ancestorMapping[$typeName], $resolvedTypeMap)) {
5698-
$resolvedTypeMap[$ancestorMapping[$typeName]] = $type;
5697+
$ancestorType = $ancestorMapping[$typeName];
5698+
if (!$ancestorType->getBound()->isSuperTypeOf($type)->yes()) {
56995699
continue;
57005700
}
57015701

5702-
$resolvedTypeMap[$ancestorMapping[$typeName]] = TypeCombinator::union($resolvedTypeMap[$ancestorMapping[$typeName]], $type);
5702+
if (!array_key_exists($ancestorType->getName(), $resolvedTypeMap)) {
5703+
$resolvedTypeMap[$ancestorType->getName()] = $type;
5704+
continue;
5705+
}
5706+
5707+
$resolvedTypeMap[$ancestorType->getName()] = TypeCombinator::union($resolvedTypeMap[$ancestorType->getName()], $type);
57035708
}
57045709

57055710
return new GenericObjectType(
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Bug12386;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function doFoo() {
8+
$landMapper = new Application_Model_Mapper_Land();
9+
assertType('Bug12386\\Clx_Model_Iterator<Bug12386\\Application_Model_Land>', $landMapper->fetchAllActivePrependDefault(12));
10+
}
11+
12+
/**
13+
* @template T of Clx_Model_Abstract
14+
*/
15+
abstract class Clx_Model_Mapper_Abstract
16+
{
17+
public function __construct()
18+
{
19+
}
20+
}
21+
22+
/**
23+
* @template T of Application_Model_Land
24+
*
25+
* @extends Clx_Model_Mapper_Abstract<T>
26+
*/
27+
class ClxProductNet_Model_Mapper_Land extends Clx_Model_Mapper_Abstract
28+
{
29+
/**
30+
* @param int $defaultLandid
31+
*
32+
* @return Clx_Model_Iterator<T>
33+
*/
34+
public function fetchAllActivePrependDefault($defaultLandid): Clx_Model_Iterator
35+
{}
36+
}
37+
38+
/**
39+
* @template T of Application_Model_Land
40+
*
41+
* @extends ClxProductNet_Model_Mapper_Land<T>
42+
*/
43+
final class Application_Model_Mapper_Land extends ClxProductNet_Model_Mapper_Land
44+
{
45+
}
46+
47+
/**
48+
* @template T of Clx_Model_Abstract
49+
*
50+
* @implements \Iterator<T>
51+
*/
52+
abstract class Clx_Model_Iterator implements \Countable, \Iterator
53+
{}
54+
55+
abstract class Clx_Model_Abstract implements \Stringable
56+
{}
57+
58+
abstract class ClxProductNet_Model_Land extends Clx_Model_Abstract
59+
{}
60+
61+
final class Application_Model_Land extends ClxProductNet_Model_Land
62+
{
63+
public function __toString()
64+
{
65+
return 'foo';
66+
}
67+
68+
}

0 commit comments

Comments
 (0)