From f73965ff319acc9ce4528584109380f9b0c7be88 Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Tue, 10 Oct 2023 12:34:57 +0200 Subject: [PATCH] bugfix: exhaustive match on stale symbols 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 --- .../scala/meta/internal/pc/MetalsGlobal.scala | 3 +-- .../scala/tests/pc/CompletionMatchSuite.scala | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/MetalsGlobal.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/MetalsGlobal.scala index 12ad97bd256..256c54688dc 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/MetalsGlobal.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/MetalsGlobal.scala @@ -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) diff --git a/tests/cross/src/test/scala/tests/pc/CompletionMatchSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionMatchSuite.scala index 256a67c920b..be1e3ad46de 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionMatchSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionMatchSuite.scala @@ -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, + ) + }