-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #9295: Avoid recursive Dynamics conversion #9300
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
Conversation
@@ -142,7 +142,8 @@ trait TypeAssigner { | |||
val mbr = qualType.findMember(name, pre) | |||
if (reallyExists(mbr)) | |||
qualType.select(name, mbr) | |||
else if (qualType.derivesFrom(defn.DynamicClass) && name.isTermName && !Dynamic.isDynamicMethod(name)) | |||
else if (qualType.derivesFrom(defn.DynamicClass) && name.isTermName && !Dynamic.isDynamicMethod(name) && | |||
!(name == nme.apply && tree.span.isSynthetic && Dynamic.isDynamicMethod(qual1.symbol.name))) |
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.
The following code compiles before, but fails to compile after the changes:
import scala.language.dynamics
class Foo extends Dynamic {
def applyDynamic(name: String): Bar = ???
}
class Bar extends Dynamic {
def applyDynamic(name: String)(x: Int): Qux = ???
}
class Qux extends Dynamic {
def applyDynamic(name: String)(x: Int) = ???
}
var foo = new Foo
def baz = foo.blah(42).blah(45)
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 is intended, as in Scala 2.
https://scastie.scala-lang.org/gsxJ9jifRQyc5jLTbrmYSQ
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.
The only worry I have is about using positions for semantics (though we have precedent for that when dealing with contextual functions), as positions are very weak invariants.
If there are no better alternatives, maybe we add the example as a neg test?
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.
Indeed. I will try to find another way to identify the application
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.
Now I handle properly contextual functions, but we still need to check the positions.
Avoid trying to apply `Dynamic` transformation on `apply` with a qualifier that already has a been handled by the `Dynamic` transformation.
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.
LGTM
Avoid trying to apply
Dynamic
transformation onapply
with a qualifier that already hasa been handled by the
Dynamic
transformation.