Skip to content

Avoid using anonymous classes in some situations #4503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ object Symbols {
denot = underlying.denot
}

@sharable val NoSymbol: Symbol = new Symbol(NoCoord, 0) {
@sharable object NoSymbol extends Symbol(NoCoord, 0) {
override def associatedFile(implicit ctx: Context): AbstractFile = NoSource.file
override def recomputeDenot(lastd: SymDenotation)(implicit ctx: Context): SymDenotation = NoDenotation
}
Expand Down
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,7 @@ object Types {
private[this] var myRecThis: RecThis = null

def recThis: RecThis = {
if (myRecThis == null) myRecThis = new RecThis(this) {}
if (myRecThis == null) myRecThis = new RecThisImpl(this)
myRecThis
}

Expand Down Expand Up @@ -2849,7 +2849,7 @@ object Types {
*/
def isParamDependent(implicit ctx: Context): Boolean = paramDependencyStatus == TrueDeps

def newParamRef(n: Int) = new TermParamRef(this, n) {}
def newParamRef(n: Int): TermParamRef = new TermParamRefImpl(this, n)

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

def newParamRef(n: Int) = new TypeParamRef(this, n) {}
def newParamRef(n: Int): TypeParamRef = new TypeParamRefImpl(this, n)

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

private final class TermParamRefImpl(binder: TermLambda, paramNum: Int) extends TermParamRef(binder, paramNum)

/** Only created in `binder.paramRefs`. Use `binder.paramRefs(paramNum)` to
* refer to `TypeParamRef(binder, paramNum)`.
*/
Expand All @@ -3305,6 +3307,8 @@ object Types {
}
}

private final class TypeParamRefImpl(binder: TypeLambda, paramNum: Int) extends TypeParamRef(binder, paramNum)

/** a self-reference to an enclosing recursive type. The only creation method is
* `binder.recThis`, returning `RecThis(binder)`.
*/
Expand All @@ -3331,6 +3335,8 @@ object Types {
}
}

private final class RecThisImpl(binder: RecType) extends RecThis(binder)

// ----- Skolem types -----------------------------------------------

/** A skolem type reference with underlying type `binder`. */
Expand Down