Skip to content

fix(diagnostics): resolve literal types for argument type checking - #192

Merged
AJenbo merged 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-txqrkspmkoww
Jul 4, 2026
Merged

AJenbo merged 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-txqrkspmkoww

Conversation

@calebdw

@calebdw calebdw commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Fixes #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).

@codecov-commenter

codecov-commenter commented Jul 4, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/diagnostics/type_errors.rs 94.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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
AJenbo force-pushed the calebdw/push-txqrkspmkoww branch from 83b9a6e to fa1deec Compare July 4, 2026 03:59
@AJenbo
AJenbo merged commit 31cc5e2 into PHPantom-dev:main Jul 4, 2026
7 checks passed
@calebdw
calebdw deleted the calebdw/push-txqrkspmkoww branch July 4, 2026 04:06
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.

Bogus error on Eloquent orderBy()

3 participants