Skip to content

Fix compiler crash in sealedStrictDescendants #15919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to skip the whole thing if the symbol is a type, otherwise it will recompute every time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean, could you elaborate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I've come across this again, the problem is calling children recursively in sealedStrictDescendants, and the isAllOf(JavaEnumTrait) will also return true for java enum cases, so best to check that it is also a class


annotations.collect { case Annotation.Child(child) => child }.reverse
end children
Expand Down
14 changes: 14 additions & 0 deletions compiler/test/dotty/tools/dotc/core/SealedDescendantsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""}")
Expand Down