@@ -17,6 +17,7 @@ import NameKinds.{InlineAccessorName, UniqueInlineName}
17
17
import NameOps ._
18
18
import Annotations ._
19
19
import transform .{AccessProxies , PCPCheckAndHeal , Splicer }
20
+ import transform .SymUtils .*
20
21
import config .Printers .inlining
21
22
import util .Property
22
23
import dotty .tools .dotc .transform .TreeMapWithStages ._
@@ -61,13 +62,17 @@ object PrepareInlineable {
61
62
*
62
63
* Constant vals don't need accessors since they are inlined in FirstTransform.
63
64
* Inline methods don't need accessors since they are inlined in Typer.
65
+ *
66
+ * When creating accessors for staged/quoted code we only need to create accessors
67
+ * for the code that is staged. This excludes code at level 0 (except if it is inlined).
64
68
*/
65
69
def needsAccessor (sym : Symbol )(using Context ): Boolean =
66
70
sym.isTerm &&
67
71
(sym.isOneOf(AccessFlags ) || sym.privateWithin.exists) &&
68
72
! sym.isContainedIn(inlineSym) &&
69
73
! (sym.isStableMember && sym.info.widenTermRefExpr.isInstanceOf [ConstantType ]) &&
70
- ! sym.isInlineMethod
74
+ ! sym.isInlineMethod &&
75
+ (Inliner .inInlineMethod || StagingContext .level > 0 )
71
76
72
77
def preTransform (tree : Tree )(using Context ): Tree
73
78
@@ -79,7 +84,14 @@ object PrepareInlineable {
79
84
}
80
85
81
86
override def transform (tree : Tree )(using Context ): Tree =
82
- postTransform(super .transform(preTransform(tree)))
87
+ inContext(stagingContext(tree)) {
88
+ postTransform(super .transform(preTransform(tree)))
89
+ }
90
+
91
+ private def stagingContext (tree : Tree )(using Context ): Context = tree match
92
+ case tree : Apply if tree.symbol.isQuote => StagingContext .quoteContext
93
+ case tree : Apply if tree.symbol.isExprSplice => StagingContext .spliceContext
94
+ case _ => ctx
83
95
}
84
96
85
97
/** Direct approach: place the accessor with the accessed symbol. This has the
0 commit comments