diff --git a/src/Type/Generic/GenericClassStringType.php b/src/Type/Generic/GenericClassStringType.php index b4ac3eff88..1d0cf1d589 100644 --- a/src/Type/Generic/GenericClassStringType.php +++ b/src/Type/Generic/GenericClassStringType.php @@ -94,6 +94,9 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult if ($type instanceof ConstantStringType) { $genericType = $this->type; if ($genericType instanceof MixedType) { + if (!$type->isClassString()->yes()) { + return IsSuperTypeOfResult::createMaybe(); + } return IsSuperTypeOfResult::createYes(); } diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index ee754a40d9..fb855592c8 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -2817,4 +2817,9 @@ public function testBug14312b(): void $this->analyse([__DIR__ . '/data/bug-14312b.php'], []); } + public function testBug10076(): void + { + $this->analyse([__DIR__ . '/data/bug-10076.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-10076.php b/tests/PHPStan/Rules/Functions/data/bug-10076.php new file mode 100644 index 0000000000..ca4a9b404b --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-10076.php @@ -0,0 +1,20 @@ + $type + * + * @return list + */ +function result($type = 'object'): array +{ + return []; +} + +result(); +result('object'); +result('array'); +result(\DateTime::class);