diff --git a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala index ccf6cd6f995b..dbf4fe91a970 100644 --- a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala +++ b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala @@ -126,11 +126,13 @@ class Interpreter(pos: SrcPos, classLoader0: ClassLoader)(using Context): view.toList fnType.dealias match - case fnType: MethodType if fnType.hasErasedParams => interpretArgs(argss, fnType.resType) case fnType: MethodType => val argTypes = fnType.paramInfos assert(argss.head.size == argTypes.size) - interpretArgsGroup(argss.head, argTypes) ::: interpretArgs(argss.tail, fnType.resType) + val nonErasedArgs = argss.head.lazyZip(fnType.erasedParams).collect { case (arg, false) => arg }.toList + val nonErasedArgTypes = fnType.paramInfos.lazyZip(fnType.erasedParams).collect { case (arg, false) => arg }.toList + assert(nonErasedArgs.size == nonErasedArgTypes.size) + interpretArgsGroup(nonErasedArgs, nonErasedArgTypes) ::: interpretArgs(argss.tail, fnType.resType) case fnType: AppliedType if defn.isContextFunctionType(fnType) => val argTypes :+ resType = fnType.args: @unchecked interpretArgsGroup(argss.head, argTypes) ::: interpretArgs(argss.tail, resType) @@ -328,8 +330,8 @@ object Interpreter: object Call: import tpd._ /** Matches an expression that is either a field access or an application - * It retruns a TermRef containing field accessed or a method reference and the arguments passed to it. - */ + * It returns a TermRef containing field accessed or a method reference and the arguments passed to it. + */ def unapply(arg: Tree)(using Context): Option[(RefTree, List[List[Tree]])] = Call0.unapply(arg).map((fn, args) => (fn, args.reverse)) @@ -339,10 +341,8 @@ object Interpreter: Some((fn, args)) case fn: Ident => Some((tpd.desugarIdent(fn).withSpan(fn.span), Nil)) case fn: Select => Some((fn, Nil)) - case Apply(f @ Call0(fn, args1), args2) => - if (f.tpe.widenDealias.hasErasedParams) Some((fn, args1)) - else Some((fn, args2 :: args1)) - case TypeApply(Call0(fn, args), _) => Some((fn, args)) + case Apply(f @ Call0(fn, argss), args) => Some((fn, args :: argss)) + case TypeApply(Call0(fn, argss), _) => Some((fn, argss)) case _ => None } } diff --git a/tests/pos-macros/erasedArgs/Macro_1.scala b/tests/pos-macros/erasedArgs/Macro_1.scala new file mode 100644 index 000000000000..08706d6110b9 --- /dev/null +++ b/tests/pos-macros/erasedArgs/Macro_1.scala @@ -0,0 +1,7 @@ +import scala.quoted._ +import scala.language.experimental.erasedDefinitions + +transparent inline def mcr: Any = ${ mcrImpl(1, 2d, "abc") } + +def mcrImpl(x: Int, erased y: Double, z: String)(using Quotes): Expr[String] = + Expr(x.toString() + z) diff --git a/tests/pos-macros/erasedArgs/Test_2.scala b/tests/pos-macros/erasedArgs/Test_2.scala new file mode 100644 index 000000000000..19f0364d3f71 --- /dev/null +++ b/tests/pos-macros/erasedArgs/Test_2.scala @@ -0,0 +1 @@ +def test: "1abc" = mcr