Reputation: 41909
As I understand the def bar(x: X#Inner)
signature, it simply requires any instance of Inner
to compile successfully. Whereas, foo(x: this.Inner)
will only compile with the same Outer.Inner
class instance.
While reading Scala in Depth, I put this code into REPL, but I'm getting a compile-time error.
scala> class Outer {
| trait Inner
| def y = new Inner {}
| def foo(x: this.Inner) = null
| def bar(x: X#Inner) = null
| }
<console>:11: error: not found: type X
def bar(x: X#Inner) = null
^
Also, what is the compile-time error here?
Upvotes: 0
Views: 152
Reputation: 67280
The X
in X#Inner
refers to the outer type. You do not have a type X
anywhere, that's what the compiler error says exactly.
In your example you will want to refer to type Outer
instead:
class Outer {
trait Inner
def foo(x: this.Inner) = ???
def bar(x: Outer#Inner) = ???
}
Upvotes: 1
Reputation: 161
X#Inner
should be Outer#Inner
,I think the author of Scala in depth
just typed falsely in the book.
Upvotes: 0