Skip to content

Commit 60460fa

Browse files
dwijnandWojciechMazur
authored andcommitted
Handle opaque aliases of arrays in Space erase
[Cherry-picked 4421d12]
1 parent 20a3c73 commit 60460fa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ object SpaceEngine {
458458
*
459459
* @param inArray whether `tp` is a type argument to `Array`
460460
* @param isValue whether `tp` is the type which match against values
461+
* @param isTyped whether `tp` is the type from a `Typed` tree
461462
*
462463
* If `isValue` is true, then pattern-bound symbols are erased to its upper bound.
463464
* This is needed to avoid spurious unreachable warnings. See tests/patmat/i6197.scala.
@@ -468,7 +469,7 @@ object SpaceEngine {
468469
WildcardType
469470

470471
case tp @ AppliedType(tycon, args) =>
471-
val inArray = tycon.isRef(defn.ArrayClass)
472+
val inArray = tycon.isRef(defn.ArrayClass) || tp.translucentSuperType.isRef(defn.ArrayClass)
472473
val args2 =
473474
if isTyped && !inArray then args.map(_ => WildcardType)
474475
else args.map(arg => erase(arg, inArray = inArray, isValue = false))

tests/pos/i18364.Tup.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Capturing the regression will implementing the fix for i18364
2+
// That broke in CI, "case _" "Unreachable case except for null"
3+
// Because IArray is an opaque alias of Array
4+
object Tup:
5+
/** Convert an immutable array into a tuple of unknown arity and types */
6+
def fromIArray[T](xs: IArray[T]): Tuple =
7+
val xs2: IArray[Object] = xs match
8+
case xs: IArray[Object] @unchecked => xs
9+
case _ => xs.map(_.asInstanceOf[Object])
10+
runtime.Tuples.fromIArray(xs2)

0 commit comments

Comments
 (0)