Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 7, 2025

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

I don't like this fix, it's very one-off. There are many things in expressions that aren't assigns, that would still be broken.

As I said, this either needs virtual nodes, or ambitious refactoring.

@staabm
Copy link
Contributor Author

staabm commented Sep 7, 2025

As I said, this either needs virtual nodes

so you mean e.g. a CallLikeArg virtual node so we would hook a rule onto every arg and rework all callers of FunctionCallParametersCheck::check?

@staabm
Copy link
Contributor Author

staabm commented Sep 7, 2025

ambitious refactoring.

this would mean something like a new MutatingScope->enterCallLike() method, right?

@ondrejmirtes
Copy link
Member

The args need to be considered together. Looking at this the problem goes really deep and it might not be so easy to fix. Looking at places where FunctionCallParametersCheck is called, ParametersAcceptorSelector is called:

ParametersAcceptorSelector::selectFromArgs(
	$scope,
	$node->getArgs(),
	$constructorReflection->getVariants(),
	$constructorReflection->getNamedArgumentsVariants(),
)

The considered types inside are going to be wrong too because we're only passing along a single scope.

And of course this method is one of the most used methods across the codebase. Changing that would have ripple effects across the ecosystem so we can't do that now.

Also, FunctionCallParametersCheck::check() accepts a single scope and $funcCall where it gets its arguments. This might be easier to fix. We need a new virtual node for each of Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $funcCall. And inside of them we need $args to be a new virtual node array, something like Argument[]. The Argument would contain Scope too.

The proper Argument virtual nodes objects would need to be made inside NodeScopeResolver::processArgs().

@ondrejmirtes
Copy link
Member

So my conclusion is that we can fix FunctionCallParametersCheck::check() now and it might work in most of the cases.

If people do assignment shenanigans and they have wrong generics resolved because of that, it's not so easy to fix.

@ondrejmirtes
Copy link
Member

this would mean something like a new MutatingScope->enterCallLike() method, right?

No, I meant the really ambitious refactoring that I described here #4237 (comment) and that I don't know how the code should look like after yet 😅

@staabm
Copy link
Contributor Author

staabm commented Sep 7, 2025

Also, FunctionCallParametersCheck::check() accepts a single scope and $funcCall where it gets its arguments. This might be easier to fix. We need a new virtual node for each of Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $funcCall. And inside of them we need $args to be a new virtual node array, something like Argument[]. The Argument would contain Scope too.

The proper Argument virtual nodes objects would need to be made inside NodeScopeResolver::processArgs().

While this makes sense it sounds to be a big undertaking to support things I don't like to use at all myself (assigns in expressions).

I prefer to spend my time somewhere on something more valuable

@ondrejmirtes
Copy link
Member

Yeah, sure 👍

Keeping this open because the tests are valuable.

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.

Type of variable assigned in a parameter list is not preserved in following parameters Type lost when assigning variable in method argument
2 participants