Skip to content

Commit 3f4be93

Browse files
committed
Simplify GenericArray extractor
1 parent 94203bc commit 3f4be93

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ object GenericSignatures {
363363
* e.g. with "tagged types" like Array[Int] with T.
364364
*/
365365
private def unboundedGenericArrayLevel(tp: Type)(implicit ctx: Context): Int = tp match {
366-
case GenericArray(level, core) if !(core <:< defn.AnyRefType) =>
366+
case GenericArray(core, level) if !(core <:< defn.AnyRefType) =>
367367
level
368368
case AndType(tp1, tp2) =>
369369
unboundedGenericArrayLevel(tp1) max unboundedGenericArrayLevel(tp2)
@@ -426,8 +426,7 @@ object GenericSignatures {
426426
* In short, members of an existential type (e.g. `T` in `forSome { type T }`) can have pretty arbitrary
427427
* owners (e.g. when computing lubs, <root> is used). All packageClass symbols have `isJavaDefined == true`.
428428
*/
429-
case _: TypeRef =>
430-
val sym = tp.typeSymbol
429+
case RefOrAppliedType(sym, tp, _) =>
431430
if (sym.isAbstractType && (!sym.owner.is(JavaDefined) || sym.is(Scala2Existential)))
432431
tp
433432
else
@@ -436,13 +435,6 @@ object GenericSignatures {
436435
case bounds: TypeBounds =>
437436
bounds
438437

439-
case AppliedType(tp, _) =>
440-
val sym = tp.typeSymbol
441-
if (sym.isAbstractType && (!sym.owner.is(JavaDefined) || sym.is(Scala2Existential)))
442-
tp
443-
else
444-
NoType
445-
446438
case _ =>
447439
NoType
448440
}
@@ -451,18 +443,16 @@ object GenericSignatures {
451443
* then Some((N, T)) where N is the number of Array constructors enclosing `T`,
452444
* otherwise None. Existentials on any level are ignored.
453445
*/
454-
def unapply(tp: Type)(implicit ctx: Context): Option[(Int, Type)] = tp.widenDealias match {
455-
case AppliedType(tp, arg :: Nil) =>
456-
val test = tp.typeSymbol == defn.ArrayClass
457-
if (!test) return None
446+
def unapply(tp: Type)(implicit ctx: Context): Option[(Type, Int)] = tp.widenDealias match {
447+
case defn.ArrayOf(arg) =>
458448
genericCore(arg) match {
459449
case NoType =>
460-
unapply(arg) match {
461-
case Some((level, core)) => Some((level + 1, core))
462-
case None => None
450+
arg match {
451+
case GenericArray(core, level) => Some((core, level + 1))
452+
case _ => None
463453
}
464454
case core =>
465-
Some((1, core))
455+
Some((core, 1))
466456
}
467457
case _ =>
468458
None

0 commit comments

Comments
 (0)