summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/transform/Delambdafy.scala4
-rw-r--r--test/files/pos/t9097.flags1
-rw-r--r--test/files/pos/t9097.scala9
-rw-r--r--test/files/run/t9097.scala26
4 files changed, 39 insertions, 1 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/test/files/pos/t9097.flags b/test/files/pos/t9097.flags
new file mode 100644
index 0000000000..0f8175b88b
--- /dev/null
+++ b/test/files/pos/t9097.flags
@@ -0,0 +1 @@
+-Ydelambdafy:method -Ybackend:GenBCode -Xfatal-warnings \ No newline at end of file
diff --git a/test/files/pos/t9097.scala b/test/files/pos/t9097.scala
new file mode 100644
index 0000000000..5e0e921271
--- /dev/null
+++ b/test/files/pos/t9097.scala
@@ -0,0 +1,9 @@
+package o
+package a {
+ class C {
+ def hihi = List(1,2).map(_ * 2)
+ }
+}
+package object a {
+ def f = 1
+}
diff --git a/test/files/run/t9097.scala b/test/files/run/t9097.scala
new file mode 100644
index 0000000000..0f148c3b9d
--- /dev/null
+++ b/test/files/run/t9097.scala
@@ -0,0 +1,26 @@
+import scala.tools.partest._
+import java.io.{Console => _, _}
+
+object Test extends DirectTest {
+
+ override def extraSettings: String = "-usejavacp -Ydelambdafy:method -Xprint:delambdafy -d " + testOutput.path
+
+ 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()))
+ 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)
+ }
+}