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

Check for type hierarchy while checking overrides #124

Merged
merged 1 commit into from
Oct 18, 2020

Conversation

yigit
Copy link
Collaborator

@yigit yigit commented Oct 12, 2020

This PR fixes a bug where override would return true if base method is sent as the overrider.
Similarly, it was also returning true when override is called with the same function itself.

I've also changed the override util call to also check for return type.

Fixes: #123

val typeOverride = subClassDescription.getAllSuperClassifiers()
.filter { it != subClassDescription } // exclude subclass itself as it cannot override its own methods
.any {
it == superClassDescription
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these 2 lamdas be merged into one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sequence<ClassifierDescriptor> returns a sequence so i kept them separate for readability (and does not have the cost of creating intermediate lists).
happy to change if you have a strong preference.

@neetopia
Copy link
Contributor

neetopia commented Oct 12, 2020

LGTM. Can you rebase commit history a little bit or would you like me to squash them all into one?

There was a bug in overrides check where superClass.foo overrides
subClass.foo would return true even though super class cannot override
a subClass. This PR fixes that issue by checking for class hiearchy
in addition to the method signature.

Fixes: google#123
Test: CheckOverrideProcessor
@yigit yigit force-pushed the override-from-sub-class branch from f17f13b to b9ceceb Compare October 18, 2020 04:02
@yigit
Copy link
Collaborator Author

yigit commented Oct 18, 2020

ready for merge. rebased manually with a proper single commit message.

@neetopia neetopia merged commit eae30cf into google:master Oct 18, 2020
@neetopia
Copy link
Contributor

Merged into master, thanks for contribution!

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.

baseMethod.overrides(childMethod) returns true
2 participants