X Tutup
Skip to content

Allow goto definition from first class callables#3025

Open
przepompownia wants to merge 1 commit intophpactor:masterfrom
przepompownia:fcc-gotodef
Open

Allow goto definition from first class callables#3025
przepompownia wants to merge 1 commit intophpactor:masterfrom
przepompownia:fcc-gotodef

Conversation

@przepompownia
Copy link
Contributor

@przepompownia przepompownia commented Mar 2, 2026

Fix: #2975

@przepompownia
Copy link
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
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
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
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?

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

X Tutup