diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/ScalaSettings.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala | 29 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 3dab85f77c..70f6ea0b89 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -109,6 +109,8 @@ trait ScalaSettings extends AbsScalaSettings with StandardScalaSettings { val Xdce = BooleanSetting ("-Ydead-code", "Perform dead code elimination.") val debug = BooleanSetting ("-Ydebug", "Increase the quantity of debugging output.") // val doc = BooleanSetting ("-Ydoc", "Generate documentation") + val termConflict = ChoiceSetting ("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", + List("package", "object", "error"), "error") val inline = BooleanSetting ("-Yinline", "Perform inlining when possible.") val Xlinearizer = ChoiceSetting ("-Ylinearizer", "which", "Linearizer to use", List("normal", "dfs", "rpo", "dump"), "rpo") val log = PhasesSetting ("-Ylog", "Log operations during") diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index ff54613d47..83b6168c03 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -151,9 +151,32 @@ abstract class SymbolLoaders { def enterPackage(root: Symbol, name: String, completer: SymbolLoader) { val preExisting = root.info.decls.lookup(newTermName(name)) - if (preExisting != NoSymbol) - throw new TypeError( - root+" contains object and package with same name: "+name+"\none of them needs to be removed from classpath") + if (preExisting != NoSymbol) { + // Some jars (often, obfuscated ones) include a package and + // object with the same name. Rather than render them unusable, + // offer a setting to resolve the conflict one way or the other. + // This was motivated by the desire to use YourKit probes, which + // require yjp.jar at runtime. See SI-2089. + if (settings.termConflict.isDefault) + throw new TypeError( + root+" contains object and package with same name: "+ + name+"\none of them needs to be removed from classpath" + ) + else if (settings.termConflict.value == "package") { + global.warning( + "Resolving package/object name conflict in favor of package " + + preExisting.fullName + ". The object will be inaccessible." + ) + root.info.decls.unlink(preExisting) + } + else { + global.warning( + "Resolving package/object name conflict in favor of object " + + preExisting.fullName + ". The package will be inaccessible." + ) + return + } + } val pkg = root.newPackage(NoPosition, newTermName(name)) pkg.moduleClass.setInfo(completer) pkg.setInfo(pkg.moduleClass.tpe) |