Skip to content

Commit bc86dcc

Browse files
committed
[BE] Improve impossible type checker for void-returning functions
1 parent 6f6e25d commit bc86dcc

24 files changed

+3
-31
lines changed

changelog-2.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Improvements 🔧
126126
* Check mixed in unary operator ([#3253](https://github.com/phpstan/phpstan-src/pull/3253)), thanks @schlndh!
127127
* Stub files validation - detect duplicate classes and functions (https://github.com/phpstan/phpstan-src/commit/ddf8d5c3859c2c75c20f525a0e2ca8b99032373a, https://github.com/phpstan/phpstan-src/commit/17e4b74335e5235d7cd6708eb687a774a0eeead4)
128128
* NoopRule - take advantage of impure points (https://github.com/phpstan/phpstan-src/commit/a6470521b65d7424f552633c1f3827704c6262c3), #10389
129+
* Improve impossible type checker for void-returning functions ([#1857](https://github.com/phpstan/phpstan-src/pull/1857)), #8169, thanks @rvanvelzen!
129130

130131
Bugfixes 🐛
131132
=====================

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ parameters:
1616
runtimeReflectionRules: true
1717
curlSetOptTypes: true
1818
missingMagicSerializationRule: true
19-
nullContextForVoidReturningFunctions: true
2019
alwaysCheckTooWideReturnTypeFinalMethods: true
2120
alwaysTrueAlwaysReported: true
2221
disableUnreachableBranchesRules: true

conf/config.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ parameters:
3737
runtimeReflectionRules: false
3838
curlSetOptTypes: false
3939
missingMagicSerializationRule: false
40-
nullContextForVoidReturningFunctions: false
4140
alwaysCheckTooWideReturnTypeFinalMethods: false
4241
alwaysTrueAlwaysReported: false
4342
disableUnreachableBranchesRules: false
@@ -895,7 +894,6 @@ services:
895894
arguments:
896895
universalObjectCratesClasses: %universalObjectCratesClasses%
897896
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
898-
nullContextForVoidReturningFunctions: %featureToggles.nullContextForVoidReturningFunctions%
899897

900898
-
901899
class: PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver
@@ -1792,7 +1790,6 @@ services:
17921790
arguments:
17931791
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
17941792
universalObjectCratesClasses: %universalObjectCratesClasses%
1795-
nullContextForVoidReturningFunctions: %featureToggles.nullContextForVoidReturningFunctions%
17961793
tags:
17971794
- phpstan.broker.dynamicFunctionReturnTypeExtension
17981795

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ parametersSchema:
4343
runtimeReflectionRules: bool()
4444
curlSetOptTypes: bool()
4545
missingMagicSerializationRule: bool()
46-
nullContextForVoidReturningFunctions: bool()
4746
alwaysCheckTooWideReturnTypeFinalMethods: bool()
4847
alwaysTrueAlwaysReported: bool()
4948
disableUnreachableBranchesRules: bool()

src/Rules/Comparison/ImpossibleCheckTypeHelper.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function __construct(
4848
private TypeSpecifier $typeSpecifier,
4949
private array $universalObjectCratesClasses,
5050
private bool $treatPhpDocTypesAsCertain,
51-
private bool $nullContextForVoidReturningFunctions,
5251
)
5352
{
5453
}
@@ -369,16 +368,11 @@ public function doNotTreatPhpDocTypesAsCertain(): self
369368
$this->typeSpecifier,
370369
$this->universalObjectCratesClasses,
371370
false,
372-
$this->nullContextForVoidReturningFunctions,
373371
);
374372
}
375373

376374
private function determineContext(Scope $scope, Expr $node): TypeSpecifierContext
377375
{
378-
if (!$this->nullContextForVoidReturningFunctions) {
379-
return TypeSpecifierContext::createTruthy();
380-
}
381-
382376
if ($node instanceof Expr\CallLike && $node->isFirstClassCallable()) {
383377
return TypeSpecifierContext::createTruthy();
384378
}

src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class TypeSpecifyingFunctionsDynamicReturnTypeExtension implements Dynamic
2525
/**
2626
* @param string[] $universalObjectCratesClasses
2727
*/
28-
public function __construct(private ReflectionProvider $reflectionProvider, private bool $treatPhpDocTypesAsCertain, private array $universalObjectCratesClasses, private bool $nullContextForVoidReturningFunctions)
28+
public function __construct(private ReflectionProvider $reflectionProvider, private bool $treatPhpDocTypesAsCertain, private array $universalObjectCratesClasses)
2929
{
3030
}
3131

@@ -68,7 +68,7 @@ public function getTypeFromFunctionCall(
6868
private function getHelper(): ImpossibleCheckTypeHelper
6969
{
7070
if ($this->helper === null) {
71-
$this->helper = new ImpossibleCheckTypeHelper($this->reflectionProvider, $this->typeSpecifier, $this->universalObjectCratesClasses, $this->treatPhpDocTypesAsCertain, $this->nullContextForVoidReturningFunctions);
71+
$this->helper = new ImpossibleCheckTypeHelper($this->reflectionProvider, $this->typeSpecifier, $this->universalObjectCratesClasses, $this->treatPhpDocTypesAsCertain);
7272
}
7373

7474
return $this->helper;

tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ protected function getRule(): Rule
2424
$this->getTypeSpecifier(),
2525
[],
2626
$this->treatPhpDocTypesAsCertain,
27-
true,
2827
),
2928
$this->treatPhpDocTypesAsCertain,
3029
true,

tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ protected function getRule(): Rule
2424
$this->getTypeSpecifier(),
2525
[],
2626
$this->treatPhpDocTypesAsCertain,
27-
true,
2827
),
2928
$this->treatPhpDocTypesAsCertain,
3029
true,

tests/PHPStan/Rules/Comparison/BooleanOrConstantConditionRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ protected function getRule(): Rule
2525
$this->getTypeSpecifier(),
2626
[],
2727
$this->treatPhpDocTypesAsCertain,
28-
true,
2928
),
3029
$this->treatPhpDocTypesAsCertain,
3130
true,

tests/PHPStan/Rules/Comparison/DoWhileLoopConstantConditionRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ protected function getRule(): Rule
2222
$this->getTypeSpecifier(),
2323
[],
2424
$this->treatPhpDocTypesAsCertain,
25-
true,
2625
),
2726
$this->treatPhpDocTypesAsCertain,
2827
true,

0 commit comments

Comments
 (0)