From bf46b4996e74db0e676c7fd009f737f4acd718ad Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Mon, 16 Oct 2023 17:46:00 +0200 Subject: [PATCH] bugfix: Backticked named arguments --- .../src/main/dotty/tools/pc/PcCollector.scala | 13 ++++++++++--- .../tools/pc/tests/edit/PcPrepareRenameSuite.scala | 13 +++++++++++++ .../pc/tests/highlight/DocumentHighlightSuite.scala | 11 +++++++++++ .../tools/pc/tests/tokens/SemanticTokensSuite.scala | 11 +++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala b/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala index fda62cbb25e4..1f8eea8f4688 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcCollector.scala @@ -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) @@ -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 @@ -489,6 +495,7 @@ 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( @@ -496,7 +503,7 @@ abstract class PcCollector[T]( pos .withSpan( arg.span - .withEnd(arg.span.start + realName.length) + .withEnd(arg.span.start + length) .withPoint(arg.span.start) ), sym diff --git a/presentation-compiler/test/dotty/tools/pc/tests/edit/PcPrepareRenameSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/edit/PcPrepareRenameSuite.scala index 1e0b623f2dd5..9489e18d7fd2 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/edit/PcPrepareRenameSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/edit/PcPrepareRenameSuite.scala @@ -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, + ) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala index 0ed40c6c537f..80451fc67562 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/highlight/DocumentHighlightSuite.scala @@ -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: diff --git a/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala index 7da049270ff9..c1a36bc59ed4 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala @@ -332,3 +332,14 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite: |} |""".stripMargin ) + + @Test def `named-arg-backtick` = + check( + """|object <
>/*class*/ { + | def <>/*method,definition*/(<<`type`>>/*parameter,declaration,readonly*/: <>/*type*/): <>/*type*/ = <<`type`>>/*parameter,readonly*/ + | val <>/*variable,definition,readonly*/ = <>/*method*/( + | <<`type`>>/*parameter,readonly*/ = "abc" + | ) + |} + |""".stripMargin, + )