Closed
Description
The problem exists in both 2.7 and 2.8. When I try to compile this code:
object Test extends Application {
def x: A.type = A
def y: B[A.type] = new B(A)
}
object A
class B[N](n: N)
, I have no problem with defining x. For the definition of y however I get:
Test.scala:3: error: type mismatch;
found : B[object A]
required: B[A.type]
If I look at the compiler's typer phase, the two definitions are as follows:
scalac -Xprint:typer Test.scala
def x: object A = A;
def y: B[A.type] = new B[object A](A)
We see in the first definition that "A.type" is simply translated into "object A" : the two expressions seem to mean the same thing. However in the second definition they obviously do not, as they are causing a type mismatch.
I can compile the definition of y if I force the type parameter to A.type:
def y: B[A.type] = new B[A.type](A)
My question : do "object A" and A.type mean the same thing, or not ? If not, why does the definition of x work ? If they do, why does the definition of y fail ? Thanks