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

Wrong position for parens wrapped identifier #1083

Closed
olafurpg opened this issue Aug 23, 2017 · 6 comments
Closed

Wrong position for parens wrapped identifier #1083

olafurpg opened this issue Aug 23, 2017 · 6 comments
Assignees
Labels

Comments

@olafurpg
Copy link
Member

@ """val x = (a).value""".parse[Stat].get.collect {
    case n: Name => n.syntax
  }
res1: List[String] = List("x", "(a)", "value") // obtained
res1: List[String] = List("x", "a", "value") // expected

This causes problems when looking up symbols of names by their positions.

@olafurpg
Copy link
Member Author

olafurpg commented Aug 23, 2017

Just hit again on a similar problem

@ """
    List(builder) map (_.result)
  """.parse[Stat].get.collect {
  case t @ q"_.result" => t.syntax
  }
res1: List[String] = List("(_.result)") // obtained
res1: List[String] = List("_.result") // expected

The example works as expected if it's not an ApplyInfix

@olafurpg
Copy link
Member Author

Reported by @MasseGuillaume in #1444

def structure(source: String): String = 
  source.parse[Stat].get.asInstanceOf[Term.ApplyInfix].args.head.tokens.structure 

// This is what I get
structure("a op (f)") == "Tokens(( [5..6), f [6..7), ) [7..8))"

// This is what I expect
structure("a op (f)") == "Tokens(f [6..7))"

// With multiple args I get what I expect
structure("a op (f, g)") == "Tokens(f [6..7))"

@olafurpg
Copy link
Member Author

A good place to look into this would be

def termName(advance: Boolean = true): Term.Name = name(Term.Name(_), advance)
def typeName(advance: Boolean = true): Type.Name = name(Type.Name(_), advance)

where Term.Name nodes are created.

@MasseGuillaume
Copy link
Collaborator

I'm on this.

@MasseGuillaume MasseGuillaume self-assigned this Apr 11, 2018
MasseGuillaume added a commit to MasseGuillaume/scalameta that referenced this issue Apr 11, 2018
giabao added a commit to giabao/scalafix that referenced this issue Apr 24, 2020
giabao added a commit to giabao/scalafix that referenced this issue Apr 24, 2020
giabao added a commit to ohze/scala-rewrites that referenced this issue Apr 27, 2020
and scalacenter/scalafix#1104

Given
```
trait Test {
  def shouldBe(r: Any) = ???
  def arg() = ""
  this shouldBe (arg)
}
```

Without changes in this commit then `this shouldBe (arg)`
+ will not be rewritten if scalacenter/scalafix#1104 is not fixed
+ will be rewritten to invalid code `this shouldBe (arg)()` if scalacenter/scalafix#1104 is fixed but scalameta/scalameta#1083 is not fixed
giabao added a commit to ohze/scala-rewrites that referenced this issue Apr 27, 2020
and scalacenter/scalafix#1104

Given
```
trait Test {
  def shouldBe(r: Any) = ???
  def arg() = ""
  this shouldBe (arg)
}
```

Without changes in this commit then `this shouldBe (arg)`
+ will not be rewritten if scalacenter/scalafix#1104 is not fixed
+ will be rewritten to invalid code `this shouldBe (arg)()` if scalacenter/scalafix#1104 is fixed but scalameta/scalameta#1083 is not fixed
@kitbellew
Copy link
Contributor

still relevant? i can't repro.

@olafurpg
Copy link
Member Author

Closing as fixed then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants