Skip to content

Commit e5618d2

Browse files
committed
Simplify methods implemented in #436
1 parent c560648 commit e5618d2

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,10 @@ object desugar {
361361
}
362362
companionDefs(parent, applyMeths ::: unapplyMeth :: defaultGetters)
363363
}
364-
else {
365-
if (defaultGetters.nonEmpty)
364+
else if (defaultGetters.nonEmpty)
366365
companionDefs(anyRef, defaultGetters)
367-
else Nil
368-
}
366+
else Nil
367+
369368

370369
// For an implicit class C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, .., pMN: TMN), the method
371370
// synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] =

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,11 @@ object SymDenotations {
12861286
def enter(sym: Symbol, scope: Scope = EmptyScope)(implicit ctx: Context): Unit = {
12871287
val mscope = scope match {
12881288
case scope: MutableScope =>
1289-
assert(this.nextInRun == this) // we are not going to bring this symbol into future
1289+
// if enter gets a scope as an argument,
1290+
// than this is a scope that will eventually become decls of this symbol.
1291+
// And this should only happen if this is first time the scope of symbol
1292+
// is computed, ie symbol yet has no future.
1293+
assert(this.nextInRun == this)
12901294
scope
12911295
case _ => unforcedDecls.openForMutations
12921296
}
@@ -1300,7 +1304,7 @@ object SymDenotations {
13001304
}
13011305
enterNoReplace(sym, mscope)
13021306
val nxt = this.nextInRun
1303-
if((nxt ne this) && (nxt.validFor.code > this.validFor.code)) {
1307+
if (nxt.validFor.code > this.validFor.code) {
13041308
this.nextInRun.asSymDenotation.asClass.enter(sym)
13051309
}
13061310
}

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,14 @@ trait Symbols { this: Context =>
161161
owner.thisType, modcls, parents, decls, TermRef.withSymAndName(owner.thisType, module, name)),
162162
privateWithin, coord, assocFile)
163163

164-
def synthesizeCompanionMethod(name: TermName, ret: SymDenotation, owner: SymDenotation)(implicit ctx: Context) = {
165-
if(owner.exists && ret.exists && !owner.isAbsent && !ret.isAbsent) {
164+
def synthesizeCompanionMethod(name: Name, target: SymDenotation, owner: SymDenotation)(implicit ctx: Context) =
165+
if(owner.exists && target.exists && !owner.isAbsent && !target.isAbsent) {
166166
val existing = owner.unforcedDecls.lookup(name)
167-
if (existing.exists) existing
168-
else
169-
ctx.newSymbol(
170-
owner = owner.symbol,
171-
name = name,
172-
flags = Flags.Synthetic | Flags.Private,
173-
info = ExprType(ret.typeRef))
174167

175-
}
176-
else NoSymbol
177-
}
168+
existing.orElse{
169+
ctx.newSymbol(owner.symbol, name, Flags.Synthetic | Flags.Private, ExprType(target.typeRef))
170+
}
171+
} else NoSymbol
178172

179173
/** Create a package symbol with associated package class
180174
* from its non-info fields and a lazy type for loading the package's members.

0 commit comments

Comments
 (0)