Include argument index in dumpType message to preserve argument order#5503
Merged
ondrejmirtes merged 1 commit intophpstan:2.1.xfrom Apr 21, 2026
Merged
Conversation
- When multiple arguments are passed to `dumpType()`, `dumpNativeType()`, or `dumpPhpDocType()`, messages now include `#N` (e.g. "Dumped type phpstan#1: int") to maintain stable argument ordering through the alphabetical error sort - Single-argument calls retain the original "Dumped type: ..." format - Fixed all three dump rules: DumpTypeRule, DumpNativeTypeRule, DumpPhpDocTypeRule - Updated existing multi-arg test expectations to match new format
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.
Summary
When
PHPStan\dumpType()is called with multiple arguments, the dumped types were displayed in alphabetical order by message rather than in argument order. This happened becauseAnalyserResult::getErrors()sorts errors on the same line alphabetically by message.The fix adds an argument index (
#1,#2, ...) to the message when multiple arguments are passed, ensuring the sort produces the correct argument order.Changes
src/Rules/Debug/DumpTypeRule.php— include#Nin message format whencount($args) > 1src/Rules/Debug/DumpNativeTypeRule.php— same fix fordumpNativeType()src/Rules/Debug/DumpPhpDocTypeRule.php— same fix fordumpPhpDocType()"Dumped type #N: ..."formatProbed analogous cases:
dumpNativeType()— had the same bug, fixeddumpPhpDocType()— had the same bug, fixedRoot cause
AnalyserResult::getErrors()andRuleTestCase::analyse()both sort errors by[file, line, message]. When multipledumpTypeerrors appear on the same line, the alphabetical sort on the message string reorders them, losing the original argument order. For example,dumpType($int, $bool)would show "Dumped type: bool" before "Dumped type: int<0, 100>" because'b' < 'i'.By including
#1,#2, etc. in the message, the sort key becomes"Dumped type #1: ..."vs"Dumped type #2: ...", which preserves argument order regardless of the type descriptions.Test
tests/PHPStan/Rules/Debug/data/bug-14508.php— regression test for the reported issue withdumpType()tests/PHPStan/Rules/Debug/data/bug-14508-native.php— analogous test fordumpNativeType()tests/PHPStan/Rules/Debug/data/bug-14508-phpdoc.php— analogous test fordumpPhpDocType()$intand$boolare passed to the dump function, the int type is reported as#1and bool as#2Fixes phpstan/phpstan#14508