Skip to content

Commit

Permalink
backport: Finer grained accessibility check for auto-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Oct 11, 2024
1 parent 6429b4b commit 87db0da
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CompilerSearchVisitor(
owner.isStatic && owner.isPublic

private def isAccessible(sym: Symbol): Boolean = try
sym != NoSymbol && sym.isPublic && sym.isStatic || isAccessibleImplicitClass(sym)
(sym != NoSymbol && sym.isAccessibleFrom(ctx.owner.info) && sym.isStatic) || isAccessibleImplicitClass(sym)
catch
case err: AssertionError =>
logger.log(Level.WARNING, err.getMessage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class PcDefinitionProvider(
SemanticdbSymbols.symbolName(sym),
List(loc).asJava,
)
else DefinitionResultImpl.empty
else DefinitionResultImpl.empty
case None =>
DefinitionResultImpl.empty
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,29 @@ class CompletionSnippetSuite extends BaseCompletionSuite:
)

@Test def `no-apply` =
checkSnippet(
s"""|package example
|
|object Widget{}
|object Main {
| Wi@@
|}
|""".stripMargin,
"""|Widget - example
|Window - java.awt
|WindowPeer - java.awt.peer
|WithFilter - [A](p: A => Boolean, xs: Array[A]): WithFilter[A]
|WithFilter - [A, CC[_$$2]](self: IterableOps[A, CC, ?], p: A => Boolean): WithFilter[A, CC]
|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]
|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]
|WithFilter - [A, IterableCC[_$$1], CC[X] <: SortedSet[X]](self: SortedSetOps[A, CC, ?] & IterableOps[A, IterableCC, ?], p: A => Boolean): WithFilter[A, IterableCC, CC]
|WithFilter - (p: Char => Boolean, s: String): WithFilter
|WithFilter - [A](l: Stream[A] @uncheckedVariance, p: A => Boolean): WithFilter[A]
|""".stripMargin,
includeDetail = true,
)

@Test def `no-apply2` =
checkSnippet(
s"""|package example
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,19 @@ class CompletionSuite extends BaseCompletionSuite:
|""".stripMargin
)

@Test def `shadowing` =
check(
"""|package pkg
|object Main {
| val x = ListBuff@@
|}
|""".stripMargin,
"""|ListBuffer[A](elems: A*): ListBuffer[A] - scala.collection.mutable
|new ListBuffer[A]: ListBuffer[A] - scala.collection.mutable
|ListBuffer - scala.collection.mutable
|""".stripMargin
)

@Test def `conflict-edit-2` =
checkEdit(
"""|package a
Expand Down

0 comments on commit 87db0da

Please sign in to comment.