From e5618d29e37ad50bd1b8c591ed50db63a6d7bc79 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 2 Apr 2015 16:11:20 +0200 Subject: Simplify methods implemented in #436 --- src/dotty/tools/dotc/ast/Desugar.scala | 7 +++---- src/dotty/tools/dotc/core/SymDenotations.scala | 8 ++++++-- src/dotty/tools/dotc/core/Symbols.scala | 18 ++++++------------ 3 files changed, 15 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 961675fed..1dfa24291 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -361,11 +361,10 @@ object desugar { } companionDefs(parent, applyMeths ::: unapplyMeth :: defaultGetters) } - else { - if (defaultGetters.nonEmpty) + else if (defaultGetters.nonEmpty) companionDefs(anyRef, defaultGetters) - else Nil - } + else Nil + // For an implicit class C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, .., pMN: TMN), the method // synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] = diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 0ee633861..9889bc89c 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1286,7 +1286,11 @@ object SymDenotations { def enter(sym: Symbol, scope: Scope = EmptyScope)(implicit ctx: Context): Unit = { val mscope = scope match { case scope: MutableScope => - assert(this.nextInRun == this) // we are not going to bring this symbol into future + // if enter gets a scope as an argument, + // than this is a scope that will eventually become decls of this symbol. + // And this should only happen if this is first time the scope of symbol + // is computed, ie symbol yet has no future. + assert(this.nextInRun == this) scope case _ => unforcedDecls.openForMutations } @@ -1300,7 +1304,7 @@ object SymDenotations { } enterNoReplace(sym, mscope) val nxt = this.nextInRun - if((nxt ne this) && (nxt.validFor.code > this.validFor.code)) { + if (nxt.validFor.code > this.validFor.code) { this.nextInRun.asSymDenotation.asClass.enter(sym) } } diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index 97fe1f23e..0b50187a5 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -161,20 +161,14 @@ trait Symbols { this: Context => owner.thisType, modcls, parents, decls, TermRef.withSymAndName(owner.thisType, module, name)), privateWithin, coord, assocFile) - def synthesizeCompanionMethod(name: TermName, ret: SymDenotation, owner: SymDenotation)(implicit ctx: Context) = { - if(owner.exists && ret.exists && !owner.isAbsent && !ret.isAbsent) { + def synthesizeCompanionMethod(name: Name, target: SymDenotation, owner: SymDenotation)(implicit ctx: Context) = + if(owner.exists && target.exists && !owner.isAbsent && !target.isAbsent) { val existing = owner.unforcedDecls.lookup(name) - if (existing.exists) existing - else - ctx.newSymbol( - owner = owner.symbol, - name = name, - flags = Flags.Synthetic | Flags.Private, - info = ExprType(ret.typeRef)) - } - else NoSymbol - } + existing.orElse{ + ctx.newSymbol(owner.symbol, name, Flags.Synthetic | Flags.Private, ExprType(target.typeRef)) + } + } else NoSymbol /** Create a package symbol with associated package class * from its non-info fields and a lazy type for loading the package's members. -- cgit v1.2.3