Repository navigation
fix(diagnostics): resolve literal types for argument type checking - #192
Merged
Merged
Conversation
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
calebdw
force-pushed
the
calebdw/push-txqrkspmkoww
branch
from
July 4, 2026 03:07
f0bcbd9 to
83b9a6e
Compare
Fixes PHPantom-dev#180 — string/int/float literal expressions passed as arguments are now narrowed to their precise literal type (e.g. `'desc'` becomes `PhpType::Literal("'desc'")`) instead of the widened base type (`string`). This allows literal values to correctly match PHPDoc literal-union parameter types like `'asc'|'desc'`. Also fixes `is_string_subtype()` and `is_int_subtype()` to handle `PhpType::Union` — a union of string/int literals (e.g. `'asc'|'desc'`) is now recognised as a string/int subtype, allowing PHPDoc `@param` annotations with literal unions to properly override native scalar type hints. The narrowing is applied only in the diagnostic argument-collection path (not in general variable resolution) to avoid changing inferred types for array shapes and list element tracking. Includes 8 new integration tests covering correct and incorrect string, integer, and float literals against literal-union parameters, plus precise numeric-string checking (`'42'` passes, `'hello'` is flagged). Closes PHPantom-dev#180 Signed-off-by: Anders Jenbo <[email protected]>
AJenbo
force-pushed
the
calebdw/push-txqrkspmkoww
branch
from
July 4, 2026 03:59
83b9a6e to
fa1deec
Compare
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.
Fixes #180 — string/int/float literal expressions passed as arguments are now narrowed to their precise literal type (e.g.
'desc'becomesPhpType::Literal("'desc'")) instead of the widened base type (string). This allows literal values to correctly match PHPDoc literal-union parameter types like'asc'|'desc'.Also fixes
is_string_subtype()andis_int_subtype()to handlePhpType::Union— a union of string/int literals (e.g.'asc'|'desc') is now recognised as a string/int subtype, allowing PHPDoc@paramannotations with literal unions to properly override native scalar type hints.The narrowing is applied only in the diagnostic argument-collection path (not in general variable resolution) to avoid changing inferred types for array shapes and list element tracking.
Includes 8 new integration tests covering correct and incorrect string, integer, and float literals against literal-union parameters, plus precise numeric-string checking (
'42'passes,'hello'is flagged).