Skip to content

Commit

Permalink
bugfix: exhaustive match on stale symbols
Browse files Browse the repository at this point in the history
It doesn't reproduce in tests, but for case classes/objects defined inside an object
we get stale symbols and filter out the not-stale ones
  • Loading branch information
jkciesluk committed Oct 10, 2023
1 parent 40fb585 commit 5639187
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,9 @@ class MetalsGlobal(
def loop(sym: Symbol): Unit = {
sym.knownDirectSubclasses.foreach { child =>
val unique = semanticdbSymbol(child)
if (!isVisited(unique)) {
if (!isVisited(unique) && !child.isStale) {
isVisited += unique
if (child.name.containsName(CURSOR)) ()
else if (child.isStale) ()
else if (child.name == tpnme.LOCAL_CHILD) ()
else if (child.isSealed && (child.isAbstract || child.isTrait)) {
loop(child)
Expand Down
23 changes: 23 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionMatchSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,27 @@ class CompletionMatchSuite extends BaseCompletionSuite {
filter = _.contains("exhaustive"),
)

check(
"stale-symbols",
"""
|package example
|
|object Main {
| val x: ScalaTargetType = ???
| val y = x match@@
|}
|sealed trait ScalaTargetType
|object ScalaTargetType {
| case object Scala2 extends ScalaTargetType
| case object Scala3 extends ScalaTargetType
| case object JS extends ScalaTargetType
| case object Native extends ScalaTargetType
| case object Typelevel extends ScalaTargetType
| case object ScalaCli extends ScalaTargetType
|}""".stripMargin,
"""|match
|match (exhaustive) ScalaTargetType (6 cases)
|""".stripMargin,
)

}

0 comments on commit 5639187

Please sign in to comment.