David Meyer
08/12/2025, 8:43 PMclass A : A.B {
interface B
}
This actually worked perfectly in Kotlin 2.0.21. We drilled down further and found that it worked in 2.1.10 and broke starting with 2.1.20.
I've done quite a bit of research to try to figure this out before coming here:
• Related issue: https://youtrack.jetbrains.com/issue/KT-17455/Confusing-error-message-Theres-a-cycle-in-the-inheritance-hierarchy-for-this-type-when-outer-class-inherits-nested-class
◦ This is a really old issue and indicates that Java does not allow this either and that it shouldn't be allowed in Kotlin, presumably for JVM compatibility. It seems the resolution was to make the error message less confusing.
• K2 issue: https://youtrack.jetbrains.com/projects/KT/issues/KT-78909/K2-Missing-diagnostics-CYCLIC[…]r-recursive-class-inheritance-leads-to-StackOverflowError
◦ This is a different issue, but related to cyclic inheritance. A comment seems to indicate that detection of cyclic inheritance may have been missing since Kotlin 2.0.0.
• Related Slack message: https://kotlinlang.slack.com/archives/C7L3JB43G/p1721904517084629?thread_ts=1721904003.811169&cid=C7L3JB43G
◦ Slightly different scenario (outer types inherit from a different outer type's nested type). However, the explanation as to why this isn't allowed may still apply. However, the quoted error message suggests that this was before K2.
My conclusion, based on all of this, is that this is probably something that was never supposed to be allowed in Kotlin, and this was "fixed" in 2.1.20 so that it no longer works. However, this feels a lot like a breaking change to us, since it did work before, and now it no longer works.
It also begs the question: If it actually did work, then is this really an artificial limitation now? Could Kotlin allow this type structure now? 🤔dmitriy.novozhilov
08/14/2025, 9:12 AMSlightly different scenario (outer types inherit from a different outer type's nested type). However, the explanation as to why this isn't allowed may still apply. However, the quoted error message suggests that this was before K2.This explanation is indeed correct for your example too. And it's not related to K1 or K2 implementation details. This is a conceptual resolution problem
David Meyer
08/17/2025, 3:32 AMCycle in supertypes and/or containing declarations detected. I changed the Kotlin dependency to 2.1.10, and the very same code compiled and ran just fine. Using IntelliJ. Interestingly, the IDE still underlines the code and says the same error message, but it builds and runs fine anyway.
Something must be different about the Kotlin Playground than doing it in a real Kotlin project.dmitriy.novozhilov
08/18/2025, 7:01 AMDavid Meyer
08/18/2025, 11:52 PMNick Lunyak
08/19/2025, 3:11 PMNick Lunyak
08/19/2025, 3:17 PMDavid Meyer
08/21/2025, 12:07 AM