Skip to content

CC: Self-type constraints and cap interaction #24676

@bracevac

Description

@bracevac

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions