Last active
January 3, 2016 04:09
-
-
Save manjuraj/8406896 to your computer and use it in GitHub Desktop.
type selection vs type projection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> :pa | |
class Outer { | |
trait Inner // nested type | |
def y = new Inner {} | |
def foo(x: Inner) = null // path-dependent type - same as `def foo(x: this.Inner) = null` | |
def bar(x: Outer#Inner) = null // type projection | |
} | |
scala> val x = new Outer | |
x: Outer = Outer@33dd3a26 | |
scala> val y = new Outer | |
y: Outer = Outer@7bf7fb55 | |
scala> x.y | |
res1: x.Inner = Outer$$anon$1@1eb049ba | |
scala> x.foo(x.y) | |
res2: Null = null | |
scala> x.foo(y.y) | |
<console>:11: error: type mismatch; | |
found : y.Inner | |
required: x.Inner | |
x.foo(y.y) | |
^ | |
scala> x.bar(y.y) | |
res4: Null = null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment