Skip to content

Fix callable typecast arguments with untyped or union parameters - #578

Open
dajiaohuang wants to merge 1 commit into
cycle:2.xfrom
dajiaohuang:repostew/typecast-callable-args-20261015
Open

dajiaohuang wants to merge 1 commit into
cycle:2.xfrom
dajiaohuang:repostew/typecast-callable-args-20261015

Conversation

@dajiaohuang

Copy link
Copy Markdown
Contributor

🔍 What was changed

Inspect the optional second callable parameter as a ReflectionType, and inject the database only for an exact named DatabaseInterface type. Keep the existing explicit-argument calling convention for other types. Remove the two obsolete Psalm suppressions for the old expression.

🤔 Why?

Fixes #574. A supported three-element typecast rule with an untyped or union-typed second argument prevents getRepository(...)->findByPK() from loading the entity. A single-parameter callable with an empty argument list also raises an undefined-index warning. The regression uses real repository loading and synthetic SQLite rows, with a typed control.

📝 Checklist

  • Regression tests added to the shared driver suite (untyped, union, single parameter, typed control).
  • New cases fail on the base: two raw Errors and an undefined-index warning; pass with this change (4 tests, 40 assertions on SQLite/PHP 8.3.35).
  • Unit suite: 383 tests, 1,211 assertions passed.
  • SQLite suite with both independent typecast/collection fixes: 1,321 tests, 30,354 assertions; upstream 10 skipped / 3 incomplete unchanged.
  • Composer validate --strict; changed-file code style; git diff --check.

Static analysis is not green on the base: Psalm 6.20.0 reports 12 errors before changes. The combined fixes report 11 pre-existing errors outside the changed paths (HasMany, ToOneTrait, Select); the typecast null-reference error is removed. No suppressions were added. Other PHP versions and MySQL/PostgreSQL/SQLServer suites were not run locally.

📃 Documentation

No API/default changes; callable rules already support explicit arguments.

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.

Typecast rule [class, method, args] crashes with a raw Error when the callable's 2nd parameter is untyped or a union type

1 participant