Skip to content
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

Expose all synthetic semantic trees #981

Merged

Conversation

ingarabr
Copy link
Contributor

@ingarabr ingarabr commented Sep 3, 2019

The optimized lookup only exposed the last tree for a given position. A position can have multiple synthetic semantic trees. This occurs when we have a function with only an implicit argument.

Given the code:

object MyObject {
  trait Value[A] { def value: A }
  implicit val intValue: Value[Int] = new Value[Int] { def value: Int = 1 }
  class Foo[A]() {
    def baz[AA >: A](implicit s: Value[AA]): AA = s.value
  }

  val foo = new Foo[Int]()
  foo.baz
}

The tree for the foo.baz looks like this:

Term.Select(Term.Name("foo"), Term.Name("baz"))

When calling term.synthetic on the Term we're not able to extract the implicit arguments. If we add parentheses, foo.baz(), it will be wrapped in a Term.Apply, where the implicit is available. When querying the semantic tree from the given position we're ending up with two results where scalafix has optimized the lookup and expects at most one result.

This change exposes all the semantic trees that are available in the given position. It also depricates the API where we're expecting zero or one result.

The optimized lookup only exposed the last tree for a given position.
A position can have multiple synthetic semantic trees. This occurs when
we have a function with only an implicit argument.
@ingarabr ingarabr force-pushed the fix/expose-all-synthetic-semantic-tree branch from d51df53 to 154fc2c Compare September 4, 2019 16:01
@olafurpg olafurpg changed the title expose all synthetic semantic trees Expose all synthetic semantic trees Sep 12, 2019
Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution! LGTM 👍

@olafurpg olafurpg merged commit f3ceb98 into scalacenter:master Sep 12, 2019
@olafurpg
Copy link
Contributor

This fix is now available in 0.9.7, I've kickstarted a release of the sbt plugin which may take an hour to finish

@ingarabr ingarabr deleted the fix/expose-all-synthetic-semantic-tree branch September 12, 2019 13:46
@ingarabr
Copy link
Contributor Author

@olafurpg, thanks.

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.

3 participants