diff options
author | Paul Phillips <paulp@improving.org> | 2009-09-23 18:26:59 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-09-23 18:26:59 +0000 |
commit | 9992fe264c779e36e27bad215ac42012e05cfde4 (patch) | |
tree | c174b55852491d48db8f8e4e71243b6dcb35afbd /src | |
parent | 4edbecfe9baaec89ced227f5bd6b92fb1f54e1ec (diff) | |
download | scala-9992fe264c779e36e27bad215ac42012e05cfde4.tar.gz scala-9992fe264c779e36e27bad215ac42012e05cfde4.tar.bz2 scala-9992fe264c779e36e27bad215ac42012e05cfde4.zip |
Fix and test case for #2377.
Diffstat (limited to 'src')
-rwxr-xr-x | src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 4d36816853..4d230470c6 100755 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -633,9 +633,29 @@ trait JavaParsers extends JavaScanners { Import(Ident(cdef.name.toTermName), List((nme.WILDCARD, null))) } - // create companion object even if it has no statics, so import A._ works; bug #1700 - def addCompanionObject(statics: List[Tree], cdef: ClassDef): List[Tree] = - List(makeCompanionObject(cdef, statics), importCompanionObject(cdef), cdef) + // Importing the companion object members cannot be done uncritically: see + // ticket #2377 wherein a class contains two static inner classes, each of which + // has a static inner class called "Builder" - this results in an ambiguity error + // when each performs the import in the enclosing class's scope. + // + // To address this I moved the import Companion._ inside the class, as the first + // statement. This should work without compromising the enclosing scope, but may (?) + // end up suffering from the same issues it does in scala - specifically that this + // leaves auxiliary constructors unable to access members of the companion object + // as unqualified identifiers. + def addCompanionObject(statics: List[Tree], cdef: ClassDef): List[Tree] = { + def implWithImport(importStmt: Tree) = { + import cdef.impl._ + treeCopy.Template(cdef.impl, parents, self, importStmt :: body) + } + // if there are no statics we can use the original cdef, but we always + // create the companion so import A._ is not an error (see ticket #1700) + val cdefNew = + if (statics.isEmpty) cdef + else treeCopy.ClassDef(cdef, cdef.mods, cdef.name, cdef.tparams, implWithImport(importCompanionObject(cdef))) + + List(makeCompanionObject(cdefNew, statics), cdefNew) + } def importDecl(): List[Tree] = { accept(IMPORT) |