Skip to content

Repeated calls keep their conditional return type - #578

Merged
AJenbo merged 2 commits into
PHPantom-dev:mainfrom
giuseppe-esposito-87:fix-conditional-call-seed
Nov 23, 2026
Merged

AJenbo merged 2 commits into
PHPantom-dev:mainfrom
giuseppe-esposito-87:fix-conditional-call-seed

Conversation

@giuseppe-esposito-87

Copy link
Copy Markdown
Contributor

🤖 This was written by an AI agent on behalf of @giuseppe-esposito-87 (claude-code/claude-opus-5-5).

A call without arguments that appears a second time in the same method, or is checked in a condition, now gets the branch its conditional return type picks. Before, the repeat fell back to the wider declared type, so passing it on was reported.

/** @return ($flag is true ? Generated : string) */
public function make($flag = false): string|Generated {}

takeString($maker->make());   // string
takeString($maker->make());   // string, was string|Generated and reported
  • Conditionals decided by the receiver's class template, by $this, or through an inherited method resolve the same way on the repeat.
  • A call whose type the condition cannot decide keeps its declared type, as before.

Drupal's $url->toString() called twice in one method is a common case once #577 gives it a conditional return type.

Checked

analyze on Drupal core 11.4 and on a site with the redirect and flag modules reports exactly what main reports.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, examples/). Not applicable: no documented behaviour changes.
  • I have updated the config schema (config-schema.json). Not applicable: this PR adds or changes no setting.
  • I have added/updated tests to cover my changes
  • If I used AI tools, I have reviewed what they produced and can explain
    the changes and why they are needed.
  • I have read through any AI-generated text, especially documentation,
    the changelog, and other user-facing content, and removed or corrected
    anything inaccurate, unclear, or unnecessary.

@codecov-commenter

codecov-commenter commented Nov 22, 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 98.75000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ne/variable/forward_walk/cond_narrowing/seeding.rs 96.42% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AJenbo AJenbo added this to the Sprint 9 milestone Nov 23, 2026
giuseppe-esposito-87 and others added 2 commits November 23, 2026 02:07
A call statement records its argument-less call arguments in the walker's
scope under their written form, and a check does the same for the call it
tests. The recorded type was the method's declared return type, so a later
occurrence of the same call read that wider type instead of the branch the
conditional return type picks. Record the conditional decided with every
parameter at its default, as a call without arguments resolves it.

Assisted-by: claude-code/claude-opus-5-5
Seeding a condition's argument-less call fully resolved its declared
type only to throw it away when the method had no conditional return.
Ask a cheap predicate (method_return_is_conditional /
is_conditional_call_key) instead, share the receiver lookup with
resolve_member_key_type, and cover a reassigned receiver and mixing
make() with make(true).

Seed the conditional call from what it returns once its receiver is
set, like the other call keys, so a `?->` check leaves no `null` on
the plain call that repeats it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AJenbo
AJenbo force-pushed the fix-conditional-call-seed branch from 208bc09 to 4ec6088 Compare November 23, 2026 01:54
@AJenbo
AJenbo merged commit 3746901 into PHPantom-dev:main Nov 23, 2026
15 checks passed
@AJenbo

AJenbo commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks

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.

3 participants