Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "fix: prefer non-export definition locations" to LTS #21085

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dotty.tools.dotc.ast.NavigateAST
import dotty.tools.dotc.ast.tpd.*
import dotty.tools.dotc.ast.untpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Flags.ModuleClass
import dotty.tools.dotc.core.Flags.{Exported, ModuleClass}
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
Expand Down Expand Up @@ -123,9 +123,12 @@ class PcDefinitionProvider(
case symbols @ (sym :: other) =>
val isLocal = sym.source == pos.source
if isLocal then
val defs =
Interactive.findDefinitions(List(sym), driver, false, false).filter(_.source == sym.source)
defs.headOption match
val (exportedDefs, otherDefs) =
Interactive.findDefinitions(List(sym), driver, false, false)
.filter(_.source == sym.source)
.partition(_.tree.symbol.is(Exported))

otherDefs.headOption.orElse(exportedDefs.headOption) match
case Some(srcTree) =>
val pos = srcTree.namePos
pos.toLocation match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
|""".stripMargin
)

@Test def exportTermExtension =
check(
"""|package a
|class Test extends A {
| assert("Hello".fo@@o == "HelloFoo")
|}
|
|trait A {
| export B.*
|}
|
|object B {
| extension (value: String) def <<foo>>: String = s"${value}Foo"
|}
|""".stripMargin
)

@Test def `named-arg-local` =
check(
"""|
Expand Down