Skip to content

Commit

Permalink
Handle opaque aliases of arrays in Space erase
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 15, 2023
1 parent 6453179 commit 079bffc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ object SpaceEngine {
*
* @param inArray whether `tp` is a type argument to `Array`
* @param isValue whether `tp` is the type which match against values
* @param isTyped whether `tp` is the type from a `Typed` tree
*
* If `isValue` is true, then pattern-bound symbols are erased to its upper bound.
* This is needed to avoid spurious unreachable warnings. See tests/patmat/i6197.scala.
Expand All @@ -459,7 +460,7 @@ object SpaceEngine {
WildcardType

case tp @ AppliedType(tycon, args) =>
val inArray = tycon.isRef(defn.ArrayClass)
val inArray = tycon.isRef(defn.ArrayClass) || tp.translucentSuperType.isRef(defn.ArrayClass)
val args2 =
if isTyped && !inArray then args.map(_ => WildcardType)
else args.map(arg => erase(arg, inArray = inArray, isValue = false))
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i18364.Tup.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Capturing the regression will implementing the fix for i18364
// That broke in CI, "case _" "Unreachable case except for null"
// Because IArray is an opaque alias of Array
object Tup:
/** Convert an immutable array into a tuple of unknown arity and types */
def fromIArray[T](xs: IArray[T]): Tuple =
val xs2: IArray[Object] = xs match
case xs: IArray[Object] @unchecked => xs
case _ => xs.map(_.asInstanceOf[Object])
runtime.Tuples.fromIArray(xs2)

0 comments on commit 079bffc

Please sign in to comment.