summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2015-02-09 14:28:12 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2015-02-09 14:28:12 -0800
commit41cee92bb516c6a9679773ebae88230c30ac67bd (patch)
tree26ef6d6c26349c1efee232d611cbe41ce1544bcb
parent27988cac0aaa681b8dfa8cd8e1fc4f4dd491e812 (diff)
parent486f92c5ddd6f02cdcd6e32329ce92f90a9fa1c9 (diff)
downloadscala-41cee92bb516c6a9679773ebae88230c30ac67bd.tar.gz
scala-41cee92bb516c6a9679773ebae88230c30ac67bd.tar.bz2
scala-41cee92bb516c6a9679773ebae88230c30ac67bd.zip
Merge pull request #4263 from lrytz/t9097
SI-9097 Remove spurious warning about conflicting filenames
-rw-r--r--src/compiler/scala/tools/nsc/transform/Delambdafy.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/Flatten.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/LambdaLift.scala5
-rw-r--r--test/files/run/t9097.scala34
4 files changed, 40 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
index d2c511a2d1..1f832ba81e 100644
--- a/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
+++ b/src/compiler/scala/tools/nsc/transform/Delambdafy.scala
@@ -113,7 +113,9 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
// after working on the entire compilation until we'll have a set of
// new class definitions to add to the top level
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
- super.transformStats(stats, exprOwner) ++ lambdaClassDefs(exprOwner)
+ // Need to remove from the lambdaClassDefs map: there may be multiple PackageDef for the same
+ // package when defining a package object. We only add the lambda class to one. See SI-9097.
+ super.transformStats(stats, exprOwner) ++ lambdaClassDefs.remove(exprOwner).getOrElse(Nil)
}
private def optionSymbol(sym: Symbol): Option[Symbol] = if (sym.exists) Some(sym) else None
diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala
index 6149e40fa7..fbb0307773 100644
--- a/src/compiler/scala/tools/nsc/transform/Flatten.scala
+++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala
@@ -166,7 +166,7 @@ abstract class Flatten extends InfoTransform {
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
val stats1 = super.transformStats(stats, exprOwner)
if (currentOwner.isPackageClass) {
- val lifted = liftedDefs(currentOwner).toList
+ val lifted = liftedDefs.remove(currentOwner).toList.flatten
stats1 ::: lifted
}
else stats1
diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
index fa0c1f797b..a703542587 100644
--- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
+++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
@@ -539,12 +539,11 @@ abstract class LambdaLift extends InfoTransform {
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
def addLifted(stat: Tree): Tree = stat match {
case ClassDef(_, _, _, _) =>
- val lifted = liftedDefs get stat.symbol match {
+ val lifted = liftedDefs remove stat.symbol match {
case Some(xs) => xs reverseMap addLifted
case _ => log("unexpectedly no lifted defs for " + stat.symbol) ; Nil
}
- try deriveClassDef(stat)(impl => deriveTemplate(impl)(_ ::: lifted))
- finally liftedDefs -= stat.symbol
+ deriveClassDef(stat)(impl => deriveTemplate(impl)(_ ::: lifted))
case DefDef(_, _, _, _, _, Block(Nil, expr)) if !stat.symbol.isConstructor =>
deriveDefDef(stat)(_ => expr)
diff --git a/test/files/run/t9097.scala b/test/files/run/t9097.scala
new file mode 100644
index 0000000000..d2bf55fc44
--- /dev/null
+++ b/test/files/run/t9097.scala
@@ -0,0 +1,34 @@
+import scala.tools.partest._
+import java.io.{Console => _, _}
+
+object Test extends StoreReporterDirectTest {
+
+ override def extraSettings: String = List(
+ "-usejavacp",
+ "-Xfatal-warnings",
+ "-Ybackend:GenBCode",
+ "-Ydelambdafy:method",
+ "-Xprint:delambdafy",
+ s"-d ${testOutput.path}"
+ ) mkString " "
+
+ override def code = """package o
+ |package a {
+ | class C {
+ | def hihi = List(1,2).map(_ * 2)
+ | }
+ |}
+ |package object a {
+ | def f = 1
+ |}
+ |""".stripMargin.trim
+
+ override def show(): Unit = {
+ val baos = new java.io.ByteArrayOutputStream()
+ Console.withOut(baos)(Console.withErr(baos)(compile()))
+ assert(!storeReporter.hasErrors, message = filteredInfos map (_.msg) mkString "; ")
+ val out = baos.toString("UTF-8")
+ // was 2 before the fix, the two PackageDefs for a would both contain the ClassDef for the closure
+ assert(out.lines.count(_ contains "class hihi$1") == 1, out)
+ }
+}