Skip to content

Commit af6f11e

Browse files
committed
bugfix: Catch exception from the compiler when coursier api is on classpath
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
1 parent 99ceaf9 commit af6f11e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class CompilerSearchVisitor(
2323
private def isAccessible(sym: Symbol): Boolean = try
2424
sym != NoSymbol && sym.isPublic && sym.isStatic
2525
catch
26+
case err: AssertionError =>
27+
logger.log(Level.WARNING, err.getMessage())
28+
false
2629
case NonFatal(e) =>
2730
reports.incognito.create(
2831
Report(
@@ -65,8 +68,14 @@ class CompilerSearchVisitor(
6568
.stripSuffix("$")
6669
.split("\\$")
6770

68-
val added = toSymbols(pkg, innerPath.toList).filter(visitSymbol)
71+
val added =
72+
try toSymbols(pkg, innerPath.toList).filter(visitSymbol)
73+
catch
74+
case NonFatal(e) =>
75+
logger.log(Level.WARNING, e.getMessage(), e)
76+
Nil
6977
added.size
78+
end visitClassfile
7079

7180
def visitWorkspaceSymbol(
7281
path: java.nio.file.Path,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package tests.pc
2+
3+
import coursierapi.Dependency
4+
import tests.BaseCompletionSuite
5+
6+
class ShadowingCompletionSuite extends BaseCompletionSuite {
7+
8+
override protected def extraDependencies(
9+
scalaVersion: String
10+
): Seq[Dependency] = Seq(
11+
Dependency.of("io.get-coursier", "interface", "1.0.18")
12+
)
13+
14+
check(
15+
"buffer".tag(IgnoreForScala3CompilerPC),
16+
"""package pkg
17+
|object Main {
18+
| val x = ListBuff@@
19+
|}
20+
|""".stripMargin,
21+
"""|ListBuffer[A](elems: A*): CC[A]
22+
|ListBuffer(i: Int): A
23+
|ListBuffer - scala.collection.mutable
24+
|""".stripMargin,
25+
compat = Map(
26+
"2" -> "ListBuffer - scala.collection.mutable"
27+
),
28+
)
29+
}

0 commit comments

Comments
 (0)