Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ trait Applications extends Compatibility {
// For `Rec()` we do `Boolean`
if componentTypes.isEmpty then defn.BooleanType
else if isVararg then
val defn.ArrayOf(elemType) = componentTypes.last.runtimeChecked
val defn.ArrayOf(elemType) = componentTypes.last.stripNull().runtimeChecked
val wrapperType = defn.Array_UnapplySeqWrapper.typeRef.appliedTo(elemType)
// For `Rec(T*)` we do `Array.UnapplySeqWrapper[T]`
if componentTypes.length == 1 then wrapperType
Expand Down Expand Up @@ -1948,7 +1948,7 @@ trait Applications extends Compatibility {
if fields.isEmpty then Literal(Constant(true))
else if isVararg then
val lastField = accessor(fields.last)
val defn.ArrayOf(lastElemType) = lastField.tpe.runtimeChecked
val defn.ArrayOf(lastElemType) = lastField.tpe.stripNull().runtimeChecked
val lastFieldSeq = ref(defn.ArrayModule.requiredMethod(nme.unapplySeq))
.appliedToType(lastElemType).appliedTo(lastField)
if fields.length == 1 then lastFieldSeq
Expand Down
4 changes: 4 additions & 0 deletions tests/explicit-nulls/pos/java-record-varargs-src/J.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class J {
public record RecVarOnly(String... xs) {}
public record RecVar(int x, String... xs) {}
}
15 changes: 15 additions & 0 deletions tests/explicit-nulls/pos/java-record-varargs-src/S.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import J.*

def varargOnly(r: RecVarOnly): Unit =
r match
case RecVarOnly(xs*) => xs.foreach(x => ())
r match
case RecVarOnly(a, rest*) => ()
case _ => ()

def varargWithPrefix(r: RecVar): Unit =
r match
case RecVar(x, xs*) => xs.foreach(x => ())
r match
case RecVar(x, a, b) => ()
case _ => ()
Loading