Skip to content

Commit d1679c3

Browse files
committed
Fix #5411: varargs with intersection type elements
We need to generate a ClassTag to construct a Java vararg array. Just computing the class symbol of the element type is not enough, as some types do not have class symbols. We need instead to compute the class symbol on the erased element type.
1 parent fcc35d2 commit d1679c3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Constants._
1313
import Decorators._
1414
import Denotations._, SymDenotations._
1515
import dotty.tools.dotc.ast.tpd
16+
import TypeErasure.erasure
1617
import DenotTransformers._
1718

1819
object ElimRepeated {
@@ -92,7 +93,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
9293
JavaSeqLiteral(elems, elemtpt)
9394
case _ =>
9495
val elemType = tree.tpe.elemType
95-
var elemClass = elemType.classSymbol
96+
var elemClass = erasure(elemType).classSymbol
9697
if (defn.NotRuntimeClasses.contains(elemClass)) elemClass = defn.ObjectClass
9798
ref(defn.DottyArraysModule)
9899
.select(nme.seqToArray)

tests/pos/i5411.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait A
2+
trait B
3+
object O {
4+
def m(x: Seq[A & B]) = java.util.Arrays.asList(x: _*)
5+
}

0 commit comments

Comments
 (0)