From 09dd5cb4df2f46c382fa1ecf05fca8f6196870b9 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 14 Aug 2023 13:06:21 +0100 Subject: [PATCH] Handle opaque aliases of arrays in Space erase --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 3 ++- tests/pos/i18364.Tup.scala | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i18364.Tup.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index d6c557eb2bf0..e47a2d5671cb 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -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. @@ -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)) diff --git a/tests/pos/i18364.Tup.scala b/tests/pos/i18364.Tup.scala new file mode 100644 index 000000000000..806342934e67 --- /dev/null +++ b/tests/pos/i18364.Tup.scala @@ -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)