diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-01-28 09:10:37 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-02-02 13:19:06 +0100 |
commit | fd6125428af90b02cb8969a53586f3551e275b0f (patch) | |
tree | 17acfa819519ec2d92eeac8b2e0dece89aad7b25 /src/compiler/scala/tools/nsc/typechecker/Namers.scala | |
parent | ee24807f8706bb91b9d854eaba39f0ddd9c2a054 (diff) | |
download | scala-fd6125428af90b02cb8969a53586f3551e275b0f.tar.gz scala-fd6125428af90b02cb8969a53586f3551e275b0f.tar.bz2 scala-fd6125428af90b02cb8969a53586f3551e275b0f.zip |
SI-6666 Account for nesting in setting INCONSTRUCTOR
This flag is calcualed in Namers, and assigned to class
and module class symbols that are defined in self/super-calls,
and in early definitions.
For example, class D is INCONSTRUCTOR in each case below:
class C extends Super({class D; ()})
class C(a: Any) {
def this(a: Any) = this({class D; ()})
}
new { val x = { class D; () } with Super(())
But, the calculation of this flag failed to account for
nesting, so it was not set in cases like:
class C(a: Any) {
def this(a: Any) = this({val x = {class D; ()}; x})
}
This patch searches the enclosing context chain, rather than
just the immediate context. The search is terminated at the
first non term-owned context. In the following example, this
avoids marking `E` as INCONSTRUCTOR; only `D` should be.
class C extends Super({class D { class E }; ()})
This closes SI-6259 and SI-6506, and fixes one problem
in the recently reopened SI-6957.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Namers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 98b6264051..967a3214f2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -123,9 +123,12 @@ trait Namers extends MethodSynthesis { def setPrivateWithin(tree: MemberDef, sym: Symbol): Symbol = setPrivateWithin(tree, sym, tree.mods) - def inConstructorFlag: Long = - if (owner.isConstructor && !context.inConstructorSuffix || owner.isEarlyInitialized) INCONSTRUCTOR - else 0l + def inConstructorFlag: Long = { + val termOwnedContexts: List[Context] = context.enclosingContextChain.takeWhile(_.owner.isTerm) + val constructorNonSuffix = termOwnedContexts exists (c => c.owner.isConstructor && !c.inConstructorSuffix) + val earlyInit = termOwnedContexts exists (_.owner.isEarlyInitialized) + if (constructorNonSuffix || earlyInit) INCONSTRUCTOR else 0L + } def moduleClassFlags(moduleFlags: Long) = (moduleFlags & ModuleToClassFlags) | inConstructorFlag |