Skip to content

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
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