-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow selectDynamic and applyDynamic to be extension methods #17106
Conversation
@@ -186,7 +186,7 @@ trait Dynamic { | |||
// ($qual: Selectable).$selectorName("$name") | |||
val base = | |||
untpd.Apply( | |||
untpd.TypedSplice(selectable.select(selectorName)).withSpan(fun.span), | |||
untpd.Select(untpd.TypedSplice(selectable), selectorName).withSpan(fun.span), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will indeed allow extension methods, but won't it also allow all sorts of other things? Like recursive structural lookups and insertion of implicit conversions? That seems too much (especially the recursive structural lookup).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will allow implicit conversions, and that's intentional. It will allow recursive structural lookup if selectDynamic is defined in the structural type. But I think that's a weird corner case, and I also see nothing wrong to support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT: That should have been applyDynamic
.
Allow selectDynamic and applyDynamic to be an extension methods when dispatching structurally. Fixes scala#17100
Given ```scala trait Sel extends Dynamic extension (s: Sel) def selectDynamic(name: String) = ??? ``` the following worked: ```scala val sel = new Sel {} val foo = sel.foo ``` but the following didn't: ```scala val sel2 = (new Sel {}).asInstanceOf[Sel{ def foo: String }] val foo2 = sel2.foo ``` The problem was that we recognized a structural dispatch and then required the qualifier to be an instance of `Selectable`. But in fact, `Dynamic` works just as well, and the mechanism is the same. It's just that `Dynamic` is less type safe then `Selectable`.
Allow selectDynamic and applyDynamic to be extension methods when dispatching structurally.
Fixes #17100