|
| 1 | +// This file is part of tests for inferring GADT constraints from type members, |
| 2 | +// which needed to be reverted because of soundness issues. |
| 3 | +// |
| 4 | +// Lines with "// limitation" are the ones that we could soundly allow. |
| 5 | +object Test { |
| 6 | + |
| 7 | + trait Expr { type T } |
| 8 | + trait IntLit extends Expr { type T <: Int } |
| 9 | + trait IntExpr extends Expr { type T = Int } |
| 10 | + |
| 11 | + type ExprSub[+A] = Expr { type T <: A } |
| 12 | + type ExprExact[A] = Expr { type T = A } |
| 13 | + |
| 14 | + trait IndirectIntLit extends Expr { type S <: Int; type T = S } |
| 15 | + trait IndirectIntExpr extends Expr { type S = Int; type T = S } |
| 16 | + |
| 17 | + type IndirectExprSub[+A] = Expr { type S <: A; type T = S } |
| 18 | + type IndirectExprSub2[A] = Expr { type S = A; type T <: S } |
| 19 | + type IndirectExprExact[A] = Expr { type S = A; type T = S } |
| 20 | + |
| 21 | + trait AltIndirectIntLit extends Expr { type U <: Int; type T = U } |
| 22 | + trait AltIndirectIntExpr extends Expr { type U = Int; type T = U } |
| 23 | + |
| 24 | + type AltIndirectExprSub[+A] = Expr { type U <: A; type T = U } |
| 25 | + type AltIndirectExprSub2[A] = Expr { type U = A; type T <: U } |
| 26 | + type AltIndirectExprExact[A] = Expr { type U = A; type T = U } |
| 27 | + |
| 28 | + def foo[A](e: IndirectExprExact[A]) = e match { |
| 29 | + case _: AltIndirectIntLit => |
| 30 | + val a: A = 0 // error |
| 31 | + val i: Int = ??? : A // limitation // error |
| 32 | + |
| 33 | + case _: AltIndirectExprSub[Int] => |
| 34 | + val a: A = 0 // error |
| 35 | + val i: Int = ??? : A // limitation // error |
| 36 | + |
| 37 | + case _: AltIndirectExprSub2[Int] => |
| 38 | + val a: A = 0 // error |
| 39 | + val i: Int = ??? : A // limitation // error |
| 40 | + |
| 41 | + case _: AltIndirectIntExpr => |
| 42 | + val a: A = 0 // limitation // error |
| 43 | + val i: Int = ??? : A // limitation // error |
| 44 | + |
| 45 | + case _: AltIndirectExprExact[Int] => |
| 46 | + val a: A = 0 // limitation // error |
| 47 | + val i: Int = ??? : A // limitation // error |
| 48 | + } |
| 49 | + |
| 50 | + def bar[A](e: IndirectExprSub[A]) = e match { |
| 51 | + case _: AltIndirectIntLit => |
| 52 | + val a: A = 0 // error |
| 53 | + val i: Int = ??? : A // error |
| 54 | + |
| 55 | + case _: AltIndirectExprSub[Int] => |
| 56 | + val a: A = 0 // error |
| 57 | + val i: Int = ??? : A // error |
| 58 | + |
| 59 | + case _: AltIndirectExprSub2[Int] => |
| 60 | + val a: A = 0 // error |
| 61 | + val i: Int = ??? : A // error |
| 62 | + |
| 63 | + case _: AltIndirectIntExpr => |
| 64 | + val a: A = 0 // limitation // error |
| 65 | + val i: Int = ??? : A // error |
| 66 | + |
| 67 | + case _: AltIndirectExprExact[Int] => |
| 68 | + val a: A = 0 // limitation // error |
| 69 | + val i: Int = ??? : A // error |
| 70 | + } |
| 71 | + |
| 72 | + def baz[A](e: IndirectExprSub2[A]) = e match { |
| 73 | + case _: AltIndirectIntLit => |
| 74 | + val a: A = 0 // error |
| 75 | + val i: Int = ??? : A // error |
| 76 | + |
| 77 | + case _: AltIndirectExprSub[Int] => |
| 78 | + val a: A = 0 // error |
| 79 | + val i: Int = ??? : A // error |
| 80 | + |
| 81 | + case _: AltIndirectExprSub2[Int] => |
| 82 | + val a: A = 0 // error |
| 83 | + val i: Int = ??? : A // error |
| 84 | + |
| 85 | + case _: AltIndirectIntExpr => |
| 86 | + val a: A = 0 // limitation // error |
| 87 | + val i: Int = ??? : A // error |
| 88 | + |
| 89 | + case _: AltIndirectExprExact[Int] => |
| 90 | + val a: A = 0 // limitation // error |
| 91 | + val i: Int = ??? : A // error |
| 92 | + } |
| 93 | +} |
0 commit comments