Skip to content

Commit b34af6c

Browse files
kasiaMarekWojciechMazur
authored andcommitted
fix: prefer non-export definition locations
[Cherry-picked 41c735e]
1 parent 77b66cd commit b34af6c

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import dotty.tools.dotc.ast.NavigateAST
1313
import dotty.tools.dotc.ast.tpd.*
1414
import dotty.tools.dotc.ast.untpd
1515
import dotty.tools.dotc.core.Contexts.Context
16-
import dotty.tools.dotc.core.Flags.ModuleClass
16+
import dotty.tools.dotc.core.Flags.{Exported, ModuleClass}
1717
import dotty.tools.dotc.core.Symbols.*
1818
import dotty.tools.dotc.interactive.Interactive
1919
import dotty.tools.dotc.interactive.InteractiveDriver
@@ -123,9 +123,12 @@ class PcDefinitionProvider(
123123
case symbols @ (sym :: other) =>
124124
val isLocal = sym.source == pos.source
125125
if isLocal then
126-
val defs =
127-
Interactive.findDefinitions(List(sym), driver, false, false).filter(_.source == sym.source)
128-
defs.headOption match
126+
val (exportedDefs, otherDefs) =
127+
Interactive.findDefinitions(List(sym), driver, false, false)
128+
.filter(_.source == sym.source)
129+
.partition(_.tree.symbol.is(Exported))
130+
131+
otherDefs.headOption.orElse(exportedDefs.headOption) match
129132
case Some(srcTree) =>
130133
val pos = srcTree.namePos
131134
pos.toLocation match

presentation-compiler/test/dotty/tools/pc/tests/definition/PcDefinitionSuite.scala

+17
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,23 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
274274
|""".stripMargin
275275
)
276276

277+
@Test def exportTermExtension =
278+
check(
279+
"""|package a
280+
|class Test extends A {
281+
| assert("Hello".fo@@o == "HelloFoo")
282+
|}
283+
|
284+
|trait A {
285+
| export B.*
286+
|}
287+
|
288+
|object B {
289+
| extension (value: String) def <<foo>>: String = s"${value}Foo"
290+
|}
291+
|""".stripMargin
292+
)
293+
277294
@Test def `named-arg-local` =
278295
check(
279296
"""|

0 commit comments

Comments
 (0)