diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-08 19:16:13 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-08 19:16:13 +0000 |
commit | 1e8d2048517dcd57b33bbd27e850f6362e5e7074 (patch) | |
tree | f0ec374df190f826e8b9af009a3cc1b9a3b89bb9 /src | |
parent | f3c0640e3d7270795cc15dc923d811074c0836d7 (diff) | |
download | scala-1e8d2048517dcd57b33bbd27e850f6362e5e7074.tar.gz scala-1e8d2048517dcd57b33bbd27e850f6362e5e7074.tar.bz2 scala-1e8d2048517dcd57b33bbd27e850f6362e5e7074.zip |
Fix and test case for #1960.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Constructors.scala | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index c9a43270a1..17dbe36a8d 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -257,9 +257,22 @@ abstract class Constructors extends Transform { for ((accSym, accBody) <- outerAccessors) if (mustbeKept(accSym)) accessTraverser.traverse(accBody) + // Conflicting symbol list from parents: see bug #1960. + // It would be better to mangle the constructor parameter name since + // it can only be used internally, but I think we need more robust name + // mangling before we introduce more of it. + val parentSymbols = + Map(( for (p <- impl.parents ; sym <- p.symbol.info.nonPrivateMembers) yield sym.name -> p ): _*) + // Initialize all parameters fields that must be kept. - val paramInits = for (acc <- paramAccessors if mustbeKept(acc)) - yield copyParam(acc, parameter(acc)) + val paramInits = + for (acc <- paramAccessors if mustbeKept(acc)) yield { + if ((parentSymbols contains acc.name) && !(acc.name startsWith "$outer")) + unit.error(acc.pos, "parameter '%s' requires field but conflicts with %s in '%s'".format( + acc.name, acc.name, parentSymbols(acc.name))) + + copyParam(acc, parameter(acc)) + } // Assemble final constructor defBuf += copy.DefDef( @@ -275,7 +288,7 @@ abstract class Constructors extends Transform { // Eliminate all field definitions that can be dropped from template copy.Template(impl, impl.parents, impl.self, - defBuf.toList filter (stat => mustbeKept(stat.symbol))) + defBuf.toList filter (stat => mustbeKept(stat.symbol))) } // transformClassTemplate override def transform(tree: Tree): Tree = |