Skip to content

Commit db418d3

Browse files
committed
bugfix: Backticked named arguments
1 parent 55c5864 commit db418d3

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ abstract class PcCollector[T](
200200
val realName = arg.name.stripModuleClassSuffix.lastPart
201201
if pos.span.start > arg.span.start && pos.span.end < arg.span.point + realName.length
202202
then
203+
val realName = arg.name.stripModuleClassSuffix.lastPart
204+
val length = realName.toString.backticked.length()
205+
val pos = arg.sourcePos.withSpan(
206+
arg.span
207+
.withEnd(arg.span.start + length)
208+
.withPoint(arg.span.start)
209+
)
203210
appl.symbol.paramSymss.flatten.find(_.name == arg.name).map { s =>
204211
// if it's a case class we need to look for parameters also
205212
if caseClassSynthetics(s.owner.name) && s.owner.is(Flags.Synthetic)
@@ -211,9 +218,9 @@ abstract class PcCollector[T](
211218
s.owner.owner.info.member(s.name).symbol
212219
)
213220
.filter(_ != NoSymbol),
214-
arg.sourcePos,
221+
pos,
215222
)
216-
else (Set(s), arg.sourcePos)
223+
else (Set(s), pos)
217224
}
218225
else None
219226
end if
@@ -489,14 +496,15 @@ abstract class PcCollector[T](
489496
}
490497
val named = args.map { arg =>
491498
val realName = arg.name.stripModuleClassSuffix.lastPart
499+
val length = realName.toString.backticked.length()
492500
val sym = apply.symbol.paramSymss.flatten
493501
.find(_.name == realName)
494502
collect(
495503
arg,
496504
pos
497505
.withSpan(
498506
arg.span
499-
.withEnd(arg.span.start + realName.length)
507+
.withEnd(arg.span.start + length)
500508
.withPoint(arg.span.start)
501509
),
502510
sym

presentation-compiler/test/dotty/tools/pc/tests/edit/PcPrepareRenameSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,16 @@ class PcPrepareRenameSuite extends BasePcRenameSuite:
507507
|end extension
508508
|""".stripMargin
509509
)
510+
511+
@Test def `named-arg-backtick` =
512+
prepare(
513+
"""|object Main {
514+
| def m() = {
515+
| def foo(`type`: String): String = `type`
516+
| val x = foo(
517+
| <<`ty@@pe`>> = "abc"
518+
| )
519+
| }
520+
|}
521+
|""".stripMargin,
522+
)

presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,17 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite:
843843
|""".stripMargin,
844844
)
845845

846+
@Test def `named-arg-backtick` =
847+
check(
848+
"""|object Main {
849+
| def foo(<<`type`>>: String): String = <<`type`>>
850+
| val x = foo(
851+
| <<`ty@@pe`>> = "abc"
852+
| )
853+
|}
854+
|""".stripMargin,
855+
)
856+
846857
@Test def `enum1` =
847858
check(
848859
"""|enum FooEnum:

presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,14 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
332332
|}
333333
|""".stripMargin
334334
)
335+
336+
@Test def `named-arg-backtick` =
337+
check(
338+
"""|object <<Main>>/*class*/ {
339+
| def <<foo>>/*method,definition*/(<<`type`>>/*parameter,declaration,readonly*/: <<String>>/*type*/): <<String>>/*type*/ = <<`type`>>/*parameter,readonly*/
340+
| val <<x>>/*variable,definition,readonly*/ = <<foo>>/*method*/(
341+
| <<`type`>>/*parameter,readonly*/ = "abc"
342+
| )
343+
|}
344+
|""".stripMargin,
345+
)

0 commit comments

Comments
 (0)