File tree 2 files changed +13
-9
lines changed
compiler/src/dotty/tools/dotc
2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -100,20 +100,22 @@ object JavaNullInterop {
100
100
101
101
/** Should we nullify `tp` at the outermost level? */
102
102
def needsNull (tp : Type ): Boolean =
103
- ! outermostLevelAlreadyNullable && (tp match {
103
+ ! ( outermostLevelAlreadyNullable || (tp match {
104
104
case tp : TypeRef =>
105
105
// We don't modify value types because they're non-nullable even in Java.
106
- ! tp.symbol.isValueClass &&
106
+ tp.symbol.isValueClass
107
+ // We don't modify unit types.
108
+ || tp.isRef(defn.UnitClass )
107
109
// We don't modify `Any` because it's already nullable.
108
- ! tp.isRef(defn.AnyClass ) &&
110
+ || tp.isRef(defn.AnyClass )
109
111
// We don't nullify Java varargs at the top level.
110
112
// Example: if `setNames` is a Java method with signature `void setNames(String... names)`,
111
113
// then its Scala signature will be `def setNames(names: (String|Null)*): Unit`.
112
114
// This is because `setNames(null)` passes as argument a single-element array containing the value `null`,
113
115
// and not a `null` array.
114
- ! tp.isRef(defn.RepeatedParamClass )
116
+ || ! ctx.flexibleTypes && tp.isRef(defn.RepeatedParamClass )
115
117
case _ => true
116
- })
118
+ }))
117
119
118
120
override def apply (tp : Type ): Type = tp match {
119
121
case tp : TypeRef if needsNull(tp) => nullify(tp)
Original file line number Diff line number Diff line change @@ -970,13 +970,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
970
970
// A sequence argument `xs: _*` can be either a `Seq[T]` or an `Array[_ <: T]`,
971
971
// irrespective of whether the method we're calling is a Java or Scala method,
972
972
// so the expected type is the union `Seq[T] | Array[_ <: T]`.
973
- val ptArg =
973
+ val pt1 = pt.stripFlexible
974
+ val ptArg0 =
974
975
// FIXME(#8680): Quoted patterns do not support Array repeated arguments
975
976
if ctx.mode.isQuotedPattern then
976
- pt .translateFromRepeated(toArray = false , translateWildcard = true )
977
+ pt1 .translateFromRepeated(toArray = false , translateWildcard = true )
977
978
else
978
- pt.translateFromRepeated(toArray = false , translateWildcard = true )
979
- | pt.translateFromRepeated(toArray = true , translateWildcard = true )
979
+ pt1.translateFromRepeated(toArray = false , translateWildcard = true )
980
+ | pt1.translateFromRepeated(toArray = true , translateWildcard = true )
981
+ val ptArg = if pt1 eq pt then ptArg0 else FlexibleType (ptArg0)
980
982
val expr0 = typedExpr(tree.expr, ptArg)
981
983
val expr1 = if ctx.explicitNulls && (! ctx.mode.is(Mode .Pattern )) then
982
984
if expr0.tpe.isNullType then
You can’t perform that action at this time.
0 commit comments