Skip to content

Instantly share code, notes, and snippets.

@SethTisue
Created July 24, 2015 22:15
Show Gist options
  • Save SethTisue/dcb512a9cafd7caf920e to your computer and use it in GitHub Desktop.
Save SethTisue/dcb512a9cafd7caf920e to your computer and use it in GitHub Desktop.
scala> import scala.language.existentials
import scala.language.existentials
scala> class Outer { class Inner }
defined class Outer
scala> def f[I <: o.Inner forSome { val o: Outer }](i1: I, i2: I) = ()
f: [I <: o.Inner forSome { val o: Outer }](i1: I, i2: I)Unit
scala> val o1, o2 = new Outer
o1: Outer = Outer@52d455b8
o2: Outer = Outer@4f4a7090
scala> val i1, i2 = new o1.Inner
i1: o1.Inner = Outer$Inner@3ab39c39
i2: o1.Inner = Outer$Inner@2eee9593
scala> val i3 = new o2.Inner
i3: o2.Inner = Outer$Inner@3ac3fd8b
scala> f(i1, i2)
scala> f(i1, i3)
<console>:18: error: inferred type arguments [Outer#Inner] do not conform to method f's type parameter bounds [I <: o.Inner forSome { val o: Outer }]
f(i1, i3)
^
<console>:18: error: type mismatch;
found : o1.Inner
required: I
f(i1, i3)
^
<console>:18: error: type mismatch;
found : o2.Inner
required: I
f(i1, i3)
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment