File tree 7 files changed +56
-1
lines changed
compiler/src/dotty/tools/dotc
sbt-test/source-dependencies/sealed-extends-sealed
7 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -1614,6 +1614,26 @@ object SymDenotations {
1614
1614
1615
1615
annotations.collect { case Annotation .Child (child) => child }.reverse
1616
1616
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
1617
1637
}
1618
1638
1619
1639
/** The contents of a class definition during a period
Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
221
221
val modifiers = apiModifiers(sym)
222
222
val anns = apiAnnotations(sym).toArray
223
223
val topLevel = sym.isTopLevelClass
224
- val childrenOfSealedClass = sym.children .sorted(classFirstSort).map(c =>
224
+ val childrenOfSealedClass = sym.sealedDescendants .sorted(classFirstSort).map(c =>
225
225
if (c.isClass)
226
226
apiType(c.typeRef)
227
227
else
Original file line number Diff line number Diff line change
1
+ sealed trait Z
2
+ sealed trait A extends Z
3
+ class B extends A
4
+ class C extends A
Original file line number Diff line number Diff line change
1
+ object App {
2
+ def foo (z : Z ) = z match {
3
+ case _ : B =>
4
+ case _ : C =>
5
+ }
6
+ }
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments