Skip to content

UnresolvableTypeHelper: early return type traversal#4671

Merged
ondrejmirtes merged 1 commit into
phpstan:2.1.xfrom
staabm:eff
Dec 26, 2025
Merged

UnresolvableTypeHelper: early return type traversal#4671
ondrejmirtes merged 1 commit into
phpstan:2.1.xfrom
staabm:eff

Conversation

@staabm

@staabm staabm commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

analog #4669

@ondrejmirtes ondrejmirtes merged commit f0b3820 into phpstan:2.1.x Dec 26, 2025
634 of 640 checks passed
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you!

@staabm staabm deleted the eff branch December 26, 2025 18:37
phpstan-bot added a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 2, 2026
Explains, in response to review, that the toggle gate mirrors
StringType::toArrayKey() and is required to avoid the bug phpstan#4671
false positive (isset on a string-keyed array with a (string) $int offset).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 2, 2026
- `IntegerType::toString()` now returns `string&decimal-int-string` instead of `string&lowercase-string&uppercase-string&numeric-string`. Casting an int to string always yields the canonical decimal representation (no leading `+`/zeros, no exponent), which is exactly `decimal-int-string` (a subtype of numeric/lowercase/uppercase, so this is strictly more precise).
- `IntegerRangeType::toString()` mirrors the same change for the non-finite branches, keeping `non-falsy-string` for ranges that exclude `0`.
- `(string) bool` and `(string) constant-int` were already precise (`''|'1'` / constant strings), so no change was needed there.
- Fixed an adjacent inconsistency: `IntersectionType::toArrayKey()` coerced `decimal-int-string` to `int` unconditionally, ignoring `ReportUnsafeArrayStringKeyCastingToggle`, while `StringType::toArrayKey()` respects it. This made `[$decimalIntString => 1]` infer `array<int, 1>` by default even though `[$plainString => 1]` stays `array<string, 1>`, and reintroduced the bug phpstan#4671 false positive (`isset($stringKeyedArray[(string) $int])`). The decimal branch now stays a string key unless the toggle is `PREVENT`, matching `StringType`.
- Updated `decimal-int-string.php` to reflect the corrected lenient default (`[$s => 1]` is `array<decimal-int-string, 1>`), and refreshed the expected types in the cast/array-key inference tests that now report the more precise `decimal-int-string`.
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 2, 2026
Explains, in response to review, that the toggle gate mirrors
StringType::toArrayKey() and is required to avoid the bug phpstan#4671
false positive (isset on a string-keyed array with a (string) $int offset).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 2, 2026
- `IntegerType::toString()` now returns `string&decimal-int-string` instead of `string&lowercase-string&uppercase-string&numeric-string`. Casting an int to string always yields the canonical decimal representation (no leading `+`/zeros, no exponent), which is exactly `decimal-int-string` (a subtype of numeric/lowercase/uppercase, so this is strictly more precise).
- `IntegerRangeType::toString()` mirrors the same change for the non-finite branches, keeping `non-falsy-string` for ranges that exclude `0`.
- `(string) bool` and `(string) constant-int` were already precise (`''|'1'` / constant strings), so no change was needed there.
- Fixed an adjacent inconsistency: `IntersectionType::toArrayKey()` coerced `decimal-int-string` to `int` unconditionally, ignoring `ReportUnsafeArrayStringKeyCastingToggle`, while `StringType::toArrayKey()` respects it. This made `[$decimalIntString => 1]` infer `array<int, 1>` by default even though `[$plainString => 1]` stays `array<string, 1>`, and reintroduced the bug phpstan#4671 false positive (`isset($stringKeyedArray[(string) $int])`). The decimal branch now stays a string key unless the toggle is `PREVENT`, matching `StringType`.
- Updated `decimal-int-string.php` to reflect the corrected lenient default (`[$s => 1]` is `array<decimal-int-string, 1>`), and refreshed the expected types in the cast/array-key inference tests that now report the more precise `decimal-int-string`.
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 2, 2026
Explains, in response to review, that the toggle gate mirrors
StringType::toArrayKey() and is required to avoid the bug phpstan#4671
false positive (isset on a string-keyed array with a (string) $int offset).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
phpstan-bot added a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 3, 2026
The toArrayKey() coercion of decimal-int-string keys is an unrelated
concern tracked separately in phpstan/phpstan#14758, so it is dropped
from this PR. Removing the special case lets decimal-int-string fall
through to the numeric-string branch (it is a numeric-string), yielding
int|decimal-int-string just like any other numeric string. This keeps
the bug phpstan#4671 isset regression test green without implementing the
toggle-gated precision behavior, which belongs in #14758.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 4, 2026
- `IntegerType::toString()` now returns `string&decimal-int-string` instead of `string&lowercase-string&uppercase-string&numeric-string`. Casting an int to string always yields the canonical decimal representation (no leading `+`/zeros, no exponent), which is exactly `decimal-int-string` (a subtype of numeric/lowercase/uppercase, so this is strictly more precise).
- `IntegerRangeType::toString()` mirrors the same change for the non-finite branches, keeping `non-falsy-string` for ranges that exclude `0`.
- `(string) bool` and `(string) constant-int` were already precise (`''|'1'` / constant strings), so no change was needed there.
- Fixed an adjacent inconsistency: `IntersectionType::toArrayKey()` coerced `decimal-int-string` to `int` unconditionally, ignoring `ReportUnsafeArrayStringKeyCastingToggle`, while `StringType::toArrayKey()` respects it. This made `[$decimalIntString => 1]` infer `array<int, 1>` by default even though `[$plainString => 1]` stays `array<string, 1>`, and reintroduced the bug phpstan#4671 false positive (`isset($stringKeyedArray[(string) $int])`). The decimal branch now stays a string key unless the toggle is `PREVENT`, matching `StringType`.
- Updated `decimal-int-string.php` to reflect the corrected lenient default (`[$s => 1]` is `array<decimal-int-string, 1>`), and refreshed the expected types in the cast/array-key inference tests that now report the more precise `decimal-int-string`.
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 4, 2026
Explains, in response to review, that the toggle gate mirrors
StringType::toArrayKey() and is required to avoid the bug phpstan#4671
false positive (isset on a string-keyed array with a (string) $int offset).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 4, 2026
The toArrayKey() coercion of decimal-int-string keys is an unrelated
concern tracked separately in phpstan/phpstan#14758, so it is dropped
from this PR. Removing the special case lets decimal-int-string fall
through to the numeric-string branch (it is a numeric-string), yielding
int|decimal-int-string just like any other numeric string. This keeps
the bug phpstan#4671 isset regression test green without implementing the
toggle-gated precision behavior, which belongs in #14758.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 4, 2026
- `IntegerType::toString()` now returns `string&decimal-int-string` instead of `string&lowercase-string&uppercase-string&numeric-string`. Casting an int to string always yields the canonical decimal representation (no leading `+`/zeros, no exponent), which is exactly `decimal-int-string` (a subtype of numeric/lowercase/uppercase, so this is strictly more precise).
- `IntegerRangeType::toString()` mirrors the same change for the non-finite branches, keeping `non-falsy-string` for ranges that exclude `0`.
- `(string) bool` and `(string) constant-int` were already precise (`''|'1'` / constant strings), so no change was needed there.
- Fixed an adjacent inconsistency: `IntersectionType::toArrayKey()` coerced `decimal-int-string` to `int` unconditionally, ignoring `ReportUnsafeArrayStringKeyCastingToggle`, while `StringType::toArrayKey()` respects it. This made `[$decimalIntString => 1]` infer `array<int, 1>` by default even though `[$plainString => 1]` stays `array<string, 1>`, and reintroduced the bug phpstan#4671 false positive (`isset($stringKeyedArray[(string) $int])`). The decimal branch now stays a string key unless the toggle is `PREVENT`, matching `StringType`.
- Updated `decimal-int-string.php` to reflect the corrected lenient default (`[$s => 1]` is `array<decimal-int-string, 1>`), and refreshed the expected types in the cast/array-key inference tests that now report the more precise `decimal-int-string`.
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 4, 2026
Explains, in response to review, that the toggle gate mirrors
StringType::toArrayKey() and is required to avoid the bug phpstan#4671
false positive (isset on a string-keyed array with a (string) $int offset).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
staabm pushed a commit to phpstan-bot/phpstan-src that referenced this pull request Jun 4, 2026
The toArrayKey() coercion of decimal-int-string keys is an unrelated
concern tracked separately in phpstan/phpstan#14758, so it is dropped
from this PR. Removing the special case lets decimal-int-string fall
through to the numeric-string branch (it is a numeric-string), yielding
int|decimal-int-string just like any other numeric string. This keeps
the bug phpstan#4671 isset regression test green without implementing the
toggle-gated precision behavior, which belongs in #14758.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants