Skip to content

Instantly share code, notes, and snippets.

@manjuraj
Last active January 3, 2016 04:09
Show Gist options
  • Save manjuraj/8406896 to your computer and use it in GitHub Desktop.
Save manjuraj/8406896 to your computer and use it in GitHub Desktop.
type selection vs type projection
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