Skip to content

Instantly share code, notes, and snippets.

@Blaisorblade
Last active June 7, 2019 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blaisorblade/3e5a1102c0699f05f1c11333d785a077 to your computer and use it in GitHub Desktop.
Save Blaisorblade/3e5a1102c0699f05f1c11333d785a077 to your computer and use it in GitHub Desktop.
object Test {
abstract class ExprBase { s =>
type A
}
abstract class Lit extends ExprBase { s =>
type A = Int
val n: A
}
def castTest1(e1: ExprBase)(e2: e1.type)(x: e1.A): e2.A = x
def castTest2(e1: ExprBase { type A = Int })(e2: e1.type)(x: e1.A): e2.A = x
def castTest3(e1: ExprBase)(e2: ExprBase with e1.type)(x: e2.A): e1.A = x
def castTest4(e1: ExprBase { type A = Int })(e2: ExprBase with e1.type)(x: e2.A): e1.A = x
//fail:
// def castTestFail1(e1: ExprBase)(e2: Lit with e1.type)(x: e1.A): e2.A = x
// def castTestFail2(e1: ExprBase)(e2: Lit with e1.type)(x: e2.A): e1.A = x
def castTestFail3(e1: ExprBase)(e2: Lit with e1.type)(x: e1.A): e2.A = {
val y: e1.type with e2.type = e2
val z = x: y.A
z
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment