Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ public function resolveConcatType(Type $left, Type $right): Type

$leftNumericStringNonEmpty = TypeCombinator::remove($leftStringType, new ConstantStringType(''));
if ($leftNumericStringNonEmpty->isNumericString()->yes()) {
$allowedPattern = $left->isInteger()->yes() ? '#^[0-9.]+$#' : '#^[0-9]+$#';

$allRightConstantsZeroOrMore = false;
foreach ($rightConstantStrings as $rightConstantString) {
if ($rightConstantString->getValue() === '') {
Expand All @@ -514,7 +516,7 @@ public function resolveConcatType(Type $left, Type $right): Type

if (
!is_numeric($rightConstantString->getValue())
|| Strings::match($rightConstantString->getValue(), '#^[0-9]+$#') === null
|| Strings::match($rightConstantString->getValue(), $allowedPattern) === null
) {
$allRightConstantsZeroOrMore = false;
break;
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/nsrt/bug-11129.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function foo(
assertType('lowercase-string&non-falsy-string', $i.$maybeNonNumericConstStrings);
assertType('lowercase-string&non-falsy-string', $maybeNonNumericConstStrings.$i);

assertType('lowercase-string&non-falsy-string&uppercase-string', $i.$maybeFloatConstStrings); // could be 'lowercase-string&non-falsy-string&numeric-string'
assertType('lowercase-string&non-falsy-string&numeric-string&uppercase-string', $i.$maybeFloatConstStrings);
assertType('lowercase-string&non-falsy-string&uppercase-string', $maybeFloatConstStrings.$i);

assertType('lowercase-string&non-empty-string&numeric-string&uppercase-string', $i.$bool);
Expand All @@ -68,7 +68,7 @@ public function foo(
assertType('non-falsy-string&numeric-string&uppercase-string', $float.$positiveInt);
assertType('non-falsy-string&uppercase-string', $float.$negativeInt);
assertType('non-falsy-string&uppercase-string', $float.$i);
assertType('non-falsy-string&uppercase-string', $i.$float); // could be 'non-falsy-string&numeric-string&uppercase-string'
assertType('non-falsy-string&uppercase-string', $i.$float);
assertType('non-falsy-string', $numericString.$float);
assertType('non-falsy-string', $numericString.$maybeFloatConstStrings);

Expand Down
Loading