Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c65f834

Browse files
Don't generalize template types
1 parent 1182199 commit c65f834

33 files changed

+124
-142
lines changed

‎src/Type/Generic/TemplateArrayType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ public function traverse(callable $cb): Type
4646
return $this;
4747
}
4848

49-
protected function shouldGeneralizeInferredType(): bool
50-
{
51-
return false;
52-
}
53-
5449
}

‎src/Type/Generic/TemplateBooleanType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ public function traverse(callable $cb): Type
4646
return $this;
4747
}
4848

49-
protected function shouldGeneralizeInferredType(): bool
50-
{
51-
return false;
52-
}
53-
5449
}

‎src/Type/Generic/TemplateConstantArrayType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ public function traverse(callable $cb): Type
4646
return $this;
4747
}
4848

49-
protected function shouldGeneralizeInferredType(): bool
50-
{
51-
return false;
52-
}
53-
5449
}

‎src/Type/Generic/TemplateFloatType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ public function traverse(callable $cb): Type
4646
return $this;
4747
}
4848

49-
protected function shouldGeneralizeInferredType(): bool
50-
{
51-
return false;
52-
}
53-
5449
}

‎src/Type/Generic/TemplateIntegerType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ public function traverse(callable $cb): Type
4646
return $this;
4747
}
4848

49-
protected function shouldGeneralizeInferredType(): bool
50-
{
51-
return false;
52-
}
53-
5449
}

‎src/Type/Generic/TemplateKeyOfType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ public function traverse(callable $cb): Type
4646
return $this;
4747
}
4848

49-
protected function shouldGeneralizeInferredType(): bool
50-
{
51-
return false;
52-
}
53-
5449
}

‎src/Type/Generic/TemplateStringType.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,4 @@ public function traverse(callable $cb): Type
4646
return $this;
4747
}
4848

49-
protected function shouldGeneralizeInferredType(): bool
50-
{
51-
return false;
52-
}
53-
5449
}

‎src/Type/Generic/TemplateTypeTrait.php‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Type\Generic;
44

55
use PHPStan\TrinaryLogic;
6-
use PHPStan\Type\GeneralizePrecision;
76
use PHPStan\Type\IntersectionType;
87
use PHPStan\Type\MixedType;
98
use PHPStan\Type\NeverType;
@@ -250,7 +249,7 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
250249
$resolvedBound = TypeUtils::resolveLateResolvableTypes(TemplateTypeHelper::resolveTemplateTypes($this->getBound(), $map));
251250
if ($resolvedBound->isSuperTypeOf($receivedType)->yes()) {
252251
return (new TemplateTypeMap([
253-
$this->name => $this->shouldGeneralizeInferredType() ? $receivedType->generalize(GeneralizePrecision::templateArgument()) : $receivedType,
252+
$this->name => $receivedType,
254253
]))->union($map);
255254
}
256255

@@ -267,11 +266,6 @@ public function getVariance(): TemplateTypeVariance
267266
return $this->variance;
268267
}
269268

270-
protected function shouldGeneralizeInferredType(): bool
271-
{
272-
return true;
273-
}
274-
275269
public function tryRemove(Type $typeToRemove): ?Type
276270
{
277271
if ($this->getBound()->isSuperTypeOf($typeToRemove)->yes()) {

‎tests/PHPStan/Analyser/AnalyserIntegrationTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,11 @@ public function testDiscussion7124(): void
763763

764764
$errors = $this->runAnalyse(__DIR__ . '/data/discussion-7124.php');
765765
$this->assertCount(4, $errors);
766-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int, bool): bool given.', $errors[0]->getMessage());
766+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, 0|1|2): bool, Closure(int, bool): bool given.', $errors[0]->getMessage());
767767
$this->assertSame(38, $errors[0]->getLine());
768-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int): bool given.', $errors[1]->getMessage());
768+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, 0|1|2): bool, Closure(int): bool given.', $errors[1]->getMessage());
769769
$this->assertSame(45, $errors[1]->getLine());
770-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(int): bool, Closure(bool): bool given.', $errors[2]->getMessage());
770+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(0|1|2): bool, Closure(bool): bool given.', $errors[2]->getMessage());
771771
$this->assertSame(52, $errors[2]->getLine());
772772
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool): bool, Closure(int): bool given.', $errors[3]->getMessage());
773773
$this->assertSame(59, $errors[3]->getLine());

‎tests/PHPStan/Analyser/data/bug-3351.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function sayHello(): void
1010
$b = [1, 2, 3];
1111

1212
$c = $this->combine($a, $b);
13-
assertType('array<string, int>|false', $c);
13+
assertType("array<'a'|'b'|'c', 1|2|3>|false", $c);
1414

1515
assertType('array{a: 1, b: 2, c: 3}', array_combine($a, $b));
1616
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /