Skip to content

Commit add425d

Browse files
Move code to constructors while preserving its source information
1 parent adb2df0 commit add425d

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,10 @@ class Inliner(val call: tpd.Tree)(using Context):
583583
val inlinedCtx = ctx.withSource(inlinedMethod.topLevelClass.source)
584584
paramProxy.get(tree.tpe) match {
585585
case Some(t) if tree.isTerm && t.isSingleton =>
586-
val inlinedSingleton = singleton(t).withSpan(tree.span)
586+
val inlinedSingleton = singleton(t).withSpan(argSpan)
587587
inlinedFromOutside(inlinedSingleton)(tree.span)
588588
case Some(t) if tree.isType =>
589-
inlinedFromOutside(TypeTree(t).withSpan(tree.span))(tree.span)
589+
inlinedFromOutside(TypeTree(t).withSpan(argSpan))(tree.span)
590590
case _ => tree
591591
}
592592
case tree @ Select(qual: This, name) if tree.symbol.is(Private) && tree.symbol.isInlineMethod =>

compiler/src/dotty/tools/dotc/transform/Constructors.scala

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,26 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
150150
// drop the () when replacing by the parameter.
151151
object intoConstr extends TreeMap {
152152
private var isSuperCall = false
153-
override def transform(tree: Tree)(using Context): Tree = tree match {
154-
case Ident(_) | Select(This(_), _) =>
155-
var sym = tree.symbol
156-
if sym.is(ParamAccessor) && (!sym.is(Mutable) || isSuperCall)
157-
// Variables need to go through the getter since they might have been updated,
158-
// except if we are in a super call, since then the virtual getter call would
159-
// be illegal.
160-
then
161-
sym = sym.subst(accessors, paramSyms)
162-
if (sym.maybeOwner.isConstructor) ref(sym).withSpan(tree.span) else tree
163-
case Apply(fn, Nil) =>
164-
val fn1 = transform(fn)
165-
if ((fn1 ne fn) && fn1.symbol.is(Param) && fn1.symbol.owner.isPrimaryConstructor)
166-
fn1 // in this case, fn1.symbol was an alias for a parameter in a superclass
167-
else cpy.Apply(tree)(fn1, Nil)
168-
case _ =>
169-
if (noDirectRefsFrom(tree)) tree else super.transform(tree)
153+
override def transform(tree: Tree)(using Context): Tree =
154+
inContext(transformCtx(tree)) {
155+
tree match {
156+
case Ident(_) | Select(This(_), _) =>
157+
var sym = tree.symbol
158+
if sym.is(ParamAccessor) && (!sym.is(Mutable) || isSuperCall)
159+
// Variables need to go through the getter since they might have been updated,
160+
// except if we are in a super call, since then the virtual getter call would
161+
// be illegal.
162+
then
163+
sym = sym.subst(accessors, paramSyms)
164+
if (sym.maybeOwner.isConstructor) ref(sym).withSpan(tree.span) else tree
165+
case Apply(fn, Nil) =>
166+
val fn1 = transform(fn)
167+
if ((fn1 ne fn) && fn1.symbol.is(Param) && fn1.symbol.owner.isPrimaryConstructor)
168+
fn1 // in this case, fn1.symbol was an alias for a parameter in a superclass
169+
else cpy.Apply(tree)(fn1, Nil)
170+
case _ =>
171+
if (noDirectRefsFrom(tree)) tree else super.transform(tree)
172+
}
170173
}
171174

172175
def apply(tree: Tree, prevOwner: Symbol)(using Context): Tree =

0 commit comments

Comments
 (0)