Skip to content

Commit 53ff1ec

Browse files
jkcieslukWojciechMazur
authored andcommitted
bugfix: Backticked named arguments
[Cherry-picked d652c3e]
1 parent bb40486 commit 53ff1ec

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ 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 length = realName.toString.backticked.length()
204+
val pos = arg.sourcePos.withSpan(
205+
arg.span
206+
.withEnd(arg.span.start + length)
207+
.withPoint(arg.span.start)
208+
)
203209
appl.symbol.paramSymss.flatten.find(_.name == arg.name).map { s =>
204210
// if it's a case class we need to look for parameters also
205211
if caseClassSynthetics(s.owner.name) && s.owner.is(Flags.Synthetic)
@@ -211,9 +217,9 @@ abstract class PcCollector[T](
211217
s.owner.owner.info.member(s.name).symbol
212218
)
213219
.filter(_ != NoSymbol),
214-
arg.sourcePos,
220+
pos,
215221
)
216-
else (Set(s), arg.sourcePos)
222+
else (Set(s), pos)
217223
}
218224
else None
219225
end if
@@ -489,14 +495,15 @@ abstract class PcCollector[T](
489495
}
490496
val named = args.map { arg =>
491497
val realName = arg.name.stripModuleClassSuffix.lastPart
498+
val length = realName.toString.backticked.length()
492499
val sym = apply.symbol.paramSymss.flatten
493500
.find(_.name == realName)
494501
collect(
495502
arg,
496503
pos
497504
.withSpan(
498505
arg.span
499-
.withEnd(arg.span.start + realName.length)
506+
.withEnd(arg.span.start + length)
500507
.withPoint(arg.span.start)
501508
),
502509
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)