Skip to content

Commit 00a6c4a

Browse files
authored
Fix extracting the elemType of a union of arrays (#16569)
2 parents c208845 + ffa8ee3 commit 00a6c4a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ class TypeApplications(val self: Type) extends AnyVal {
533533
case JavaArrayType(elemtp) => elemtp
534534
case tp: OrType if tp.tp1.isBottomType => tp.tp2.elemType
535535
case tp: OrType if tp.tp2.isBottomType => tp.tp1.elemType
536-
case _ => self.baseType(defn.SeqClass).argInfos.headOption.getOrElse(NoType)
536+
case _ =>
537+
self.baseType(defn.SeqClass)
538+
.orElse(self.baseType(defn.ArrayClass))
539+
.argInfos.headOption.getOrElse(NoType)
537540
}
538541
}

tests/pos/i16562.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Test:
2+
val a: Array[Any] = Array[Any]()
3+
val b: Array[Any] = Array[Any]()
4+
5+
def ko(p: Boolean): Unit = foo((if p then a else b): _*)
6+
def ok(p: Boolean): Unit = foo({ val x = if p then a else b; x }: _*)
7+
8+
def foo(in: Any*): Unit = ()

0 commit comments

Comments
 (0)