Skip to content

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

Merged
merged 1 commit into from
Jul 10, 2020

Conversation

nicolasstucki
Copy link
Contributor

Avoid trying to apply Dynamic transformation on apply with a qualifier that already has
a been handled by the Dynamic transformation.

@nicolasstucki nicolasstucki linked an issue Jul 6, 2020 that may be closed by this pull request
@nicolasstucki nicolasstucki requested a review from liufengyun July 6, 2020 13:39
@nicolasstucki nicolasstucki marked this pull request as ready for review July 6, 2020 13:39
@@ -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)))
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@nicolasstucki nicolasstucki requested a review from liufengyun July 7, 2020 20:29
Avoid trying to apply `Dynamic` transformation on `apply` with a qualifier that already has
a been handled by the `Dynamic` transformation.
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

@nicolasstucki nicolasstucki merged commit e6bb414 into scala:master Jul 10, 2020
@nicolasstucki nicolasstucki deleted the fix-#9295 branch July 10, 2020 14:15
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.

Stackoverflow via applyDynamic
2 participants