Skip to content

Commit

Permalink
bugfix: Document highlight on anon-fun parameters in Scala 2
Browse files Browse the repository at this point in the history
Previosuly anonymous function params with the same name were not distinguished
  • Loading branch information
jkciesluk committed Nov 24, 2023
1 parent 5f9d66f commit 5342e5c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
14 changes: 9 additions & 5 deletions mtags/src/main/scala-2/scala/meta/internal/pc/PcCollector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,15 @@ abstract class PcCollector[T](
* For comprehensions have two owners, one for the enumerators and one for
* yield. This is a heuristic to find that out.
*/
def isForComprehensionOwner(named: NameTree) =
soughtNames(named.name) &&
named.symbol.owner.isAnonymousFunction && owners.exists(owner =>
pos.isDefined && owner.pos.isDefined && owner.pos.point == named.symbol.owner.pos.point
)
def isForComprehensionOwner(named: NameTree) = {
named.symbol.pos.isDefined &&
sought.exists(symbol =>
symbol.name == named.name && symbol.pos.isDefined && symbol.pos.start == named.symbol.pos.start
) &&
named.symbol.owner.isAnonymousFunction && owners.exists(owner =>
pos.isDefined && owner.pos.isDefined && owner.pos.point == named.symbol.owner.pos.point
)
}

def soughtOrOverride(sym: Symbol) =
sought(sym) || sym.allOverriddenSymbols.exists(sought(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,21 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite {
|}""".stripMargin
)

check(
"for-comp-bind2",
"""
|object Main {
| val abc = for {
| <<f@@oo>> <- List(1)
| baz = <<foo>> + 1
| a <- List(<<foo>>, 123)
| } yield {
| val x = <<foo>> + baz
| x
| }
|}""".stripMargin
)

check(
"for-comp-map",
"""|object Main {
Expand Down Expand Up @@ -993,4 +1008,16 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite {
|}""".stripMargin
)

check(
"map-bind6",
"""
|object Main {
| List("test").map {
| case <<string@@Name>>: String if <<stringName>>.startsWith("a") => <<stringName>> + "a"
| case stringName: String if stringName.startsWith("b") => stringName + "b"
| case stringName: String => stringName + "c"
| }
|}""".stripMargin
)

}

0 comments on commit 5342e5c

Please sign in to comment.