Skip to content

Commit 87a6f70

Browse files
committed
Adjust elem type
1 parent 01f040b commit 87a6f70

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Decorators._
1515
import Denotations._, SymDenotations._
1616
import TypeErasure.erasure
1717
import DenotTransformers._
18+
import NullOpsDecorator._
1819

1920
object ElimRepeated {
2021
val name: String = "elimRepeated"
@@ -335,6 +336,9 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
335336
val array = tp.translateFromRepeated(toArray = true) // Array[? <: T]
336337
val element = array.elemType.hiBound // T
337338

338-
if element <:< defn.AnyRefType || element.typeSymbol.isPrimitiveValueClass then array
339+
340+
if element <:< defn.AnyRefType
341+
|| ctx.mode.is(Mode.SafeNulls) && element.stripNull <:< defn.AnyRefType
342+
|| element.typeSymbol.isPrimitiveValueClass then array
339343
else defn.ArrayOf(TypeBounds.upper(AndType(element, defn.AnyRefType))) // Array[? <: T & AnyRef]
340344
}

0 commit comments

Comments
 (0)