diff options
author | Som Snytt <som.snytt@gmail.com> | 2016-10-27 13:38:10 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2016-10-27 14:41:28 -0700 |
commit | 9e1de6ee81e9eaf9d8ac59446bc97c79b5ff0cb6 (patch) | |
tree | aace099ca62b6375484289e27c080e006c2bf40b /src/compiler/scala/tools/nsc/typechecker/Typers.scala | |
parent | eff0aabb7824513498a4081072845001dbe4897f (diff) | |
download | scala-9e1de6ee81e9eaf9d8ac59446bc97c79b5ff0cb6.tar.gz scala-9e1de6ee81e9eaf9d8ac59446bc97c79b5ff0cb6.tar.bz2 scala-9e1de6ee81e9eaf9d8ac59446bc97c79b5ff0cb6.zip |
SI-6734 Synthesize companion near case class
Tweak the "should I synthesize now" test for
case modules, so that the tree is inserted in
the same tree as the case class.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 7d48c548a1..a92c190805 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3139,10 +3139,24 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val initElems = scope.elems // SI-5877 The decls of a package include decls of the package object. But we don't want to add // the corresponding synthetics to the package class, only to the package object class. - def shouldAdd(sym: Symbol) = - inBlock || !context.isInPackageObject(sym, context.owner) + // SI-6734 Locality test below is meaningless if we're not even in the correct tree. + def shouldAdd(sym: Symbol): Boolean = { + def shouldAddAsModule: Boolean = + sym.moduleClass.attachments.get[ClassForCaseCompanionAttachment] match { + case Some(att) => + val cdef = att.caseClass + stats.exists { + case t @ ClassDef(_, _, _, _) => t.symbol == cdef.symbol + case _ => false + } + case _ => true + } + + (!sym.isModule || shouldAddAsModule) && (inBlock || !context.isInPackageObject(sym, context.owner)) + } for (sym <- scope) - for (tree <- context.unit.synthetics get sym if shouldAdd(sym)) { // OPT: shouldAdd is usually true. Call it here, rather than in the outer loop + // OPT: shouldAdd is usually true. Call it here, rather than in the outer loop + for (tree <- context.unit.synthetics.get(sym) if shouldAdd(sym)) { newStats += typedStat(tree) // might add even more synthetics to the scope context.unit.synthetics -= sym } |