Skip to content

fix completions to properly contain public fields if they were shadowed #15236

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

Merged
merged 3 commits into from
May 20, 2022
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
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import dotty.tools.dotc.util.SourcePosition

import scala.collection.mutable
import scala.util.control.NonFatal
import dotty.tools.dotc.core.Types.TypeRef

/**
* One of the results of a completion query.
Expand Down Expand Up @@ -481,7 +480,11 @@ object Completion {
private def accessibleMembers(site: Type)(using Context): Seq[SingleDenotation] = {
def appendMemberSyms(name: Name, buf: mutable.Buffer[SingleDenotation]): Unit =
try
buf ++= site.member(name).alternatives
val member = site.member(name)
if member.symbol.is(ParamAccessor) && !member.symbol.isAccessibleFrom(site) then
buf ++= site.nonPrivateMember(name).alternatives
else
buf ++= member.alternatives
catch
case ex: TypeError =>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,4 +1275,14 @@ class CompletionTest {
.noCompletions()
}

@Test def singleDenotNoCompletions: Unit = {
code"""class Test(val symbol: String)
|class BetterTest(symbol: Int) extends Test(symbol.toString):
| symb$m1
|object O:
| def t(test: BetterTest) = test.symb$m2"""
.completion(m1, ("symbol", Field, "Int"))
.completion(m2, ("symbol", Field, "String"))
}

}