Created
May 6, 2012 13:47
-
-
Save xeno-by/2622387 to your computer and use it in GitHub Desktop.
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
trait StuffBase { | |
type Base | |
type Foo <: Base | |
val Foo: FooExtractor | |
implicit val FooTag: ClassTag[Foo] | |
abstract class FooExtractor { | |
def apply(x: Int): Foo | |
def unapply(foo: Foo): Option[Int] | |
} | |
type Bar <: Base | |
val Bar: BarExtractor | |
implicit val BarTag: ClassTag[Bar] | |
abstract class BarExtractor { | |
def apply(x: String): Bar | |
def unapply(bar: Bar): Option[String] | |
} | |
} | |
object Stuff extends StuffBase { | |
class Base | |
case class Foo(x: Int) extends Base | |
object Foo extends FooExtractor | |
implicit val FooTag = classTag[Foo] | |
case class Bar(x: String) extends Base | |
object Bar extends BarExtractor | |
implicit val BarTag = classTag[Bar] | |
} | |
object Test extends App { | |
val stuff: StuffBase = Stuff | |
import stuff._ | |
val base: Base = Foo(100) | |
base match { | |
case Bar(x: String) => println("bar: " + x) | |
case Foo(x: Int) => println("foo: " + x) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test.scala:40: warning: abstract type Test.stuff.Bar in type pattern Test.stuff.Bar is unchecked since it is eliminated by erasure
case Bar(x: String) => println("bar: " + x)
^
Test.scala:41: warning: abstract type Test.stuff.Foo in type pattern Test.stuff.Foo is unchecked since it is eliminated by erasure
case Foo(x: Int) => println("foo: " + x)
^
two warnings found