Skip to content

Commit 42e0f73

Browse files
committed
SI-7716 Exclude patmat synthetics from bounds checking
Consider this pattern match translation, that occurs *before* refchecks: scala> val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS scala> e match { case x => x } <console>:9: error: type arguments [_$1] do not conform to class Enum's type parameter bounds [E <: Enum[E]] e match { case x => x } ^ [[syntax trees at end of refchecks]] // <console> package $line5 { case <synthetic> val x1: Enum[_$1] = $line3.$read.$iw.$iw.e; case4(){ matchEnd3(x1) }; matchEnd3(x: Enum[_$1]){ x } RefChecks turns a blind eye to the non-conformant type `Enum[_$1]` in the label defs because of `65340ed4ad2e`. (Incidentally, that is far too broad, as I've noted in SI-7756.) This commit extends this exception to cover the synthetic ValDef `x1`. Commit log watchers might notice the similarities to SI-7694.
1 parent 8053c19 commit 42e0f73

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,9 +1826,11 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
18261826
case LabelDef(_, _, _) if treeInfo.hasSynthCaseSymbol(result) =>
18271827
val old = inPattern
18281828
inPattern = true
1829-
val res = deriveLabelDef(result)(transform)
1829+
val res = deriveLabelDef(result)(transform) // TODO SI-7756 Too broad! The code from the original case body should be fully refchecked!
18301830
inPattern = old
18311831
res
1832+
case ValDef(_, _, _, _) if treeInfo.hasSynthCaseSymbol(result) =>
1833+
deriveValDef(result)(transform) // SI-7716 Don't refcheck the tpt of the synthetic val that holds the selector.
18321834
case _ =>
18331835
super.transform(result)
18341836
}

test/files/pos/t7716.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object Test {
2+
def test: Unit = {
3+
val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS
4+
e match { case x => println(x) }
5+
6+
7+
trait TA[X <: CharSequence]
8+
val ta: TA[_] = new TA[String] {}
9+
10+
ta match {
11+
case _ => println("hi")
12+
}
13+
14+
def f(ta: TA[_]) = ta match { case _ => "hi" }
15+
}
16+
}

0 commit comments

Comments
 (0)