Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving deep mixins #11082

Draft
wants to merge 20 commits into
base: 5.x
Choose a base branch
from
Draft

Conversation

issidorov
Copy link
Contributor

No description provided.

Problems:
```
1) Psalm\Tests\MixinsDeepTest::testValidCode with data set "NamedMixinsWithoutT_WithObjectMethods"
Psalm\Exception\CodeException: MixedAssignment - src/somefile.php:22:1 - Unable to determine the type that $a is being assigned to

2) Psalm\Tests\MixinsDeepTest::testValidCode with data set "NamedMixinsWithT_WithObjectMethods"
Psalm\Exception\CodeException: MixedAssignment - src/somefile.php:37:1 - Unable to determine the type that $a is being assigned to
```
Creating the `handleMixins` method is necessary so that it can be used
in the future for recursive calls from the `handleTemplatedMixins` and
`handleRegularMixins` methods.
A recursive call to this method will allow us to search the depth of
the mixins.
Deep processing of mixins is planned to be done through recursive calls
to the `handleMixins` method.

To realise this, we need this method to return information that it has
managed to find the desired method.

Therefore, the `method_exists` variable was declared to make it clear
that the method was found.

The existing `naive_method_exists` variable is not suitable for us,
because it is not set to `true` if the method is magic (pseudo).
Extracting variables defined in the "if" statement block to the upper lines.

All this is necessary to use these variables for further searching
at the next deeper level of mixins, passing them to the `handleMixins`
method, performing recursion in this way.

Extracting code from:
```
if ($codebase->methods->methodExists(...)) {
    // here extracted
}
```
Problems:
```
1) Psalm\Tests\MixinsDeepTest::testValidCode with data set "TemplatedMixins_WithObjectMethods"
Psalm\Exception\CodeException: MixedAssignment - src/somefile.php:25:1 - Unable to determine the type that $a is being assigned to
```
Extracting code from:
```
if ($codebase->methods->methodExists(...)) {
    // here extracted
} elseif (...) {
    // here extracted
}
```
Comparing the `handleTemplatedMixins` and `handleRegularMixins` methods,
we can notice that in the `handleRegularMixins` method the `fq_class_name`
variable is overridden if the sought method is found in the mixin.

Whereas in the `handleTemplatedMixins` method this does not happen.
And I think therein lies the error.

Since the `class_storage` variable can be overridden in the
`handleTemplatedMixins` method, the `fq_class_name` variable should
also be overridden.
Problems:
```
1) Psalm\Tests\MixinsDeepTest::testValidCode with data set "NamedMixinsWithoutT_WithStaticMethods"
Psalm\Exception\CodeException: MixedAssignment - src/somefile.php:25:1 - Unable to determine the type that $a is being assigned to

2) Psalm\Tests\MixinsDeepTest::testValidCode with data set "NamedMixinsWithT_WithStaticMethods"
Psalm\Exception\CodeException: MixedAssignment - src/somefile.php:39:1 - Unable to determine the type that $a is being assigned to
```
Creating this method is necessary to be able to
make recursive calls using this method in the
next step.
Problems:
```
1) Psalm\Tests\MixinsDeepTest::testValidCode with data set "NamedMixinsWithoutT_WithObjectProperties"
Psalm\Exception\CodeException: MixedAssignment - src/somefile.php:23:1 - Unable to determine the type that $a is being assigned to
```
@issidorov issidorov marked this pull request as ready for review September 12, 2024 04:49
@issidorov issidorov marked this pull request as draft September 19, 2024 14:33
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.

1 participant