Skip to content

Commit 8b53d5b

Browse files
committed
Tightend "mightBeDropped" criterion
The problem is that outer accessors can also be called from outside a class definition, e.g. as part of pattern matching or type testing. So we have to be more conservative where to remove them. A drastic measure is to restrict to anonaymous classes only, which is what this commit does.
1 parent a475e47 commit 8b53d5b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ class DropOuterAccessors extends MiniPhase with IdentityDenotTransformer:
3131
def (sym: Symbol).isOuterParamAccessor(using Context) =
3232
sym.is(ParamAccessor) && sym.name == nme.OUTER
3333

34+
/** Characterizes outer accessors and outer fields that can be dropped
35+
* if there are no references to them from within the class in which they
36+
* are defined.
37+
*/
3438
private def mightBeDropped(sym: Symbol)(using Context) =
3539
(sym.is(OuterAccessor) || sym.isOuterParamAccessor)
36-
&& !sym.owner.isExtensibleClass
40+
&& sym.owner.isAnonymousClass
3741

3842
/** The number of times an outer accessor that might be dropped is accessed */
3943
private val accessCount = new mutable.HashMap[Symbol, Int]:

0 commit comments

Comments
 (0)