Skip to content

fix(diagnostics): resolve callable return type for call-result invocations#189

Open
calebdw wants to merge 2 commits into
PHPantom-dev:mainfrom
calebdw:calebdw/push-oqxkuqnpsozq
Open

fix(diagnostics): resolve callable return type for call-result invocations#189
calebdw wants to merge 2 commits into
PHPantom-dev:mainfrom
calebdw:calebdw/push-oqxkuqnpsozq

Conversation

@calebdw

@calebdw calebdw commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

When a function/method returns a callable type and the return value is immediately invoked — e.g. makeCallable('1', '2')('test') — the LSP previously used the outer function's parameter signature for the inner invocation. This caused:

  • False argument_count_mismatch diagnostics (expected 2 args, got 1)
  • Wrong inlay hint parameter names ($a instead of $c)

The fix intercepts CallExpr resolution: after resolving the inner callee, check if its return type is callable. If so, use the callable's parameter signature instead of the callee's own params.

Handles:

  • Typed callable: callable(string): string — extracts params
  • Bare callable/Closure: flags accepts_any_args to suppress diagnostics
  • Union types and nullable: recursively checks branches

Closes #184

@calebdw calebdw force-pushed the calebdw/push-oqxkuqnpsozq branch from e10807d to 7e8284e Compare July 4, 2026 01:34
@codecov-commenter

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 36.95652% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/completion/call_resolution.rs 36.95% 29 Missing ⚠️

📢 Thoughts on this report? Let us know!

@calebdw calebdw force-pushed the calebdw/push-oqxkuqnpsozq branch 2 times, most recently from 23ac09e to 4a4e9bb Compare July 4, 2026 03:07
calebdw and others added 2 commits July 3, 2026 23:07
…tions

When a function/method returns a callable type and the return value is
immediately invoked — e.g. `makeCallable('1', '2')('test')` — the LSP
previously used the outer function's parameter signature for the inner
invocation. This caused:
- False argument_count_mismatch diagnostics (expected 2 args, got 1)
- Wrong inlay hint parameter names ($a instead of $c)

The fix intercepts CallExpr resolution: after resolving the inner
callee, check if its return type is callable. If so, use the callable's
parameter signature instead of the callee's own params.

Handles:
- Typed callable: `callable(string): string` — extracts params
- Bare callable/Closure: flags accepts_any_args to suppress diagnostics
- Union types and nullable: recursively checks branches

Closes PHPantom-dev#184
Signed-off-by: Anders Jenbo <anders@jenbo.dk>
@calebdw calebdw force-pushed the calebdw/push-oqxkuqnpsozq branch from 885d442 to 8fc3672 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.

chained method calls evaluate to first called methods signature

3 participants