@@ -1079,15 +1079,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
1079
1079
}
1080
1080
}
1081
1081
1082
+ // inlineContext, enclosingInlineds, sourceFile and Decorators.sourcePos work closely together.
1083
+
1082
1084
/** A key to be used in a context property that tracks enclosing inlined calls */
1083
1085
private val InlinedCalls = new Property .Key [List [Tree ]]
1084
1086
1085
- /** Record an enclosing inlined call.
1086
- * EmptyTree calls (for parameters) cancel the next-enclosing call in the list instead of being added to it.
1087
- * We assume parameters are never nested inside parameters.
1087
+ /** Record an enclosing inlined call in enclosingInlineds, and produces the context for visiting
1088
+ * Inlined(call, ...).
1089
+ *
1090
+ * Invariants:
1091
+ * - enclosingInlineds never contains EmptyTree nodes.
1092
+ * - if enclosingInlineds.nonEmpty, the current tree comes from the file *defining* enclosingInlineds.head.symbol;
1093
+ * this is exploited in e.g. Decorators.sourcePos.
1094
+ *
1095
+ * Arguments of inlined calls (enclosed in Inlined(EmptyTree, ...)) come instead from the call-site, so
1096
+ * inlineContext(EmptyTree) pops the enclosing call.
1088
1097
*/
1089
1098
override def inlineContext (call : Tree )(implicit ctx : Context ): Context = {
1090
- // We assume enclosingInlineds is already normalized, and only process the new call with the head.
1099
+ // enclosingInlineds is already normalized, so we only process the new call with the head.
1091
1100
val oldIC = enclosingInlineds
1092
1101
val newIC = (call, oldIC) match {
1093
1102
case (t, t1 :: ts2) if t.isEmpty =>
@@ -1106,7 +1115,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
1106
1115
/** The source file where the symbol of the `inline` method referred to by `call`
1107
1116
* is defined
1108
1117
*/
1109
- def sourceFile (call : Tree )(implicit ctx : Context ) = {
1118
+ def sourceFile (call : Tree )(implicit ctx : Context ): SourceFile = {
1110
1119
val file = call.symbol.sourceFile
1111
1120
val encoding = ctx.settings.encoding.value
1112
1121
if (file != null && file.exists) new SourceFile (file, Codec (encoding)) else NoSource
0 commit comments