Skip to content

Commit b57d62a

Browse files
committed
fix #12634 - port sbt/zinc#979
Add sealedDescendants method to SymDenotation - recursive children of a symbol
1 parent a956774 commit b57d62a

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

+20
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,26 @@ object SymDenotations {
16141614

16151615
annotations.collect { case Annotation.Child(child) => child }.reverse
16161616
end children
1617+
1618+
/** Recursively assemble all children of this symbol, including this symbol.
1619+
* Preserves order of insertion.
1620+
*/
1621+
final def sealedDescendants(using Context): List[Symbol] =
1622+
@tailrec
1623+
def loop(syms: List[Symbol], acc: List[Symbol]): List[Symbol] = syms match
1624+
case sym :: syms1 =>
1625+
val notSeen = sym.children.filterConserve(!acc.contains(_))
1626+
if notSeen.isEmpty then
1627+
loop(syms1, acc)
1628+
else
1629+
loop(syms1 ::: notSeen, acc ::: notSeen)
1630+
case nil =>
1631+
acc
1632+
end loop
1633+
1634+
val lvl1 = children
1635+
loop(lvl1, this.symbol::lvl1)
1636+
end sealedDescendants
16171637
}
16181638

16191639
/** The contents of a class definition during a period

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
221221
val modifiers = apiModifiers(sym)
222222
val anns = apiAnnotations(sym).toArray
223223
val topLevel = sym.isTopLevelClass
224-
val childrenOfSealedClass = sym.children.sorted(classFirstSort).map(c =>
224+
val childrenOfSealedClass = sym.sealedDescendants.sorted(classFirstSort).map(c =>
225225
if (c.isClass)
226226
apiType(c.typeRef)
227227
else
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sealed trait Z
2+
sealed trait A extends Z
3+
class B extends A
4+
class C extends A
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object App {
2+
def foo(z: Z) = z match {
3+
case _: B =>
4+
case _: C =>
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sealed trait Z
2+
sealed trait A extends Z
3+
class B extends A
4+
class C extends A
5+
class D extends A
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sbt._
2+
import Keys._
3+
4+
object DottyInjectedPlugin extends AutoPlugin {
5+
override def requires = plugins.JvmPlugin
6+
override def trigger = allRequirements
7+
8+
override val projectSettings = Seq(
9+
scalaVersion := sys.props("plugin.scalaVersion"),
10+
scalacOptions ++= Seq("-source:3.0-migration", "-Xfatal-warnings")
11+
)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
> compile
2+
3+
# Introduce a new class C that also extends A
4+
$ copy-file changes/A.scala A.scala
5+
6+
# App.scala needs recompiling because the pattern match in it
7+
# is no longer exhaustive, which emits a warning
8+
-> compile

0 commit comments

Comments
 (0)