@@ -333,31 +333,9 @@ object Inliner {
333
333
val errors = compileForErrors(tree, false )
334
334
packErrors(errors)
335
335
336
- def code (strCtx : Tree , argsTree : Tree , pos : SrcPos )(using Context ): Tree =
337
- object Consts :
338
- def unapply (trees : List [Tree ]): Option [List [String ]] =
339
- trees match
340
- case Nil => Some (Nil )
341
- case Literal (Constant (part : String )) :: Consts (rest) => Some (part :: rest)
342
- case _ => None
343
- strCtx match
344
- case Apply (stringContextApply, List (Typed (SeqLiteral (Consts (parts), _), _)))
345
- if stringContextApply.symbol == defn.StringContextModule_apply =>
346
- argsTree match
347
- case Typed (SeqLiteral (args, _), _) =>
348
- if parts.size == args.size + 1 then
349
- val argStrs = args.map(_.show)
350
- val showed = StringContext (parts : _* ).s(argStrs : _* )
351
- Literal (Constant (showed)).withSpan(pos.span)
352
- else
353
- report.error(" Wrong number of arguments for StringContext.s" , strCtx.srcPos)
354
- ref(defn.Predef_undefined )
355
- case _ =>
356
- report.error(" Exprected explicit arguments to code" , strCtx.srcPos)
357
- ref(defn.Predef_undefined )
358
- case _ =>
359
- report.error(" Exprected StringContext.apply with explicit `parts` arguments" , strCtx.srcPos)
360
- ref(defn.Predef_undefined )
336
+ /** Expand call to scala.compiletime.codeOf */
337
+ def codeOf (arg : Tree , pos : SrcPos )(using Context ): Tree =
338
+ Literal (Constant (arg.show)).withSpan(pos.span)
361
339
}
362
340
}
363
341
@@ -644,13 +622,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
644
622
645
623
// Special handling of `requireConst`
646
624
callValueArgss match
647
- case (arg :: Nil ) :: Nil if inlinedMethod == defn.Compiletime_requireConst =>
648
- arg match
649
- case ConstantValue (_) | Inlined (_, Nil , Typed (ConstantValue (_), _)) => // ok
650
- case _ => report.error(em " expected a constant value but found: $arg" , arg.srcPos)
651
- return Literal (Constant (())).withSpan(sourcePos.span)
652
- case (strCtx :: Nil ) :: (args :: Nil ) :: Nil if inlinedMethod == defn.Compiletime_code =>
653
- return Intrinsics .code(strCtx, args, call.srcPos)
625
+ case (arg :: Nil ) :: Nil =>
626
+ if inlinedMethod == defn.Compiletime_requireConst then
627
+ arg match
628
+ case ConstantValue (_) | Inlined (_, Nil , Typed (ConstantValue (_), _)) => // ok
629
+ case _ => report.error(em " expected a constant value but found: $arg" , arg.srcPos)
630
+ return Literal (Constant (())).withSpan(sourcePos.span)
631
+ else if inlinedMethod == defn.Compiletime_codeOf then
632
+ return Intrinsics .codeOf(arg, call.srcPos)
654
633
case _ =>
655
634
656
635
// Special handling of `constValue[T]` and `constValueOpt[T]`
0 commit comments