-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathi16018.scala
More file actions
58 lines (49 loc) · 2.26 KB
/
i16018.scala
File metadata and controls
58 lines (49 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Regression test for #16018: type inference with `_ <: T` wildcards in
// pattern matching over capture-converted scrutinees.
//
// Coverage axes for the positive matrix:
// 1. The mbovel minimization (single wildcard via List.map) — was fixed
// since 3.2.0, kept here as a pin.
// 2. Pure-Scala collections — never trigger the capture-conversion path.
// 3. Identity / generic Scala helpers over the wildcard-bearing collection.
//
// The dual cases reached through Java-generic interop (java.lang.Iterable /
// java.util.List), which were the original akka regression, are in
// tests/pos/i16018b.scala.
object Test:
class Box[T](val value: T)
class Container[+S, +M]
class SubContainer[+S, +M] extends Container[S, M]
// ---- 1. mbovel's minimized case from #16018 ------------------------
def f1[T](l: List[Box[? <: T]]): List[T] = l.map(_.value)
// 1b. Variant: returning the wildcard-bearing element preserved.
def f1b[T](l: List[Box[? <: T]]): List[Box[? <: T]] = l.map(identity)
// ---- 2. Pure-Scala scrutinee — never goes through capture conversion -
def f2[M](xs: scala.collection.immutable.Seq[Container[Any, ? <: M]])
: scala.collection.immutable.Seq[Container[Any, M]] =
xs.collect {
case g: SubContainer[Any, M] @unchecked => g
case other => other
}
// 2b. Variant: `.map` instead of `.collect`.
def f2b[M](xs: scala.collection.immutable.Seq[Container[Any, ? <: M]])
: scala.collection.immutable.Seq[Container[Any, M]] =
xs.map {
case g: SubContainer[Any, M] @unchecked => g
case other => other
}
// 2c. Variant: List instead of Seq.
def f2c[M](xs: List[Container[Any, ? <: M]])
: List[Container[Any, M]] =
xs.collect {
case g: SubContainer[Any, M] @unchecked => g
case other => other
}
// ---- 3. Generic helper that stays pure-Scala does not skolemize ----
def idSeq[T](it: Iterable[T]): scala.collection.immutable.Seq[T] = ???
def f3[M](xs: List[Container[Any, ? <: M]])
: scala.collection.immutable.Seq[Container[Any, M]] =
idSeq(xs).collect {
case g: SubContainer[Any, M] @unchecked => g
case other => other
}