Skip to content

Commit 5707343

Browse files
authored
Merge pull request #6859 from dotty-staging/fix-#6858
Fix #6858: Wrap array when passed to inlined varargs
2 parents a8b9b78 + 7b6f9a9 commit 5707343

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
255255
* @param arg the argument corresponding to the parameter
256256
* @param bindingsBuf the buffer to which the definition should be appended
257257
*/
258-
private def paramBindingDef(name: Name, paramtp: Type, arg: Tree,
258+
private def paramBindingDef(name: Name, paramtp: Type, arg0: Tree,
259259
bindingsBuf: mutable.ListBuffer[ValOrDefDef])(implicit ctx: Context): ValOrDefDef = {
260+
val arg = arg0 match {
261+
case Typed(arg1, tpt) if tpt.tpe.isRepeatedParam && arg1.tpe.derivesFrom(defn.ArrayClass) =>
262+
wrapArray(arg1, arg0.tpe.elemType)
263+
case _ => arg0
264+
}
260265
val argtpe = arg.tpe.dealiasKeepAnnots
261266
val isByName = paramtp.dealias.isInstanceOf[ExprType]
262267
var inlineFlags: FlagSet = InlineProxy

tests/run/i6858.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Test extends App {
2+
inline def foo(ys: Int*): Unit = bar(ys: _*)
3+
def bar(ys: Int*) = ()
4+
5+
val xs: Array[Int] = new Array[Int](3)
6+
foo(xs: _*)
7+
8+
val ys: Seq[Int] = new Array[Int](3)
9+
foo(ys: _*)
10+
}

0 commit comments

Comments
 (0)