Skip to content

Commit 87db0da

Browse files
committed
backport: Finer grained accessibility check for auto-imports
1 parent 6429b4b commit 87db0da

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CompilerSearchVisitor(
2828
owner.isStatic && owner.isPublic
2929

3030
private def isAccessible(sym: Symbol): Boolean = try
31-
sym != NoSymbol && sym.isPublic && sym.isStatic || isAccessibleImplicitClass(sym)
31+
(sym != NoSymbol && sym.isAccessibleFrom(ctx.owner.info) && sym.isStatic) || isAccessibleImplicitClass(sym)
3232
catch
3333
case err: AssertionError =>
3434
logger.log(Level.WARNING, err.getMessage())

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class PcDefinitionProvider(
137137
SemanticdbSymbols.symbolName(sym),
138138
List(loc).asJava,
139139
)
140-
else DefinitionResultImpl.empty
140+
else DefinitionResultImpl.empty
141141
case None =>
142142
DefinitionResultImpl.empty
143143
else

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSnippetSuite.scala

+23
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,29 @@ class CompletionSnippetSuite extends BaseCompletionSuite:
385385
)
386386

387387
@Test def `no-apply` =
388+
checkSnippet(
389+
s"""|package example
390+
|
391+
|object Widget{}
392+
|object Main {
393+
| Wi@@
394+
|}
395+
|""".stripMargin,
396+
"""|Widget - example
397+
|Window - java.awt
398+
|WindowPeer - java.awt.peer
399+
|WithFilter - [A](p: A => Boolean, xs: Array[A]): WithFilter[A]
400+
|WithFilter - [A, CC[_$$2]](self: IterableOps[A, CC, ?], p: A => Boolean): WithFilter[A, CC]
401+
|WithFilter - [K, V, IterableCC[_$$3], CC[_$$4,_$$5] <: IterableOps[?, AnyConstr, ?]](self: MapOps[K, V, CC, ?] & IterableOps[(K, V), IterableCC, ?], p: ((K, V)) => Boolean): WithFilter[K, V, IterableCC, CC]
402+
|WithFilter - [K, V, IterableCC[_$$1], MapCC[X,Y] <: scala.collection.Map[X, Y], CC[X,Y] <: scala.collection.Map[X, Y] & SortedMapOps[X, Y, CC, ?]](self: SortedMapOps[K, V, CC, ?] & MapOps[K, V, MapCC, ?] & IterableOps[(K, V), IterableCC, ?], p: ((K, V)) => Boolean): WithFilter[K, V, IterableCC, MapCC, CC]
403+
|WithFilter - [A, IterableCC[_$$1], CC[X] <: SortedSet[X]](self: SortedSetOps[A, CC, ?] & IterableOps[A, IterableCC, ?], p: A => Boolean): WithFilter[A, IterableCC, CC]
404+
|WithFilter - (p: Char => Boolean, s: String): WithFilter
405+
|WithFilter - [A](l: Stream[A] @uncheckedVariance, p: A => Boolean): WithFilter[A]
406+
|""".stripMargin,
407+
includeDetail = true,
408+
)
409+
410+
@Test def `no-apply2` =
388411
checkSnippet(
389412
s"""|package example
390413
|

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

+13
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,19 @@ class CompletionSuite extends BaseCompletionSuite:
21072107
|""".stripMargin
21082108
)
21092109

2110+
@Test def `shadowing` =
2111+
check(
2112+
"""|package pkg
2113+
|object Main {
2114+
| val x = ListBuff@@
2115+
|}
2116+
|""".stripMargin,
2117+
"""|ListBuffer[A](elems: A*): ListBuffer[A] - scala.collection.mutable
2118+
|new ListBuffer[A]: ListBuffer[A] - scala.collection.mutable
2119+
|ListBuffer - scala.collection.mutable
2120+
|""".stripMargin
2121+
)
2122+
21102123
@Test def `conflict-edit-2` =
21112124
checkEdit(
21122125
"""|package a

0 commit comments

Comments
 (0)