Skip to content

Allow goto definition from first class callables#3025

Merged
dantleech merged 1 commit intophpactor:masterfrom
przepompownia:fcc-gotodef
Apr 18, 2026
Merged

Allow goto definition from first class callables#3025
dantleech merged 1 commit intophpactor:masterfrom
przepompownia:fcc-gotodef

Conversation

@przepompownia
Copy link
Copy Markdown
Contributor

@przepompownia przepompownia commented Mar 2, 2026

Fix: #2975

@przepompownia
Copy link
Copy Markdown
Contributor Author

przepompownia commented Mar 2, 2026

This is rather an early experiment that started to work only on

<?php

function foo(): int {}

foo();
$f = foo(...);

but doesn't work on methods yet.

For now, I am following the current behaviour on a real instance and not sure if I should include all needed tests in GotoDefinitionHandlerTest or somewhere else.

@przepompownia przepompownia force-pushed the fcc-gotodef branch 4 times, most recently from a81a42e to f68d34c Compare March 3, 2026 21:09
@przepompownia przepompownia marked this pull request as ready for review March 3, 2026 21:36
@przepompownia
Copy link
Copy Markdown
Contributor Author

przepompownia commented Mar 3, 2026

The path through WorseReflection is, as usual, very complex, and I easily get lost there. On the other hand, for comparison, I have the path of the "normal" call expression and I'm trying to figure out the differences.

This way, I tested what happens (in NodeContextFromMemberAccess) when we return a MethodCallContext for FCC: gotdef works, but we get the wrong type (the one returned by the method). It turns out that a MethodCallContext with the FCC type passes both the old and new tests. Even if this change is based on guesswork, I hope this is a good starting point for review.

);

if (NodeUtil::isFirstClassCallable($node->parent)) {
return $methodCallContext->withType(new ClosureType(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would imply that th method call returns a closure - which is not the case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understood correctly: would a simple method call have a chance of falling into this condition (uncaught by any test)? For example, hover would show closure type?

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Phpactor Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: bb90d5f Previous: 77f9ff9 Ratio
ConfigLoaderBench::benchJsonPlainPhp 0.01542590998043056 ms (± 7.04%) 0.007386810176125254 ms (± 3.09%) 2.09

This comment was automatically generated by workflow using github-action-benchmark.

@dantleech dantleech merged commit 6a46d38 into phpactor:master Apr 18, 2026
11 checks passed
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.

First class callable expressions: support go to definition and references

2 participants