Skip to content

Commit 2e02765

Browse files
committed
[BE] Do not generalize template types, except when in GenericObjectType
1 parent 041922b commit 2e02765

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

changelog-2.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ Bleeding edge (TODO move to other sections)
7171
* MethodSignatureRule - look at abstract trait method (https://github.com/phpstan/phpstan-src/commit/5fd8cee591ce1b07daa5f98a1ddcdfc723f1b5eb)
7272
* MagicConstantContextRule ([#2741](https://github.com/phpstan/phpstan-src/pull/2741)), #10099, thanks @staabm!
7373
* More precise `RecursiveIteratorIterator::__construct()` parameter types ([#2835](https://github.com/phpstan/phpstan-src/pull/2835)), thanks @staabm!
74-
* Do not generalize template types, except when in `GenericObjectType` ([#2818](https://github.com/phpstan/phpstan-src/pull/2818), [#2821](https://github.com/phpstan/phpstan-src/pull/2821))
75-
* This fixes following **17 issues**: #8166, #8127, #7944, #7283, #6653, #6196, #9084, #8683, #8074, #7984, #7301, #7087, #5594, #5592, #9472, #9764, #10092
7674
* TooWideMethodReturnTypehintRule - always report for final methods (https://github.com/phpstan/phpstan-src/commit/c30e9a484c8245b8126cd63444607ca74d2af761)
7775
* LogicalXorConstantConditionRule (https://github.com/phpstan/phpstan-src/commit/3a12724fd636b1bcf36c22b36e8f765d97150895, https://github.com/phpstan/phpstan-src/commit/3b011f6524254dad0f16840fdcfdbe7421548617), #7539
7876
* NoopRule - report top-level `xor` because that's probably not what the user intended to do (https://github.com/phpstan/phpstan-src/commit/a1fffb3346e09f1e8e8d987d4282263295a55142), #10267
@@ -140,6 +138,8 @@ Improvements 🔧
140138
* InvalidPhpDocTagValueRule: include PHPDoc line number in the error message (https://github.com/phpstan/phpstan-src/commit/a04e0be832900749b5b4ba22e2de21db8bfa09a0)
141139
* No implicit wildcard in FileExcluder (https://github.com/phpstan/phpstan-src/commit/e19e6e5f8cfa706cc30e44a17276a6bc269f995c), #10299
142140
* Report invalid exclude paths in PHP config (https://github.com/phpstan/phpstan-src/commit/9718c14f1ffac81ba3d2bf331b4e8b4041a4d004)
141+
* Do not generalize template types, except when in `GenericObjectType` ([#2818](https://github.com/phpstan/phpstan-src/pull/2818), [#2821](https://github.com/phpstan/phpstan-src/pull/2821))
142+
* This fixes following **17 issues**: #8166, #8127, #7944, #7283, #6653, #6196, #9084, #8683, #8074, #7984, #7301, #7087, #5594, #5592, #9472, #9764, #10092
143143

144144
Bugfixes 🐛
145145
=====================

src/Reflection/ResolvedFunctionVariantWithOriginal.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Reflection;
44

5-
use PHPStan\DependencyInjection\BleedingEdgeToggle;
65
use PHPStan\Reflection\Php\DummyParameterWithPhpDocs;
76
use PHPStan\Type\ConditionalTypeForParameter;
87
use PHPStan\Type\ErrorType;
@@ -245,7 +244,7 @@ private function resolveResolvableTemplateTypes(Type $type, TemplateTypeVariance
245244
};
246245

247246
return TypeTraverser::map($type, function (Type $type, callable $traverse) use ($references, $objectCb): Type {
248-
if (BleedingEdgeToggle::isBleedingEdge() && $type instanceof GenericObjectType) {
247+
if ($type instanceof GenericObjectType) {
249248
return TypeTraverser::map($type, $objectCb);
250249
}
251250

src/Type/Generic/TemplateTypeTrait.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace PHPStan\Type\Generic;
44

5-
use PHPStan\DependencyInjection\BleedingEdgeToggle;
65
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
76
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
87
use PHPStan\TrinaryLogic;
98
use PHPStan\Type\AcceptsResult;
10-
use PHPStan\Type\GeneralizePrecision;
119
use PHPStan\Type\IntersectionType;
1210
use PHPStan\Type\MixedType;
1311
use PHPStan\Type\NeverType;
@@ -268,13 +266,6 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
268266
TemplateTypeVariance::createStatic(),
269267
));
270268
if ($resolvedBound->isSuperTypeOf($receivedType)->yes()) {
271-
if (!BleedingEdgeToggle::isBleedingEdge() && $this->shouldGeneralizeInferredType()) {
272-
$generalizedType = $receivedType->generalize(GeneralizePrecision::templateArgument());
273-
if ($resolvedBound->isSuperTypeOf($generalizedType)->yes()) {
274-
$receivedType = $generalizedType;
275-
}
276-
}
277-
278269
return (new TemplateTypeMap([
279270
$this->name => $receivedType,
280271
]))->union($map);

0 commit comments

Comments
 (0)