From f448ae0ae144c89d90bb54710904ebd67a7cfdf1 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Thu, 21 Sep 2023 15:09:47 +0200 Subject: [PATCH] bugfix: go to definition for extension method in companion object --- .../scala/meta/internal/pc/MetalsInteractive.scala | 12 ++++++++++++ .../src/test/scala/tests/pc/PcDefinitionSuite.scala | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/MetalsInteractive.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/MetalsInteractive.scala index 768ceb58096..30f475baba6 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/MetalsInteractive.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/MetalsInteractive.scala @@ -8,6 +8,7 @@ import dotty.tools.dotc.ast.untpd import dotty.tools.dotc.core.ContextOps.* import dotty.tools.dotc.core.Contexts.* import dotty.tools.dotc.core.CyclicReference +import dotty.tools.dotc.core.Flags import dotty.tools.dotc.core.Flags.* import dotty.tools.dotc.core.Names.Name import dotty.tools.dotc.core.StdNames @@ -266,6 +267,17 @@ object MetalsInteractive: case _ => Nil + /* Workaround for missing span in: + * class MyIntOut(val value: Int) + * object MyIntOut: + * extension (i: MyIntOut) def <> = i.value % 2 == 1 + * + * val a = MyIntOut(1).un@@even + */ + case (a @ Apply(sel: Select, _)) :: _ + if sel.span.isZeroExtent && sel.symbol.is(Flags.ExtensionMethod) => + List((sel.symbol, a.typeOpt)) + case path @ head :: tail => if head.symbol.is(Synthetic) then enclosingSymbolsWithExpressionType( diff --git a/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala b/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala index b6b984fbaf3..ea6b99027ea 100644 --- a/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala @@ -559,4 +559,14 @@ class PcDefinitionSuite extends BasePcDefinitionSuite { |""".stripMargin, ) + check( + "i5630".tag(IgnoreScala2.and(IgnoreForScala3CompilerPC)), + """|class MyIntOut(val value: Int) + |object MyIntOut: + | extension (i: MyIntOut) def <> = i.value % 2 == 1 + | + |val a = MyIntOut(1).un@@even + |""".stripMargin, + ) + }