Skip to content

Commit

Permalink
bugfix: go to definition for extension method in companion object
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 12, 2023
1 parent e6e4713 commit 53e6b44
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.interactive.SourceTree
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.SourcePosition
import dotty.tools.dotc.core.Flags

object MetalsInteractive:

Expand Down Expand Up @@ -266,6 +267,17 @@ object MetalsInteractive:
case _ =>
Nil

/* Workaround for missing span in:
* class MyIntOut(val value: Int)
* object MyIntOut:
* extension (i: MyIntOut) def <<uneven>> = 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(
Expand Down
10 changes: 10 additions & 0 deletions tests/cross/src/test/scala/tests/pc/PcDefinitionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,14 @@ class PcDefinitionSuite extends BasePcDefinitionSuite {
|""".stripMargin,
)

check(
"i5630".tag(IgnoreForScala3CompilerPC),
"""|class MyIntOut(val value: Int)
|object MyIntOut:
| extension (i: MyIntOut) def <<uneven>> = i.value % 2 == 1
|
|val a = MyIntOut(1).un@@even
|""".stripMargin,
)

}

0 comments on commit 53e6b44

Please sign in to comment.