Skip to content

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

Open
calebdw wants to merge 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-mtpqxwvyzmrq
Open

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

Conversation

@calebdw

@calebdw calebdw commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Important

Depends on #192

Scans the calling file for declare(strict_types=1) and tightens
argument type checking accordingly. Under strict types, implicit
scalar coercions that PHP normally allows are now flagged:

  • int/float → string (TypeError in strict mode)
  • numeric-string → int/float (string-to-number coercion forbidden)

The int → float exception is preserved, matching PHP's runtime
semantics. Concatenation (.) is unaffected since it is not a
scalar type declaration context.

The strict_types flag is detected once per file inside the
with_parsed_program closure and threaded through
is_type_compatible to the affected MAYBE rules.

Includes 7 new integration tests covering: int→string flagging,
int→float exception, numeric-string→int flagging, int literal→string,
float→string, concatenation unaffected, and the non-strict baseline.

@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 57.77778% with 19 lines in your changes missing coverage. Please review.

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

📢 Thoughts on this report? Let us know!

…hecking

Scans the calling file for `declare(strict_types=1)` and tightens
argument type checking accordingly.  Under strict types, implicit
scalar coercions that PHP normally allows are now flagged:

  - int/float → string (TypeError in strict mode)
  - numeric-string → int/float (string-to-number coercion forbidden)

The int → float exception is preserved, matching PHP's runtime
semantics.  Concatenation (`.`) is unaffected since it is not a
scalar type declaration context.

The `strict_types` flag is detected once per file inside the
`with_parsed_program` closure and threaded through
`is_type_compatible` to the affected MAYBE rules.

Includes 7 new integration tests covering: int→string flagging,
int→float exception, numeric-string→int flagging, int literal→string,
float→string, concatenation unaffected, and the non-strict baseline.
@calebdw calebdw force-pushed the calebdw/push-mtpqxwvyzmrq branch from 3da1862 to bbe035f Compare July 4, 2026 04:07
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.

2 participants