Skip to content

Commit f483de7

Browse files
committed
fix #10724: adapt vararg parameters
follow up would be needed to adapt java varargs which are already broken
1 parent 46290f9 commit f483de7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,18 @@ class Namer { typer: Typer =>
988988
* provided `mbr` is accessible and of the right implicit/non-implicit kind.
989989
*/
990990
def addForwarder(alias: TermName, mbr: SingleDenotation, span: Span): Unit =
991+
def adaptForwarderParams(acc: List[List[tpd.Tree]], tp: Type, prefss: List[List[tpd.Tree]])
992+
: List[List[tpd.Tree]] = tp match
993+
case mt: MethodType =>
994+
if mt.paramInfos.nonEmpty && mt.paramInfos.last.isRepeatedParam then
995+
val prefsR = prefss.head.reverse
996+
val vararg = ctx.typeAssigner.seqToRepeated(prefsR.head)
997+
val prefsR1 = vararg :: prefsR.tail
998+
adaptForwarderParams(prefsR1.reverse :: acc, mt.resType, prefss.tail)
999+
else
1000+
adaptForwarderParams(prefss.head :: acc, mt.resType, prefss.tail)
1001+
case _ =>
1002+
acc.reverse ::: prefss
9911003
if (whyNoForwarder(mbr) == "") {
9921004
val sym = mbr.symbol
9931005
val forwarder =
@@ -1024,7 +1036,8 @@ class Namer { typer: Typer =>
10241036
import tpd._
10251037
val ref = path.select(sym.asTerm)
10261038
val ddef = tpd.polyDefDef(forwarder.asTerm, targs => prefss =>
1027-
ref.appliedToTypes(targs).appliedToArgss(prefss)
1039+
ref.appliedToTypes(targs)
1040+
.appliedToArgss(adaptForwarderParams(Nil, sym.info.stripPoly, prefss))
10281041
)
10291042
if forwarder.isInlineMethod then
10301043
PrepareInlineable.registerInlineInfo(forwarder, ddef.rhs)

tests/run/i10724.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object Exporter {
2+
object Exportee {
3+
inline def foo(args: String*): String = args.mkString(" ")
4+
5+
inline def bar(l: Option[Int])()(i: Int)(b: Boolean, args: String*): String =
6+
s"$l-$i-$b-${args.mkString("-")}"
7+
}
8+
export Exportee._
9+
}
10+
11+
import Exporter._
12+
13+
@main def Test =
14+
println(foo("a", "b", "c"))
15+
println(bar(Some(1))()(2)(true, "a", "b", "c"))

0 commit comments

Comments
 (0)