A possible divergence from spec in typing of (new C).O

While trying to answer my Stack Overflow question Does Scala have syntax for projection of a nested singleton type?, Andrey Tyukin noticed that Specification 6.4 says

For other expressions e, e.x is typed as if it was { val y = e; y.x }, for some fresh name y.


class C {
  object O

val x: c.O.type forSome { val c: C } = (new C).O // doesn't compile
val o: c.O.type forSome { val c: C } = { val c1 = new C; c1.O } // compiles

Is this consistent with the specification for some reason I am missing, or a bug in the compiler (or the specification)?

To me it does seem like x should compile; the error message says required type is

c.type#O.type forSome { type c.type <: ScalaFiddle.this.C with scala.this.Singleton{} }
1 Like