Skip to content

Instantly share code, notes, and snippets.

@xeno-by
Created May 6, 2012 13:47
Show Gist options
  • Save xeno-by/2622387 to your computer and use it in GitHub Desktop.
Save xeno-by/2622387 to your computer and use it in GitHub Desktop.
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)
}
}
@xeno-by
Copy link
Author

xeno-by commented May 6, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment