diff --git a/src/Type/Accessory/AccessoryNumericStringType.php b/src/Type/Accessory/AccessoryNumericStringType.php index 2e720c9800..fbc1bc4ce3 100644 --- a/src/Type/Accessory/AccessoryNumericStringType.php +++ b/src/Type/Accessory/AccessoryNumericStringType.php @@ -78,6 +78,10 @@ public function isSubTypeOf(Type $otherType): TrinaryLogic public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic { + if ($acceptingType->isNonEmptyString()->yes()) { + return TrinaryLogic::createYes(); + } + return $this->isSubTypeOf($acceptingType); } diff --git a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php index eec5f3ae9c..d780032ebd 100644 --- a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php @@ -695,4 +695,9 @@ public function testConditionalTypes(): void ]); } + public function testBug7265(): void + { + $this->analyse([__DIR__ . '/data/bug-7265.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-7265.php b/tests/PHPStan/Rules/Methods/data/bug-7265.php new file mode 100644 index 0000000000..06012e6349 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-7265.php @@ -0,0 +1,25 @@ +