Skip to content

Instantly share code, notes, and snippets.

@jsuereth
Created June 30, 2010 15:35
Show Gist options
  • Save jsuereth/458803 to your computer and use it in GitHub Desktop.
Save jsuereth/458803 to your computer and use it in GitHub Desktop.
scala> class Foo {
| type T = this.type
| def cloneit : T = {
| val x = new Foo
| x match {
| case y : T => y
| case _ => error("ZOMG")
| }
| }
| }
<console>:11: error: type mismatch;
found : y.type (with underlying type Foo.this.T)
required: Foo.this.T
case y : T => y
@jsuereth
Copy link
Author

Locking down the abstract type T still results in the type error!

scala> class Foo {            
   | final type T = this.type
   | def cloneit : T = {     
   |    val x = new Foo            
   |    x match {
   |      case y : T => y
   |      case _ => error("ZOMG")
   |    }
   | }
   | }
<console>:11: error: type mismatch;
 found   : y.type (with underlying type Foo.this.T)
 required: Foo.this.T
            case y : T => y

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