Skip to content

Fixes #7359 - Fix SAM processing #7360

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

Merged
merged 1 commit into from
Nov 14, 2019
Merged

Fixes #7359 - Fix SAM processing #7360

merged 1 commit into from
Nov 14, 2019

Conversation

neshkeev
Copy link
Contributor

@neshkeev neshkeev commented Oct 3, 2019

I would like to start sharing my progress on the #7359 issue in this pull-request.

So far I have came across the problem with java.util.Comparator, which happens to contains overridden equals method. Javadoc states that overridden methods of java.lang.Object have to be ignored:

If an interface declares an abstract method overriding one of the public methods of java.lang.Object, that also does not count toward the interface's abstract method count

Dotty finds two abstract methods (equals and compare) in this @FunctionalInterface object and fails to recognize it as SAM and hence fails to assign a proper type to it.

@neshkeev neshkeev marked this pull request as ready for review October 11, 2019 05:41
@neshkeev neshkeev changed the title WIP #7359 - Fix SAM processing Fixes #7359 - Fix SAM processing Oct 12, 2019
@smarter smarter assigned neshkeev and unassigned smarter Nov 4, 2019
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

Dotty used to call the Types.abstractTermMembers method to find all the
methods that might be used as candidates for SAM. But the method ignores
the methods of java.lang.Object's when processing a list of a term's
members and returns all the members that have no implementation. This
used to cause the problem when there are overridden java.lang.Object
methods in a trait. Such methods receive implementation by default so they
cannot be considered as candidates for SAM methods. This problem prevents
Dotty from recognising some traits as SAM.

Now the Types.possibleSamMethods method is used in order to filter out
all the overridden java.lang.Object methods that does not have an
implementation yet.

This patch applies additional predicate to Types.abstractTermMembers to
filter out all the overridden java.lang.Object methods.

Signed-off-by: Nikita Eshkeev <[email protected]>
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your work and patience here :) !

@smarter smarter merged commit 951b05f into scala:master Nov 14, 2019
@neshkeev neshkeev deleted the wip/7359-fix-sam-processing branch November 14, 2019 15:25
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.

2 participants