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

Corrected trait analysis: method ordering, abstract trait methods do not override concrete ones, method aliases now recognized #652

Merged
merged 3 commits into from
Jun 12, 2020

Conversation

kukulich
Copy link
Collaborator

@kukulich kukulich commented Jun 9, 2020

Fixes #647
Fixes #659

Also fixes methods order: https://3v4l.org/LiTi4

@kukulich kukulich marked this pull request as draft June 9, 2020 07:25
test/unit/Fixture/MethodsOrder.php Outdated Show resolved Hide resolved
@Ocramius Ocramius added the bug label Jun 9, 2020
@Ocramius Ocramius added this to the 4.5.0 milestone Jun 9, 2020
@Ocramius
Copy link
Member

Ocramius commented Jun 9, 2020

@kukulich I see this is a draft: is it still WIP on your end?

@ondrejmirtes
Copy link
Contributor

We discussed this privately with @kukulich - there's no assert about the bar() method and I think it will prove the current fix is wrong for that case.

@Ocramius Ocramius added the WIP label Jun 9, 2020
@Ocramius Ocramius removed this from the 4.5.0 milestone Jun 10, 2020
@kukulich
Copy link
Collaborator Author

@ondrejmirtes What do you think?

@ondrejmirtes
Copy link
Contributor

@kukulich It still doesn't work in some cases - if you make the parent AbstractClassImplementingMethodFromTrait non-abstract, TraitWithAbstractMethod::bar() should still win but it's not the case.

@kukulich kukulich force-pushed the trait-abstract branch 2 times, most recently from 1df774e to e7025b5 Compare June 10, 2020 21:25
@kukulich kukulich changed the title Abstract trait method should not override concrete method from parent class Traits fixes Jun 10, 2020
@kukulich kukulich force-pushed the trait-abstract branch 2 times, most recently from 315a1e3 to 91355f7 Compare June 11, 2020 06:39
@ondrejmirtes
Copy link
Contributor

I confirm this now fixes both #647 and #659.

@kukulich kukulich marked this pull request as ready for review June 11, 2020 07:01
@kukulich
Copy link
Collaborator Author

@Ocramius Please just merge it. I don't want to see the code again for some time... :)

@kukulich
Copy link
Collaborator Author

@Ocramius This is ready to review too :)

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

LGTM 👍

assert($parent instanceof self);
if ($this->cachedParentClass === null) {
$parent = $this->reflector->reflect($this->node->extends->toString());
// @TODO use actual `ClassReflector` or `FunctionReflector`?
Copy link
Member

Choose a reason for hiding this comment

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

I think this TODO is solved for now: we can improve on the type system of reflectors later on.

Copy link
Member

Choose a reason for hiding this comment

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

Not relevant for this patch: can be removed later

$this,
$method->getAliasName(),
return array_merge(
[],
Copy link
Member

Choose a reason for hiding this comment

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

BTW, since we are on PHP 7.4+, array_merge([], ...$others) is no longer needed: https://3v4l.org/HUtnH

Copy link
Member

Choose a reason for hiding this comment

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

Not relevant for this patch: maybe interesting for slevomat/coding-standard :D

$parent = $this->reflector->reflect($this->node->extends->toString());
// @TODO use actual `ClassReflector` or `FunctionReflector`?
assert($parent instanceof self);
if ($this->cachedParentClass === null) {
Copy link
Member

Choose a reason for hiding this comment

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

Caching this is a nice addition 👍

@Ocramius Ocramius removed the WIP label Jun 12, 2020
@Ocramius Ocramius changed the title Traits fixes Corrected trait analysis: method ordering, abstract trait methods do not override concrete ones, method aliases now recognized Jun 12, 2020
@Ocramius Ocramius modified the milestones: 4.7.0, 4.6.1 Jun 12, 2020
@Ocramius Ocramius changed the base branch from master to 4.6.x June 12, 2020 11:09
@Ocramius Ocramius merged commit c6797a2 into Roave:4.6.x Jun 12, 2020
@kukulich kukulich deleted the trait-abstract branch June 12, 2020 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants