summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorJames Iry <jamesiry@gmail.com>2013-02-04 14:48:23 -0800
committerJames Iry <jamesiry@gmail.com>2013-02-06 13:00:43 -0800
commit1426fec358342e0b052c5a96ee2b7e60d4d4066b (patch)
tree6ec782d4d4f9c6afe592cd335462e4e37a03d69f /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent3d318be51f8e8cdec314565920327486212f5020 (diff)
downloadscala-1426fec358342e0b052c5a96ee2b7e60d4d4066b.tar.gz
scala-1426fec358342e0b052c5a96ee2b7e60d4d4066b.tar.bz2
scala-1426fec358342e0b052c5a96ee2b7e60d4d4066b.zip
SI-7070 Turn restriction on companions in pkg objs into warning
The implementation restriction created from SI-5954 in 3ef487ecb6733bfe3c13d89780ebcfc81f9a5ea0 has two problems. 1) The problematic code works fine if compile with sbt. That means the restriction is breaking some people needlessly. 2) It's not binary compatible. To fix all that this commit changes the error into a warning and removes the setting used to get around the restriction.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 026c130a87..795ad7e5c7 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1914,29 +1914,29 @@ trait Typers extends Modes with Adaptations with Tags {
// SI-5954. On second compile of a companion class contained in a package object we end up
// with some confusion of names which leads to having two symbols with the same name in the
- // same owner. Until that can be straightened out we can't allow companion objects in package
+ // same owner. Until that can be straightened out we will warn on companion objects in package
// objects. But this code also tries to be friendly by distinguishing between case classes and
// user written companion pairs
- def restrictPackageObjectMembers(mdef : ModuleDef) = for (m <- mdef.symbol.info.members) {
+ def warnPackageObjectMembers(mdef : ModuleDef) = for (m <- mdef.symbol.info.members) {
// ignore synthetic objects, because the "companion" object to a case class is synthetic and
// we only want one error per case class
if (!m.isSynthetic) {
// can't handle case classes in package objects
- if (m.isCaseClass) pkgObjectRestriction(m, mdef, "case")
+ if (m.isCaseClass) pkgObjectWarning(m, mdef, "case")
// can't handle companion class/object pairs in package objects
else if ((m.isClass && m.companionModule != NoSymbol && !m.companionModule.isSynthetic) ||
(m.isModule && m.companionClass != NoSymbol && !m.companionClass.isSynthetic))
- pkgObjectRestriction(m, mdef, "companion")
+ pkgObjectWarning(m, mdef, "companion")
}
- def pkgObjectRestriction(m : Symbol, mdef : ModuleDef, restricted : String) = {
+ def pkgObjectWarning(m : Symbol, mdef : ModuleDef, restricted : String) = {
val pkgName = mdef.symbol.ownerChain find (_.isPackage) map (_.decodedName) getOrElse mdef.symbol.toString
- context.error(if (m.pos.isDefined) m.pos else mdef.pos, s"implementation restriction: package object ${pkgName} cannot contain ${restricted} ${m}. Instead, ${m} should be placed directly in package ${pkgName}.")
+ context.warning(if (m.pos.isDefined) m.pos else mdef.pos, s"${m} should be placed directly in package ${pkgName} instead of package object ${pkgName}. Under some circumstances companion objects and case classes in package objects can fail to recompile. See https://issues.scala-lang.org/browse/SI-5954.")
}
}
- if (!settings.companionsInPkgObjs.value && mdef.symbol.isPackageObject)
- restrictPackageObjectMembers(mdef)
+ if (mdef.symbol.isPackageObject)
+ warnPackageObjectMembers(mdef)
treeCopy.ModuleDef(mdef, typedMods, mdef.name, impl2) setType NoType
}