-
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
selectDynamic
cannot be an extension method
#17100
Comments
@odersky did I get the specification right? The only case that works and that I know about in which a structural selection is desugared to |
Yes, this should work. |
Allow selectDynamic and applyDynamic to be an extension methods when dispatching structurally. Fixes scala#17100
Should it work for extension of |
No |
Just to be clear. If I will replace trait Sel extends Dynamic
extension (s: Sel)
def selectDynamic(name: String) = ???
val sel = (new Sel {}).asInstanceOf[Sel{ def foo: String }]
val foo = sel.foo |
@plokhotnyuk Actually in case of import scala.language.dynamics
trait Sel extends Dynamic
extension (s: Sel)
def selectDynamic(name: String) = name
val sel = new Sel {}
val foo = sel.foo The point is that you need to import |
Allow selectDynamic and applyDynamic to be an extension methods when dispatching structurally. Fixes scala#17100
@odersky interestingly this code import scala.language.dynamics
trait Sel extends Dynamic {
def selectDynamic(name: String) = name
}
object Test {
val sel1 = new Sel {}
val foo1 = sel1.foo
val sel2 = (new Sel {}).asInstanceOf[Sel{ def foo: String }]
val foo2 = sel2.foo
} does compile in 2.13.10 but it raises a warning: [warn] ./Sel.scala:11:14
[warn] reflective access of structural type member method foo should be enabled
[warn] by making the implicit value scala.language.reflectiveCalls visible.
[warn] ----
[warn] This can be achieved by adding the import clause 'import scala.language.reflectiveCalls'
[warn] or by setting the compiler option -language:reflectiveCalls.
[warn] See the Scaladoc for value scala.language.reflectiveCalls for a discussion
[warn] why the feature should be explicitly enabled.
[warn] val foo2 = sel2.foo
[warn] ^^^^^^^^ so there seems to be a slight semantic difference between |
No, structural types are one of the areas where Scala 3 is different. Generally, reflectiveCalls is no longer needed in Scala 3. |
The tests fail with
Can someone explain what this is or how to fix it? |
This seems to be some problem with our CI infrastructure, present since yesterday. There's a chance rerunning the jobs might help |
Allow selectDynamic and applyDynamic to be extension methods when dispatching structurally. Fixes #17100
Allow selectDynamic and applyDynamic to be an extension methods when dispatching structurally. Fixes scala#17100
Compiler version
3.3.1-RC1-bin-20230313-f28d708-NIGHTLY and before
Minimized code
Output
Expectation
According to our reference documentation:
To my understanding this means that the code snippet should compile successfully, by applying the syntax desugarings:
Similarly it should be possible to provide the implementation of
applyDynamic
as an extension method.The text was updated successfully, but these errors were encountered: