File tree 6 files changed +37
-1
lines changed
compiler/src/dotty/tools/dotc/transform 6 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ object Splicer {
161
161
case SeqLiteral (elems, _) =>
162
162
elems.foreach(checkIfValidArgument)
163
163
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 ) =>
165
165
// OK
166
166
167
167
case _ =>
@@ -172,6 +172,7 @@ object Splicer {
172
172
|Parameters may only be:
173
173
| * Quoted parameters or fields
174
174
| * Literal values of primitive types
175
+ | * References to `inline val`s
175
176
| """ .stripMargin, tree.srcPos)
176
177
}
177
178
@@ -242,6 +243,11 @@ object Splicer {
242
243
case Literal (Constant (value)) =>
243
244
interpretLiteral(value)
244
245
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
+
245
251
// TODO disallow interpreted method calls as arguments
246
252
case Call (fn, args) =>
247
253
if (fn.symbol.isConstructor && fn.symbol.owner.owner.is(Package ))
Original file line number Diff line number Diff line change 6
6
| Parameters may only be:
7
7
| * Quoted parameters or fields
8
8
| * 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