Skip to content

Allow structural anonymous classes #9201

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 2 commits into from
Jun 18, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 18, 2020

We now allow structural dispatch on classes that extend the scala.Selectable trait. If a class extends scala.reflect.Selectable structural dispatch is resolved using Java reflection.

@odersky odersky requested a review from smarter June 18, 2020 14:54
@smarter smarter merged commit de75713 into scala:master Jun 18, 2020
@smarter smarter deleted the structural-new-2 branch June 18, 2020 18:56
@soronpo
Copy link
Contributor

soronpo commented Jun 19, 2020

Thanks for this. AFAIK, this was the last programmability gap that prevented me from porting my library to dotty. I currently don't have time to do this, but will get on that when I can.

is implemented by the base trait `reflect.Selectable` of `Vehicle`, which
defines the necessary `selectDynamic` member.

`Vehicle` could also extend some other subclass of `scala.Selectable` that implements `selectDynamic` and `applyDynamic` differently. But if it does not extend a `Selectable` at all, the code would no longer typecheck:

Choose a reason for hiding this comment

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

here you write scala.Selectable but above you write reflect.Selectable (and also in the tests). I assume this is a typo, but perhaps scala.Selectable is also a thing.

Copy link
Member

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Got it. Thanks for the clarification. (I never use these due to performance anxiety associated with reflection, so I had forgotten about that).

@Alexey-NM
Copy link

Would it be possible to use dynamic invocation in such cases, is it difficult to allow:

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.

5 participants