UnresolvableTypeHelper: early return type traversal#4671
Merged
Conversation
Member
|
Thank you! |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
analog #4669