Skip to content

Commit 16d0421

Browse files
committed
Add assert to find out whether code is redundant
1 parent 078f6c0 commit 16d0421

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th
4646
private def markUsedPrivateSymbols(tree: RefTree)(implicit ctx: Context): Unit = {
4747

4848
val sym = tree.symbol
49-
def retain() =
49+
def retain() = {
50+
//println(i"retained: $sym")
51+
//assert(i"$sym" != "value sf", ctx.owner.ownersIterator.toList)
5052
retainedPrivateVals.add(sym)
53+
}
5154

5255
if (sym.exists && sym.owner.isClass && mightBeDropped(sym)) {
5356
val owner = sym.owner.asClass
@@ -56,7 +59,8 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th
5659
case Ident(_) | Select(This(_), _) =>
5760
def inConstructor = {
5861
val method = ctx.owner.enclosingMethod
59-
method.isPrimaryConstructor && ctx.owner.enclosingClass == owner
62+
method.isPrimaryConstructor && ctx.owner.enclosingClass == owner// ||
63+
// method.isGetter && !method.is(Lazy)
6064
}
6165
if (inConstructor && (sym.is(ParamAccessor) || seenPrivateVals.contains(sym))) {
6266
// used inside constructor, accessed on this,
@@ -79,8 +83,10 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th
7983
}
8084

8185
override def transformValDef(tree: tpd.ValDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
82-
if (mightBeDropped(tree.symbol))
86+
if (mightBeDropped(tree.symbol)) {
8387
(if (isWildcardStarArg(tree.rhs)) retainedPrivateVals else seenPrivateVals) += tree.symbol
88+
assert(!isWildcardStarArg(tree.rhs))
89+
}
8490
tree
8591
}
8692

@@ -183,11 +189,13 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th
183189
case stat @ ValDef(name, tpt, _) if !stat.symbol.is(Lazy) && !stat.symbol.hasAnnotation(defn.ScalaStaticAnnot) =>
184190
val sym = stat.symbol
185191
if (isRetained(sym)) {
192+
// println(i"$sym is retained")
186193
if (!stat.rhs.isEmpty && !isWildcardArg(stat.rhs))
187194
constrStats += Assign(ref(sym), intoConstr(stat.rhs, sym)).withPos(stat.pos)
188195
clsStats += cpy.ValDef(stat)(rhs = EmptyTree)
189196
}
190197
else if (!stat.rhs.isEmpty) {
198+
// println(i"$sym ${sym.flags} is not retained")
191199
dropped += sym
192200
sym.copySymDenotation(
193201
initFlags = sym.flags &~ Private,

0 commit comments

Comments
 (0)