diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index 872dc7793ff4..8b775a25fe0c 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -207,11 +207,18 @@ class Inliner(val call: tpd.Tree)(using Context): private[inlines] def paramBindingDef(name: Name, formal: Type, arg0: Tree, buf: DefBuffer)(using Context): ValOrDefDef = { val isByName = formal.dealias.isInstanceOf[ExprType] - val arg = arg0 match { - case Typed(arg1, tpt) if tpt.tpe.isRepeatedParam && arg1.tpe.derivesFrom(defn.ArrayClass) => - wrapArray(arg1, arg0.tpe.elemType) - case _ => arg0 - } + val arg = + def dropNameArg(arg: Tree): Tree = arg match + case NamedArg(_, arg1) => arg1 + case SeqLiteral(elems, tpt) => + cpy.SeqLiteral(arg)(elems.mapConserve(dropNameArg), tpt) + case _ => arg + arg0 match + case Typed(seq, tpt) if tpt.tpe.isRepeatedParam => + if seq.tpe.derivesFrom(defn.ArrayClass) then wrapArray(dropNameArg(seq), arg0.tpe.elemType) + else cpy.Typed(arg0)(dropNameArg(seq), tpt) + case arg0 => + dropNameArg(arg0) val argtpe = arg.tpe.dealiasKeepAnnots.translateFromRepeated(toArray = false) val argIsBottom = argtpe.isBottomTypeAfterErasure val bindingType = diff --git a/tests/pos-macros/i17227/Macro_1.scala b/tests/pos-macros/i17227/Macro_1.scala new file mode 100644 index 000000000000..b483336119cb --- /dev/null +++ b/tests/pos-macros/i17227/Macro_1.scala @@ -0,0 +1,22 @@ +import scala.quoted.* + +inline def foo(f: Int => Int): Int => Int = ${impl('f)} +inline def bar(inline f: Int => Int): Int => Int = ${impl('f)} +inline def baz(inline f: (Int => Int)*): Int => Int = ${impl2('f)} + +def impl(f: Expr[Int => Int])(using Quotes): Expr[Int => Int] = + assertNoNamedArgs(f) + '{identity} + +def impl2(f: Expr[Seq[Int => Int]])(using Quotes): Expr[Int => Int] = + assertNoNamedArgs(f) + '{identity} + +def assertNoNamedArgs(expr: Expr[Any])(using Quotes): Unit = + import quotes.reflect.* + new TreeTraverser { + override def traverseTree(tree: Tree)(owner: Symbol): Unit = tree match + case _: NamedArg => + report.throwError(s"Unexpected NamedArg after inlining: ${tree}", tree.pos) + case _ => traverseTreeChildren(tree)(owner) + }.traverseTree(expr.asTerm)(Symbol.spliceOwner) diff --git a/tests/pos-macros/i17227/Test_2.scala b/tests/pos-macros/i17227/Test_2.scala new file mode 100644 index 000000000000..4106113d94c0 --- /dev/null +++ b/tests/pos-macros/i17227/Test_2.scala @@ -0,0 +1,6 @@ +def g(i: Int): Int = i + +def test = + foo(f = g) + bar(f = g) + baz(f = g) diff --git a/tests/pos/i17227.scala b/tests/pos/i17227.scala new file mode 100644 index 000000000000..d537f99f6515 --- /dev/null +++ b/tests/pos/i17227.scala @@ -0,0 +1,10 @@ +inline def foo(f: Int => Int): Int => Int = f +inline def bar(inline f: Int => Int): Int => Int = f +inline def baz(f: (Int => Int)*): Int => Int = f.head + +def g(i: Int): Int = i + +def test = + foo(f = g) + bar(f = g) + baz(f = g)