scala3
scala3 copied to clipboard
CC: Self-type constraints and cap interaction
Compiler version
3.8.1-RC1-bin-20251205-cd32c6f-NIGHTLY
Minimized code
def example(a: AnyRef^, b: AnyRef^, c: AnyRef^) =
abstract class Root:
this: Root^{a,b} =>
class Sub extends Root:
val f: AnyRef^ = c
Output
This compiles.
Expectation
It shouldn't: Judging by the language reference, we expect the capture set of a self
type to restrict the captures of subclasses. This example seems counter to this intuition. Oddly enough, if we make the self of Sub explicit, like so:
class Sub extends Root:
this: Sub^ =>
val fld: AnyRef^ = c
Then we get an error, as desired.