Skip to content

Commit

Permalink
bugfix: Backticked named arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Oct 22, 2023
1 parent 55c5864 commit bf46b49
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
13 changes: 10 additions & 3 deletions presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ abstract class PcCollector[T](
val realName = arg.name.stripModuleClassSuffix.lastPart
if pos.span.start > arg.span.start && pos.span.end < arg.span.point + realName.length
then
val length = realName.toString.backticked.length()
val pos = arg.sourcePos.withSpan(
arg.span
.withEnd(arg.span.start + length)
.withPoint(arg.span.start)
)
appl.symbol.paramSymss.flatten.find(_.name == arg.name).map { s =>
// if it's a case class we need to look for parameters also
if caseClassSynthetics(s.owner.name) && s.owner.is(Flags.Synthetic)
Expand All @@ -211,9 +217,9 @@ abstract class PcCollector[T](
s.owner.owner.info.member(s.name).symbol
)
.filter(_ != NoSymbol),
arg.sourcePos,
pos,
)
else (Set(s), arg.sourcePos)
else (Set(s), pos)
}
else None
end if
Expand Down Expand Up @@ -489,14 +495,15 @@ abstract class PcCollector[T](
}
val named = args.map { arg =>
val realName = arg.name.stripModuleClassSuffix.lastPart
val length = realName.toString.backticked.length()
val sym = apply.symbol.paramSymss.flatten
.find(_.name == realName)
collect(
arg,
pos
.withSpan(
arg.span
.withEnd(arg.span.start + realName.length)
.withEnd(arg.span.start + length)
.withPoint(arg.span.start)
),
sym
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,16 @@ class PcPrepareRenameSuite extends BasePcRenameSuite:
|end extension
|""".stripMargin
)

@Test def `named-arg-backtick` =
prepare(
"""|object Main {
| def m() = {
| def foo(`type`: String): String = `type`
| val x = foo(
| <<`ty@@pe`>> = "abc"
| )
| }
|}
|""".stripMargin,
)
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,17 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite:
|""".stripMargin,
)

@Test def `named-arg-backtick` =
check(
"""|object Main {
| def foo(<<`type`>>: String): String = <<`type`>>
| val x = foo(
| <<`ty@@pe`>> = "abc"
| )
|}
|""".stripMargin,
)

@Test def `enum1` =
check(
"""|enum FooEnum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,14 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
|}
|""".stripMargin
)

@Test def `named-arg-backtick` =
check(
"""|object <<Main>>/*class*/ {
| def <<foo>>/*method,definition*/(<<`type`>>/*parameter,declaration,readonly*/: <<String>>/*type*/): <<String>>/*type*/ = <<`type`>>/*parameter,readonly*/
| val <<x>>/*variable,definition,readonly*/ = <<foo>>/*method*/(
| <<`type`>>/*parameter,readonly*/ = "abc"
| )
|}
|""".stripMargin,
)

0 comments on commit bf46b49

Please sign in to comment.