From 9070c5bce39105a186d03e3e5b6871c2b5d28550 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 9 Jun 2021 10:16:15 +0200 Subject: [PATCH] Bleeding edge - detect unresolvable return type after generic function call --- conf/bleedingEdge.neon | 1 + conf/config.neon | 5 +- src/Rules/AttributesCheck.php | 1 + src/Rules/Classes/InstantiationRule.php | 1 + src/Rules/FunctionCallParametersCheck.php | 21 ++++- src/Rules/Functions/CallCallablesRule.php | 1 + .../CallToFunctionParametersRule.php | 1 + src/Rules/Methods/CallMethodsRule.php | 1 + src/Rules/Methods/CallStaticMethodsRule.php | 1 + .../Rules/Classes/ClassAttributesRuleTest.php | 3 + .../ClassConstantAttributesRuleTest.php | 3 + .../Rules/Classes/InstantiationRuleTest.php | 3 +- .../ArrowFunctionAttributesRuleTest.php | 3 + .../Rules/Functions/CallCallablesRuleTest.php | 3 + .../CallToFunctionParametersRuleTest.php | 3 +- .../Functions/ClosureAttributesRuleTest.php | 3 + .../Functions/FunctionAttributesRuleTest.php | 3 + .../Functions/ParamAttributesRuleTest.php | 3 + .../Rules/Methods/CallMethodsRuleTest.php | 32 +++++++- .../Methods/CallStaticMethodsRuleTest.php | 3 +- .../Methods/MethodAttributesRuleTest.php | 3 + .../data/generic-return-type-never.php | 76 +++++++++++++++++++ .../Properties/PropertyAttributesRuleTest.php | 3 + 23 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 tests/PHPStan/Rules/Methods/data/generic-return-type-never.php diff --git a/conf/bleedingEdge.neon b/conf/bleedingEdge.neon index 4fc6a845e0..cba36f7fc1 100644 --- a/conf/bleedingEdge.neon +++ b/conf/bleedingEdge.neon @@ -20,3 +20,4 @@ parameters: preciseExceptionTracking: true apiRules: true deepInspectTypes: true + neverInGenericReturnType: true diff --git a/conf/config.neon b/conf/config.neon index f9251d5885..aa13516293 100644 --- a/conf/config.neon +++ b/conf/config.neon @@ -43,6 +43,7 @@ parameters: preciseExceptionTracking: false apiRules: false deepInspectTypes: false + neverInGenericReturnType: false fileExtensions: - php checkAlwaysTrueCheckTypeFunctionCall: false @@ -213,7 +214,8 @@ parametersSchema: rememberFunctionValues: bool(), preciseExceptionTracking: bool(), apiRules: bool(), - deepInspectTypes: bool() + deepInspectTypes: bool(), + neverInGenericReturnType: bool() ]) fileExtensions: listOf(string()) checkAlwaysTrueCheckTypeFunctionCall: bool() @@ -796,6 +798,7 @@ services: checkArgumentsPassedByReference: %checkArgumentsPassedByReference% checkExtraArguments: %checkExtraArguments% checkMissingTypehints: %checkMissingTypehints% + checkNeverInGenericReturnType: %featureToggles.neverInGenericReturnType% - class: PHPStan\Rules\FunctionDefinitionCheck diff --git a/src/Rules/AttributesCheck.php b/src/Rules/AttributesCheck.php index 563a50e275..c9080f772f 100644 --- a/src/Rules/AttributesCheck.php +++ b/src/Rules/AttributesCheck.php @@ -108,6 +108,7 @@ public function check( 'Unable to resolve the template type %s in instantiation of attribute class ' . $attributeClass->getDisplayName(), 'Missing parameter $%s in call to ' . $attributeClass->getDisplayName() . ' constructor.', 'Unknown parameter $%s in call to ' . $attributeClass->getDisplayName() . ' constructor.', + 'Return type of call to ' . $attributeClass->getDisplayName() . ' constructor contains unresolvable type.', ] ); diff --git a/src/Rules/Classes/InstantiationRule.php b/src/Rules/Classes/InstantiationRule.php index 17b4413331..9aa1612b21 100644 --- a/src/Rules/Classes/InstantiationRule.php +++ b/src/Rules/Classes/InstantiationRule.php @@ -197,6 +197,7 @@ private function checkClassName(string $class, bool $isName, Node $node, Scope $ 'Unable to resolve the template type %s in instantiation of class ' . $classReflection->getDisplayName(), 'Missing parameter $%s in call to ' . $classReflection->getDisplayName() . ' constructor.', 'Unknown parameter $%s in call to ' . $classReflection->getDisplayName() . ' constructor.', + 'Return type of call to ' . $classReflection->getDisplayName() . ' constructor contains unresolvable type.', ] )); } diff --git a/src/Rules/FunctionCallParametersCheck.php b/src/Rules/FunctionCallParametersCheck.php index 83dae6eab8..26d951a98e 100644 --- a/src/Rules/FunctionCallParametersCheck.php +++ b/src/Rules/FunctionCallParametersCheck.php @@ -7,6 +7,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Reflection\ResolvedFunctionVariant; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Type\ErrorType; use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\NeverType; @@ -26,6 +27,8 @@ class FunctionCallParametersCheck private PhpVersion $phpVersion; + private UnresolvableTypeHelper $unresolvableTypeHelper; + private bool $checkArgumentTypes; private bool $checkArgumentsPassedByReference; @@ -34,30 +37,36 @@ class FunctionCallParametersCheck private bool $checkMissingTypehints; + private bool $checkNeverInGenericReturnType; + public function __construct( RuleLevelHelper $ruleLevelHelper, NullsafeCheck $nullsafeCheck, PhpVersion $phpVersion, + UnresolvableTypeHelper $unresolvableTypeHelper, bool $checkArgumentTypes, bool $checkArgumentsPassedByReference, bool $checkExtraArguments, - bool $checkMissingTypehints + bool $checkMissingTypehints, + bool $checkNeverInGenericReturnType ) { $this->ruleLevelHelper = $ruleLevelHelper; $this->nullsafeCheck = $nullsafeCheck; $this->phpVersion = $phpVersion; + $this->unresolvableTypeHelper = $unresolvableTypeHelper; $this->checkArgumentTypes = $checkArgumentTypes; $this->checkArgumentsPassedByReference = $checkArgumentsPassedByReference; $this->checkExtraArguments = $checkExtraArguments; $this->checkMissingTypehints = $checkMissingTypehints; + $this->checkNeverInGenericReturnType = $checkNeverInGenericReturnType; } /** * @param \PHPStan\Reflection\ParametersAcceptor $parametersAcceptor * @param \PHPStan\Analyser\Scope $scope * @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\New_ $funcCall - * @param array{string, string, string, string, string, string, string, string, string, string, string, string} $messages + * @param array{string, string, string, string, string, string, string, string, string, string, string, string, string} $messages * @return RuleError[] */ public function check( @@ -346,6 +355,14 @@ static function (Type $type): bool { $errors[] = RuleErrorBuilder::message(sprintf($messages[9], $name))->line($funcCall->getLine())->tip('See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type')->build(); } } + + if ( + $this->checkNeverInGenericReturnType + && !$this->unresolvableTypeHelper->containsUnresolvableType($originalParametersAcceptor->getReturnType()) + && $this->unresolvableTypeHelper->containsUnresolvableType($parametersAcceptor->getReturnType()) + ) { + $errors[] = RuleErrorBuilder::message($messages[12])->line($funcCall->getLine())->build(); + } } return $errors; diff --git a/src/Rules/Functions/CallCallablesRule.php b/src/Rules/Functions/CallCallablesRule.php index c16cdafd39..5793b79219 100644 --- a/src/Rules/Functions/CallCallablesRule.php +++ b/src/Rules/Functions/CallCallablesRule.php @@ -127,6 +127,7 @@ static function (Type $type): bool { 'Unable to resolve the template type %s in call to ' . $callableDescription, 'Missing parameter $%s in call to ' . $callableDescription . '.', 'Unknown parameter $%s in call to ' . $callableDescription . '.', + 'Return type of call to ' . $callableDescription . ' contains unresolvable type.', ] ) ); diff --git a/src/Rules/Functions/CallToFunctionParametersRule.php b/src/Rules/Functions/CallToFunctionParametersRule.php index e44206ad1e..927f9f3d88 100644 --- a/src/Rules/Functions/CallToFunctionParametersRule.php +++ b/src/Rules/Functions/CallToFunctionParametersRule.php @@ -64,6 +64,7 @@ public function processNode(Node $node, Scope $scope): array 'Unable to resolve the template type %s in call to function ' . $function->getName(), 'Missing parameter $%s in call to function ' . $function->getName() . '.', 'Unknown parameter $%s in call to function ' . $function->getName() . '.', + 'Return type of call to function ' . $function->getName() . ' contains unresolvable type.', ] ); } diff --git a/src/Rules/Methods/CallMethodsRule.php b/src/Rules/Methods/CallMethodsRule.php index d56d19120f..1e901ce981 100644 --- a/src/Rules/Methods/CallMethodsRule.php +++ b/src/Rules/Methods/CallMethodsRule.php @@ -157,6 +157,7 @@ static function (Type $type) use ($name): bool { 'Unable to resolve the template type %s in call to method ' . $messagesMethodName, 'Missing parameter $%s in call to method ' . $messagesMethodName . '.', 'Unknown parameter $%s in call to method ' . $messagesMethodName . '.', + 'Return type of call to method ' . $messagesMethodName . ' contains unresolvable type.', ] )); diff --git a/src/Rules/Methods/CallStaticMethodsRule.php b/src/Rules/Methods/CallStaticMethodsRule.php index 6fb3a61777..12d0d16271 100644 --- a/src/Rules/Methods/CallStaticMethodsRule.php +++ b/src/Rules/Methods/CallStaticMethodsRule.php @@ -289,6 +289,7 @@ static function (Type $type) use ($methodName): bool { 'Unable to resolve the template type %s in call to method ' . $lowercasedMethodName, 'Missing parameter $%s in call to ' . $lowercasedMethodName . '.', 'Unknown parameter $%s in call to ' . $lowercasedMethodName . '.', + 'Return type of call to ' . $lowercasedMethodName . ' contains unresolvable type.', ] )); diff --git a/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php b/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php index 165be8cc03..8687ce1aa1 100644 --- a/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Classes/ClassConstantAttributesRuleTest.php b/tests/PHPStan/Rules/Classes/ClassConstantAttributesRuleTest.php index 623b23448b..84e7e2bede 100644 --- a/tests/PHPStan/Rules/Classes/ClassConstantAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ClassConstantAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php index 7faa259d64..04d788763e 100644 --- a/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php +++ b/tests/PHPStan/Rules/Classes/InstantiationRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\RuleLevelHelper; /** @@ -19,7 +20,7 @@ protected function getRule(): \PHPStan\Rules\Rule $broker = $this->createReflectionProvider(); return new InstantiationRule( $broker, - new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, false), new NullsafeCheck(), new PhpVersion(80000), true, true, true, true), + new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(true), true, true, true, true, true), new ClassCaseSensitivityCheck($broker) ); } diff --git a/tests/PHPStan/Rules/Functions/ArrowFunctionAttributesRuleTest.php b/tests/PHPStan/Rules/Functions/ArrowFunctionAttributesRuleTest.php index fb03a56fcf..63c9647b55 100644 --- a/tests/PHPStan/Rules/Functions/ArrowFunctionAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ArrowFunctionAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index ff2252c2f8..7535f3b8c0 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\RuleLevelHelper; /** @@ -21,6 +22,8 @@ protected function getRule(): \PHPStan\Rules\Rule $ruleLevelHelper, new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index d0ec39c770..c59070a150 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\RuleLevelHelper; /** @@ -18,7 +19,7 @@ protected function getRule(): \PHPStan\Rules\Rule $broker = $this->createReflectionProvider(); return new CallToFunctionParametersRule( $broker, - new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, false), new NullsafeCheck(), new PhpVersion(80000), true, true, true, true) + new FunctionCallParametersCheck(new RuleLevelHelper($broker, true, false, true, false), new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(true), true, true, true, true, true) ); } diff --git a/tests/PHPStan/Rules/Functions/ClosureAttributesRuleTest.php b/tests/PHPStan/Rules/Functions/ClosureAttributesRuleTest.php index 6eedf97ab1..eed51d56d6 100644 --- a/tests/PHPStan/Rules/Functions/ClosureAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ClosureAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Functions/FunctionAttributesRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionAttributesRuleTest.php index ddca8aacbe..0833136a92 100644 --- a/tests/PHPStan/Rules/Functions/FunctionAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Functions/ParamAttributesRuleTest.php b/tests/PHPStan/Rules/Functions/ParamAttributesRuleTest.php index 3ac52119a0..648835f7a1 100644 --- a/tests/PHPStan/Rules/Functions/ParamAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ParamAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 717fe521fb..7c8fde87c6 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use const PHP_VERSION_ID; @@ -30,13 +31,16 @@ class CallMethodsRuleTest extends \PHPStan\Testing\RuleTestCase /** @var int */ private $phpVersion = PHP_VERSION_ID; + /** @var bool */ + private $checkNeverInGenericReturnType = false; + protected function getRule(): Rule { $broker = $this->createReflectionProvider(); $ruleLevelHelper = new RuleLevelHelper($broker, $this->checkNullables, $this->checkThisOnly, $this->checkUnionTypes, $this->checkExplicitMixed); return new CallMethodsRule( $broker, - new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion($this->phpVersion), true, true, true, true), + new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion($this->phpVersion), new UnresolvableTypeHelper(true), true, true, true, true, $this->checkNeverInGenericReturnType), $ruleLevelHelper, true, true @@ -1921,4 +1925,30 @@ public function testBug4800(): void ]); } + public function testGenericReturnTypeResolvedToNever(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->checkNeverInGenericReturnType = true; + $this->analyse([__DIR__ . '/data/generic-return-type-never.php'], [ + [ + 'Return type of call to method GenericReturnTypeNever\Foo::doBar() contains unresolvable type.', + 70, + ], + [ + 'Return type of call to method GenericReturnTypeNever\Foo::doBazBaz() contains unresolvable type.', + 73, + ], + ]); + } + + public function testDoNotReportGenericReturnTypeResolvedToNever(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->analyse([__DIR__ . '/data/generic-return-type-never.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php index 99bdc60099..34c40280b8 100644 --- a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php @@ -6,6 +6,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\RuleLevelHelper; /** @@ -23,7 +24,7 @@ protected function getRule(): \PHPStan\Rules\Rule $ruleLevelHelper = new RuleLevelHelper($broker, true, $this->checkThisOnly, true, false); return new CallStaticMethodsRule( $broker, - new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion(80000), true, true, true, true), + new FunctionCallParametersCheck($ruleLevelHelper, new NullsafeCheck(), new PhpVersion(80000), new UnresolvableTypeHelper(true), true, true, true, true, true), $ruleLevelHelper, new ClassCaseSensitivityCheck($broker), true, diff --git a/tests/PHPStan/Rules/Methods/MethodAttributesRuleTest.php b/tests/PHPStan/Rules/Methods/MethodAttributesRuleTest.php index 799f02c24a..4639910662 100644 --- a/tests/PHPStan/Rules/Methods/MethodAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Methods/MethodAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true, diff --git a/tests/PHPStan/Rules/Methods/data/generic-return-type-never.php b/tests/PHPStan/Rules/Methods/data/generic-return-type-never.php new file mode 100644 index 0000000000..5e66fb0c36 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/generic-return-type-never.php @@ -0,0 +1,76 @@ + + */ + public function doBazBaz($p) + { + + } + + public function doTest(Ipsum $ipsum): void + { + $this->doFoo($ipsum); // OK + $this->doBar($ipsum); // OK + $this->doBar(new Sit()); // error + $this->doBaz(); // OK + $this->doBazBaz($ipsum); // OK + $this->doBazBaz(new Sit()); // error + } + +} diff --git a/tests/PHPStan/Rules/Properties/PropertyAttributesRuleTest.php b/tests/PHPStan/Rules/Properties/PropertyAttributesRuleTest.php index 006cd4433f..ea787b22d9 100644 --- a/tests/PHPStan/Rules/Properties/PropertyAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/PropertyAttributesRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\ClassCaseSensitivityCheck; use PHPStan\Rules\FunctionCallParametersCheck; use PHPStan\Rules\NullsafeCheck; +use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleLevelHelper; use PHPStan\Testing\RuleTestCase; @@ -27,6 +28,8 @@ protected function getRule(): Rule new RuleLevelHelper($reflectionProvider, true, false, true), new NullsafeCheck(), new PhpVersion(80000), + new UnresolvableTypeHelper(true), + true, true, true, true,