-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathi16018b.scala
More file actions
47 lines (41 loc) · 2.05 KB
/
i16018b.scala
File metadata and controls
47 lines (41 loc) · 2.05 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
// Regression test for #16018: the akka-derived shapes.
//
// These exercise the path that motivated the original ticket: a value of
// type `J[? <: G[? <: M]]` (J a Java generic) flows through a method that
// re-projects it as a Scala collection, and is then `collect`/`map`-ed with
// a subtype pattern + a fallback `case other`. The combination triggers
// (i) `Inferencing.captureWildcards` — the Java-generic argument becomes
// a TypeBox.CAP skolem `?N.CAP`, and
// (ii) `Match` typing — pattern narrowing turns the first case body into
// `pat ∩ ?N.CAP`, while `case other` keeps the raw `?N.CAP`.
//
// Until the fix in `TypeComparer.compareCaptured` for wildcard-bound
// existential widening, the inferred result type could not escape the
// skolem cleanly. See:
// - tests/pos/i16018.scala — companion pos matrix (pure-Scala)
// - scala/scala3 #16018 — original bug report
object Test:
class Container[+S, +M]
class SubContainer[+S, +M] extends Container[S, M]
def seqOf[T](it: java.lang.Iterable[T]): scala.collection.immutable.Seq[T] = ???
// ---- f1: trigger via java.lang.Iterable ----------------------------
def f1[M](xs: java.lang.Iterable[? <: Container[Any, ? <: M]])
: scala.collection.immutable.Seq[Container[Any, M]] =
seqOf(xs).collect {
case g: SubContainer[Any, M] @unchecked => g
case other => other
}
// ---- f2: same trigger via java.util.List ---------------------------
def f2[M](xs: java.util.List[? <: Container[Any, ? <: M]])
: scala.collection.immutable.Seq[Container[Any, M]] =
seqOf(xs).collect {
case g: SubContainer[Any, M] @unchecked => g
case other => other
}
// ---- f3: same trigger via .map instead of .collect -----------------
def f3[M](xs: java.lang.Iterable[? <: Container[Any, ? <: M]])
: scala.collection.immutable.Seq[Container[Any, M]] =
seqOf(xs).map {
case g: SubContainer[Any, M] @unchecked => g
case other => other
}