Skip to content

feat(diagnostics): detect declare(strict_types=1) for stricter type checking - #193

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

feat(diagnostics): detect declare(strict_types=1) for stricter type checking#193
AJenbo merged 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-mtpqxwvyzmrq

Conversation

@calebdw

@calebdw calebdw commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Reads declare(strict_types=1) from the calling file and tightens call-argument type checking accordingly.

Under strict types, PHP's implicit scalar call-time coercions are now flagged in type_mismatch_argument diagnostics:

  • int/float -> string
  • numeric-string -> int/float
  • numeric-string literals -> integer range parameters when strict types are enabled

The int -> float exception is preserved to match PHP runtime semantics. Concatenation and other non-call contexts are unaffected because this change is scoped to call argument diagnostics only.

The implementation is hardened by preserving literal kinds for int, float, and string values instead of flattening literals to raw strings. That avoids cases like 1.0 being misclassified as an integer and keeps PHP numeric syntaxes such as underscores, scientific notation, and hex/binary/octal integers meaningful during compatibility checks.

Includes focused tests for:

  • strict int -> string mismatches
  • strict float -> string mismatches
  • non-strict numeric coercion baselines
  • strict and non-strict numeric-string literal behavior
  • integer range checks for decimal and hex integer literals
  • rejection of float literals for integer ranges
  • preserved int -> float behavior
  • concatenation remaining unaffected

Closes #203

@calebdw
calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch from 39a1369 to 3da1862 Compare July 4, 2026 03:21
@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 74.91639% with 75 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/php_type.rs 83.75% 32 Missing ⚠️
src/diagnostics/type_errors.rs 66.21% 25 Missing ⚠️
src/completion/types/conditional.rs 30.43% 16 Missing ⚠️
src/completion/variable/forward_walk.rs 33.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@calebdw
calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch 3 times, most recently from 41f2724 to 7d2e004 Compare July 7, 2026 03:36
@calebdw
calebdw requested a review from AJenbo July 7, 2026 15:47
@calebdw
calebdw marked this pull request as draft July 7, 2026 17:02
calebdw added a commit to calebdw/phpantom_lsp that referenced this pull request Jul 7, 2026
…hecking

Read declare(strict_types=1) from the calling file when checking
call argument compatibility so PHP's strict scalar call semantics are
reflected in type_mismatch_argument diagnostics.

This hardens the implementation by preserving literal kinds for int,
float, and string values instead of flattening them to raw strings.
That keeps float literals from being misclassified as ints and lets
numeric literals retain PHP-specific forms such as underscores,
scientific notation, and hex/binary/octal integers during checks.

Non-strict mode continues to allow PHP's call-time scalar coercions
such as int/float to string and numeric-string to int/float, while
strict mode flags those mismatches. Concatenation and other non-call
contexts are unchanged.

Closes PHPantom-dev#193
@calebdw
calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch from 7d2e004 to 991a13e Compare July 7, 2026 17:36
calebdw added a commit to calebdw/phpantom_lsp that referenced this pull request Jul 7, 2026
…hecking

Read declare(strict_types=1) from the calling file when checking
call argument compatibility so PHP's strict scalar call semantics are
reflected in type_mismatch_argument diagnostics.

This hardens the implementation by preserving literal kinds for int,
float, and string values instead of flattening them to raw strings.
That keeps float literals from being misclassified as ints and lets
numeric literals retain PHP-specific forms such as underscores,
scientific notation, and hex/binary/octal integers during checks.

Non-strict mode continues to allow PHP's call-time scalar coercions
such as int/float to string and numeric-string to int/float, while
strict mode flags those mismatches. Concatenation and other non-call
contexts are unchanged.

Closes PHPantom-dev#193
@calebdw
calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch from 991a13e to 0b0ad70 Compare July 7, 2026 17:42
calebdw added a commit to calebdw/phpantom_lsp that referenced this pull request Jul 7, 2026
…hecking

Read declare(strict_types=1) from the calling file when checking
call argument compatibility so PHP's strict scalar call semantics are
reflected in type_mismatch_argument diagnostics.

This hardens the implementation by preserving literal kinds for int,
float, and string values instead of flattening them to raw strings.
That keeps float literals from being misclassified as ints and lets
numeric literals retain PHP-specific forms such as underscores,
scientific notation, and hex/binary/octal integers during checks.

Non-strict mode continues to allow PHP's call-time scalar coercions
such as int/float to string and numeric-string to int/float, while
strict mode flags those mismatches. Concatenation and other non-call
contexts are unchanged.

Closes PHPantom-dev#193
@calebdw
calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch from 0b0ad70 to fa72ea3 Compare July 7, 2026 17:46
calebdw added a commit to calebdw/phpantom_lsp that referenced this pull request Jul 7, 2026
…hecking

Read declare(strict_types=1) from the calling file when checking
call argument compatibility so PHP's strict scalar call semantics are
reflected in type_mismatch_argument diagnostics.

This hardens the implementation by preserving literal kinds for int,
float, and string values instead of flattening them to raw strings.
That keeps float literals from being misclassified as ints and lets
numeric literals retain PHP-specific forms such as underscores,
scientific notation, and hex/binary/octal integers during checks.

Non-strict mode continues to allow PHP's call-time scalar coercions
such as int/float to string and numeric-string to int/float, while
strict mode flags those mismatches. Concatenation and other non-call
contexts are unchanged.

Closes PHPantom-dev#193
@calebdw
calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch from fa72ea3 to e742c72 Compare July 7, 2026 17:47
@calebdw
calebdw marked this pull request as ready for review July 7, 2026 17:47
@calebdw
calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch 2 times, most recently from b653167 to febc364 Compare July 7, 2026 21:17
checking

Read declare(strict_types=1) from the calling file when checking
call argument compatibility so PHP's strict scalar call semantics are
reflected in type_mismatch_argument diagnostics.

This hardens the implementation by preserving literal kinds for int,
float, and string values instead of flattening them to raw strings.
That keeps float literals from being misclassified as ints and lets
numeric literals retain PHP-specific forms such as underscores,
scientific notation, and hex/binary/octal integers during checks.

Non-strict mode continues to allow PHP's call-time scalar coercions
such as int/float to string and numeric-string to int/float, while
strict mode flags those mismatches. Concatenation and other non-call
contexts are unchanged.

Closes PHPantom-dev#203
@AJenbo
AJenbo force-pushed the calebdw/push-mtpqxwvyzmrq branch from febc364 to a26d5df Compare July 8, 2026 23:31
@AJenbo
AJenbo merged commit b983f6f into PHPantom-dev:main Jul 8, 2026
6 of 7 checks passed
@calebdw
calebdw deleted the calebdw/push-mtpqxwvyzmrq branch July 9, 2026 12:13
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.

[Laravel] Argument 2 ($type) expects "select" got 'select'

3 participants