Skip to content

Commit 0839123

Browse files
committed
Space: Revert how invariant targs are erased to fix regression
The motivating case (i16451) is complicated, because it involves unchecked type arguments. To fix the regression, I'm reverting the fix.
1 parent b40122f commit 0839123

File tree

10 files changed

+59
-15
lines changed

10 files changed

+59
-15
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+2-11
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,8 @@ object SpaceEngine {
458458
WildcardType
459459

460460
case tp @ AppliedType(tycon, args) =>
461-
val args2 =
462-
if tycon.isRef(defn.ArrayClass) then
463-
args.map(arg => erase(arg, inArray = true, isValue = false))
464-
else tycon.typeParams.lazyZip(args).map { (tparam, arg) =>
465-
if isValue && tparam.paramVarianceSign == 0 then
466-
// when matching against a value,
467-
// any type argument for an invariant type parameter will be unchecked,
468-
// meaning it won't fail to match against anything; thus the wildcard replacement
469-
WildcardType
470-
else erase(arg, inArray = false, isValue = false)
471-
}
461+
val inArray = tycon.isRef(defn.ArrayClass)
462+
val args2 = args.map(arg => erase(arg, inArray = inArray, isValue = false))
472463
tp.derivedAppliedType(erase(tycon, inArray, isValue = false), args2)
473464

474465
case tp @ OrType(tp1, tp2) =>

tests/neg-custom-args/fatal-warnings/suppressed-type-test-warnings.scala

+2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ object Test {
1818
def err2[A, B](value: Foo[A, B], a: A => Int): B = value match {
1919
case b: Bar[B] => // spurious // error
2020
b.x
21+
case _ => ??? // avoid fatal inexhaustivity warnings suppressing the uncheckable warning
2122
}
2223

2324
def fail[A, B](value: Foo[A, B], a: A => Int): B = value match {
2425
case b: Bar[Int] => // error
2526
b.x
27+
case _ => ??? // avoid fatal inexhaustivity warnings suppressing the uncheckable warning
2628
}
2729
}

tests/neg-custom-args/isInstanceOf/enum-approx2.scala

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ case class Fun[A, B](f: Exp[A => B]) extends Exp[A => B]
44
class Test {
55
def eval(e: Fun[Int, Int]) = e match {
66
case Fun(x: Fun[Int, Double]) => ??? // error
7+
case Fun(x: Exp[Int => String]) => ??? // error
8+
case _ =>
79
}
810
}

tests/neg-custom-args/isInstanceOf/i11178.scala

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ object Test1 {
1212
def test[A](bar: Bar[A]) =
1313
bar match {
1414
case _: Bar[Boolean] => ??? // error
15+
case _ => ???
1516
}
1617
}
1718

tests/neg-custom-args/isInstanceOf/i8932.scala

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Dummy extends Bar[Nothing] with Foo[String]
66
def bugReport[A](foo: Foo[A]): Foo[A] =
77
foo match {
88
case bar: Bar[A] => bar // error
9+
case dummy: Dummy => ???
910
}
1011

1112
def test = bugReport(new Dummy: Foo[String])
File renamed without changes.

tests/neg/i16451.scala renamed to tests/pending/neg/i16451.scala

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// scalac: -Werror
22
enum Color:
33
case Red, Green
4-
//sealed trait Color
5-
//object Color:
6-
// case object Red extends Color
7-
// case object Green extends Color
84

95
case class Wrapper[A](value: A)
106

tests/pos/i17230.bootstrap.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
type Untyped = Type | Null
2+
3+
class Type
4+
abstract class SearchFailureType extends Type
5+
6+
abstract class Tree[+T <: Untyped]:
7+
def tpe: T = null.asInstanceOf[T]
8+
9+
class SearchFailureIdent[+T <: Untyped] extends Tree[T]
10+
11+
class Test_i17230_bootstrap:
12+
def t1(arg: Tree[Type]) = arg match
13+
case arg: SearchFailureIdent[?] => arg.tpe match
14+
case x: SearchFailureType =>
15+
case _ =>
16+
case _ =>

tests/pos/i17230.min1.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// scalac: -Werror
2+
trait Foo:
3+
type Bar[_]
4+
5+
object Foo:
6+
type Aux[B[_]] = Foo { type Bar[A] = B[A] }
7+
8+
class Test:
9+
def t1[B[_]](self: Option[Foo.Aux[B]]) = self match
10+
case Some(_) => 1
11+
case None => 2
12+
13+
def t2[B[_]](self: Option[Foo.Aux[B]]) = self match
14+
case Some(f) => 1
15+
case None => 2

tests/pos/i17230.orig.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// scalac: -Werror
2+
import scala.util.*
3+
4+
trait Transaction {
5+
type State[_]
6+
}
7+
object Transaction {
8+
type of[S[_]] = Transaction { type State[A] = S[A] }
9+
}
10+
trait DynamicScope[State[_]]
11+
12+
case class ScopeSearch[State[_]](self: Either[Transaction.of[State], DynamicScope[State]]) {
13+
14+
def embedTransaction[T](f: Transaction.of[State] => T): T =
15+
self match {
16+
case Left(integrated) => ???
17+
case Right(ds) => ???
18+
}
19+
}
20+

0 commit comments

Comments
 (0)