Why is T a type projection of this.type in expanded type designator C.this.type#T

Viewed 75

SLS 3.2.5 Type Designators indicates

trait C {
  type T
  val x: T
}

expands to

trait C {
  type T
  val x: C.this.type#T
}

I am familiar with .type notation in singleton types, but I am not sure how it translates to C.this.type#T. For example. what is this.type part trying to convey over just saying C#T?

1 Answers

In Scala specification primary concept is type projection rather than path-dependent type.

And path-dependent types are defined in terms of type projections (and singleton types).

For example for val c: C type c.T is c.type#T by definition.

And c.x has type c.T aka c.type#T.

Inside trait C such type (when instance c is not fixed) can be referred as T aka this.T aka this.type#T aka C.this.T aka C.this.type#T.

Related