Skip to content

Commit 4b9bf18

Browse files
authored
Merge pull request #10890 from dotty-staging/fix-10724
fix #10724: adapt vararg parameters
2 parents 12ff02f + 3994e67 commit 4b9bf18

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,20 @@ 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+
// Note: in this branch we use the assumptions
995+
// that `prefss.head` corresponds to `mt.paramInfos` and
996+
// that `prefss.tail` corresponds to `mt.resType`
997+
if mt.paramInfos.nonEmpty && mt.paramInfos.last.isRepeatedParam then
998+
val init :+ vararg = prefss.head
999+
val prefs = init :+ ctx.typeAssigner.seqToRepeated(vararg)
1000+
adaptForwarderParams(prefs :: acc, mt.resType, prefss.tail)
1001+
else
1002+
adaptForwarderParams(prefss.head :: acc, mt.resType, prefss.tail)
1003+
case _ =>
1004+
acc.reverse ::: prefss
9911005
if (whyNoForwarder(mbr) == "") {
9921006
val sym = mbr.symbol
9931007
val forwarder =
@@ -1024,7 +1038,8 @@ class Namer { typer: Typer =>
10241038
import tpd._
10251039
val ref = path.select(sym.asTerm)
10261040
val ddef = tpd.polyDefDef(forwarder.asTerm, targs => prefss =>
1027-
ref.appliedToTypes(targs).appliedToArgss(prefss)
1041+
ref.appliedToTypes(targs)
1042+
.appliedToArgss(adaptForwarderParams(Nil, sym.info.stripPoly, prefss))
10281043
)
10291044
if forwarder.isInlineMethod then
10301045
PrepareInlineable.registerInlineInfo(forwarder, ddef.rhs)

tests/run/i10724.scala

+15
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)