diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index a1752ccc0976..89f79c1401cb 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1626,7 +1626,7 @@ object SymDenotations { // is defined in the same scope as `cls` or in the companion object of `cls`. completeChildrenIn(owner) completeChildrenIn(companionClass) - setFlag(ChildrenQueried) + if isType then setFlag(ChildrenQueried) annotations.collect { case Annotation.Child(child) => child }.reverse end children diff --git a/compiler/test/dotty/tools/dotc/core/SealedDescendantsTest.scala b/compiler/test/dotty/tools/dotc/core/SealedDescendantsTest.scala index 0ae9069c03d1..b3a7a3941a3f 100644 --- a/compiler/test/dotty/tools/dotc/core/SealedDescendantsTest.scala +++ b/compiler/test/dotty/tools/dotc/core/SealedDescendantsTest.scala @@ -91,6 +91,20 @@ class SealedDescendantsTest extends DottyTest { ) end hierarchicalSharedChildrenB + @Test + def javaEnum_i15908: Unit = + val source = """package testsealeddescendants""" + checkCompile("typer", source) { (_, context) => + given Context = context + val cls = requiredClass("java.nio.file.AccessMode") + + assertEquals( + List("val READ", "val WRITE", "val EXECUTE"), + cls.sealedStrictDescendants.map(_.toString) + ) + } + end javaEnum_i15908 + def expectedDescendents(source: String, root: String, expected: List[String]) = exploreRoot(source, root) { rootCls => val descendents = rootCls.sealedDescendants.map(sym => s"${sym.name}${if (sym.isTerm) ".type" else ""}")