File tree Expand file tree Collapse file tree 6 files changed +37
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 6 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ object Splicer {
161161 case SeqLiteral (elems, _) =>
162162 elems.foreach(checkIfValidArgument)
163163
164- case tree : Ident if summon[Env ].contains(tree.symbol) =>
164+ case tree : Ident if summon[Env ].contains(tree.symbol) || tree.symbol.is( Inline , butNot = Method ) =>
165165 // OK
166166
167167 case _ =>
@@ -172,6 +172,7 @@ object Splicer {
172172 |Parameters may only be:
173173 | * Quoted parameters or fields
174174 | * Literal values of primitive types
175+ | * References to `inline val`s
175176 | """ .stripMargin, tree.srcPos)
176177 }
177178
@@ -242,6 +243,11 @@ object Splicer {
242243 case Literal (Constant (value)) =>
243244 interpretLiteral(value)
244245
246+ case tree : Ident if tree.symbol.is(Inline , butNot = Method ) =>
247+ tree.tpe.widenTermRefExpr match
248+ case ConstantType (c) => c.value.asInstanceOf [Object ]
249+ case _ => throw new StopInterpretation (em " ${tree.symbol} could not be inlined " , tree.srcPos)
250+
245251 // TODO disallow interpreted method calls as arguments
246252 case Call (fn, args) =>
247253 if (fn.symbol.isConstructor && fn.symbol.owner.owner.is(Package ))
Original file line number Diff line number Diff line change 66 | Parameters may only be:
77 | * Quoted parameters or fields
88 | * Literal values of primitive types
9+ | * References to `inline val`s
Original file line number Diff line number Diff line change 1+ import scala .quoted .*
2+
3+ def qqq (s : String )(using Quotes ): Expr [Unit ] = ' {()}
4+
5+ inline val InlineVal = " i"
6+ inline def InlineDef = " i"
7+
8+ inline def withInlineVal = $ { qqq(InlineVal ) }
9+ inline def withInlineDef = $ { qqq(InlineDef ) } // error
10+ inline def withString = $ { qqq(" i" ) }
Original file line number Diff line number Diff line change 1+ import scala .quoted .*
2+
3+ def qqq (s : String )(using Quotes ): Expr [Unit ] = ' {()}
4+
5+ abstract class Foo :
6+ inline val InlineVal : String
7+
8+ val foo : Foo = ???
9+
10+ inline def withInlineVal = $ { qqq(foo.InlineVal ) } // error
Original file line number Diff line number Diff line change 1+
2+ import scala .quoted .*
3+
4+ inline val InlineStringVal = " abc"
5+
6+ inline def withInlineVal = $ { qqq(InlineStringVal ) }
7+
8+ def qqq (s : String )(using Quotes ): Expr [String ] = Expr (s)
Original file line number Diff line number Diff line change 1+ def test = withInlineVal
You can’t perform that action at this time.
0 commit comments