Skip to content

Commit 2707c7b

Browse files
committed
More tests
1 parent 76a779d commit 2707c7b

File tree

7 files changed

+76
-4
lines changed

7 files changed

+76
-4
lines changed

tests/neg/aliasing-subtypes.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
object Test {
2+
3+
trait T {
4+
type A
5+
}
6+
7+
class C extends T { this: m.type =>
8+
type A >: Int | Test.A <: Int & Test.A
9+
10+
def reveal(x: A): Int = x
11+
def inject(x: Int): A = x
12+
13+
var a: A = ???
14+
x = a // OK!
15+
a = x // OK!
16+
}
17+
18+
val m: T = new C
19+
type A = m.A
20+
21+
var x: A = ???
22+
}

tests/neg/opaque-self-encoding.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
trait TS { type TX = Int }
21
trait TT { self: { type TX = Int } =>
32
type TX
43
def lift(x: Int): TX = x

tests/neg/opaque.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object opaquetypes {
88

99
opaque type U <: String // error
1010

11-
opaque type Fix[F[_]] = F[Fix[F]] // error: cyclic
11+
opaque type Fix[F[_]] = F[Fix[F]] // error: cyclic // error
1212

1313
opaque type O = String
1414

tests/pos/opaque-aliasing.scala

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
object Test {
2+
3+
opaque type A = Int
4+
type AA = A
5+
6+
var a: A = ???
7+
var aa: AA = ???
8+
9+
object A {
10+
val x: A = a
11+
a = x
12+
val y: A = aa
13+
aa = y
14+
15+
type BB = A
16+
val z1: BB = a
17+
val z2: BB = aa
18+
a = z1
19+
aa = z2
20+
}
21+
}
22+
object Test2 {
23+
24+
opaque type A[X] = X
25+
type AA[X] = A[X]
26+
27+
var a: A[Int] = ???
28+
var aa: AA[Int] = ???
29+
30+
object A {
31+
val x: A[Int] = a
32+
a = x
33+
val y: A[Int] = aa
34+
aa = y
35+
36+
type BB[X] = A[X]
37+
val z1: BB[Int] = a
38+
val z2: BB[Int] = aa
39+
a = z1
40+
aa = z2
41+
}
42+
}
File renamed without changes.

tests/pos/opaque-immutable-array.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
object ia {
2-
2+
import scala.reflect.ClassTag
33
import java.util.Arrays
44

55
opaque type IArray[A1] = Array[A1]
66

77
object IArray {
8+
def apply[A: ClassTag](xs: A*) = initialize(Array(xs: _*))
9+
810
def initialize[A](body: => Array[A]): IArray[A] = body
911
def size[A](ia: IArray[A]): Int = ia.length
1012
def get[A](ia: IArray[A], i: Int): A = ia(i)
@@ -20,6 +22,9 @@ object ia {
2022
// (note that this doesn't mutate the array).
2123
def binarySearch(ia: IArray[Long], elem: Long): Int =
2224
Arrays.binarySearch(ia, elem)
25+
26+
assert(size(apply(1, 2, 3)) == 3)
27+
assert(size(IArray(1, 2, 3)) == 3)
2328
}
2429

2530
// same as IArray.binarySearch but implemented by-hand.

tests/pos/opaque.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ object opaquetypes {
1818
// This is the second way to unlift the logarithm type
1919
def toDouble: Double = math.exp(`this`)
2020
def +(that: Logarithm): Logarithm = Logarithm(math.exp(`this`) + math.exp(that))
21-
def *(that: Logarithm): Logarithm = Logarithm(`this` + that)
21+
def *(that: Logarithm): Logarithm = apply(`this` + that)
2222
}
23+
24+
assert(exponent(LL) == 1.0)
2325
}
26+
27+
val LL: Logarithm = Logarithm(1)
2428
}
2529
object usesites {
2630
import opaquetypes._

0 commit comments

Comments
 (0)