Skip to content

Commit

Permalink
bugfix: Catch exception from the compiler when coursier api is on cla…
Browse files Browse the repository at this point in the history
…sspath

We previously fixed another issue connected to this, when no completions would be available because `isPublic` would throw an exception. Now, it turns out we needed to wrap `toSymbols` methods, otherwise we would not get the duplicated symbols (which are also shadowed)

Connected to scala/scala3#16175
  • Loading branch information
tgodzik committed Aug 28, 2023
1 parent 99ceaf9 commit af6f11e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class CompilerSearchVisitor(
private def isAccessible(sym: Symbol): Boolean = try
sym != NoSymbol && sym.isPublic && sym.isStatic
catch
case err: AssertionError =>
logger.log(Level.WARNING, err.getMessage())
false
case NonFatal(e) =>
reports.incognito.create(
Report(
Expand Down Expand Up @@ -65,8 +68,14 @@ class CompilerSearchVisitor(
.stripSuffix("$")
.split("\\$")

val added = toSymbols(pkg, innerPath.toList).filter(visitSymbol)
val added =
try toSymbols(pkg, innerPath.toList).filter(visitSymbol)
catch
case NonFatal(e) =>
logger.log(Level.WARNING, e.getMessage(), e)
Nil
added.size
end visitClassfile

def visitWorkspaceSymbol(
path: java.nio.file.Path,
Expand Down
29 changes: 29 additions & 0 deletions tests/cross/src/test/scala/tests/pc/ShadowingCompletionSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package tests.pc

import coursierapi.Dependency
import tests.BaseCompletionSuite

class ShadowingCompletionSuite extends BaseCompletionSuite {

override protected def extraDependencies(
scalaVersion: String
): Seq[Dependency] = Seq(
Dependency.of("io.get-coursier", "interface", "1.0.18")
)

check(
"buffer".tag(IgnoreForScala3CompilerPC),
"""package pkg
|object Main {
| val x = ListBuff@@
|}
|""".stripMargin,
"""|ListBuffer[A](elems: A*): CC[A]
|ListBuffer(i: Int): A
|ListBuffer - scala.collection.mutable
|""".stripMargin,
compat = Map(
"2" -> "ListBuffer - scala.collection.mutable"
),
)
}

0 comments on commit af6f11e

Please sign in to comment.