Skip to content

Commit ecf95c1

Browse files
authored
Merge pull request #4503 from dotty-staging/opt/anon-class
Avoid using anonymous classes in some situations
2 parents 736c3ad + d0d7ee6 commit ecf95c1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ object Symbols {
707707
denot = underlying.denot
708708
}
709709

710-
@sharable val NoSymbol: Symbol = new Symbol(NoCoord, 0) {
710+
@sharable object NoSymbol extends Symbol(NoCoord, 0) {
711711
override def associatedFile(implicit ctx: Context): AbstractFile = NoSource.file
712712
override def recomputeDenot(lastd: SymDenotation)(implicit ctx: Context): SymDenotation = NoDenotation
713713
}

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,7 @@ object Types {
23552355
private[this] var myRecThis: RecThis = null
23562356

23572357
def recThis: RecThis = {
2358-
if (myRecThis == null) myRecThis = new RecThis(this) {}
2358+
if (myRecThis == null) myRecThis = new RecThisImpl(this)
23592359
myRecThis
23602360
}
23612361

@@ -2849,7 +2849,7 @@ object Types {
28492849
*/
28502850
def isParamDependent(implicit ctx: Context): Boolean = paramDependencyStatus == TrueDeps
28512851

2852-
def newParamRef(n: Int) = new TermParamRef(this, n) {}
2852+
def newParamRef(n: Int): TermParamRef = new TermParamRefImpl(this, n)
28532853

28542854
/** The least supertype of `resultType` that does not contain parameter dependencies */
28552855
def nonDependentResultApprox(implicit ctx: Context): Type =
@@ -3008,7 +3008,7 @@ object Types {
30083008
def isResultDependent(implicit ctx: Context): Boolean = true
30093009
def isParamDependent(implicit ctx: Context): Boolean = true
30103010

3011-
def newParamRef(n: Int) = new TypeParamRef(this, n) {}
3011+
def newParamRef(n: Int): TypeParamRef = new TypeParamRefImpl(this, n)
30123012

30133013
lazy val typeParams: List[LambdaParam] =
30143014
paramNames.indices.toList.map(new LambdaParam(this, _))
@@ -3285,6 +3285,8 @@ object Types {
32853285
def copyBoundType(bt: BT) = bt.paramRefs(paramNum)
32863286
}
32873287

3288+
private final class TermParamRefImpl(binder: TermLambda, paramNum: Int) extends TermParamRef(binder, paramNum)
3289+
32883290
/** Only created in `binder.paramRefs`. Use `binder.paramRefs(paramNum)` to
32893291
* refer to `TypeParamRef(binder, paramNum)`.
32903292
*/
@@ -3305,6 +3307,8 @@ object Types {
33053307
}
33063308
}
33073309

3310+
private final class TypeParamRefImpl(binder: TypeLambda, paramNum: Int) extends TypeParamRef(binder, paramNum)
3311+
33083312
/** a self-reference to an enclosing recursive type. The only creation method is
33093313
* `binder.recThis`, returning `RecThis(binder)`.
33103314
*/
@@ -3331,6 +3335,8 @@ object Types {
33313335
}
33323336
}
33333337

3338+
private final class RecThisImpl(binder: RecType) extends RecThis(binder)
3339+
33343340
// ----- Skolem types -----------------------------------------------
33353341

33363342
/** A skolem type reference with underlying type `binder`. */

0 commit comments

Comments
 (0)