diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Constructors.scala | 19 | ||||
-rw-r--r-- | test/files/neg/bug1960.check | 4 | ||||
-rw-r--r-- | test/files/neg/bug1960.scala | 5 |
3 files changed, 25 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 = diff --git a/test/files/neg/bug1960.check b/test/files/neg/bug1960.check new file mode 100644 index 0000000000..6615d90036 --- /dev/null +++ b/test/files/neg/bug1960.check @@ -0,0 +1,4 @@ +bug1960.scala:5: error: parameter 'p' requires field but conflicts with p in 'TBase' +class Aclass (p: Int) extends TBase { def g{ f(p) } } + ^ +one error found diff --git a/test/files/neg/bug1960.scala b/test/files/neg/bug1960.scala new file mode 100644 index 0000000000..b381e9df23 --- /dev/null +++ b/test/files/neg/bug1960.scala @@ -0,0 +1,5 @@ +object ClassFormatErrorExample extends Application { new Aclass(1) } + +trait TBase { var p:Int = 0; def f(p1: Int) {} } + +class Aclass (p: Int) extends TBase { def g{ f(p) } } |