Interaction between variance markers and recursive generic types
24K reputation · 26 Oct 2020, 05:08 UTC
Generic Type Variance in Ceylon
Ceylon implements a static type system for the JVM that utilizes covariance and contravariance to provide more flexible generic subtyping than standard Java. This is typically managed through type constraints and variance markers on generic parameters.
A specific design challenge arises when applying these variance markers to deep recursive generic types within complex inheritance hierarchies. It is unclear how the compiler resolves type safety when a generic type refers to itself while simultaneously being marked as covariant or contravariant.
Which rules govern the interaction between variance markers and recursive generic types in these edge-case inheritance scenarios? Does the compiler prioritize the variance marker or the recursive constraint during type erasure?