Skip to content

Commit a8b6e36

Browse files
committed
SI-9097 Remove spurious warning about conflicting filenames
When using delambdafy:method, closure classes are generated late. The class is added to a map and integrated into the PackageDef in transformStats. When declaring a package object, there are potentially multiple PackageDefs for the same package. In this case, the closure class was added to all of them. As a result, GenASM / GenBCode would run multiple times on the closure class. In GenBCode this would trigger a warning about conflicting filenames.
1 parent 783c5cc commit a8b6e36

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/compiler/scala/tools/nsc/transform/Delambdafy.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ abstract class Delambdafy extends Transform with TypingTransformers with ast.Tre
113113
// after working on the entire compilation until we'll have a set of
114114
// new class definitions to add to the top level
115115
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
116-
super.transformStats(stats, exprOwner) ++ lambdaClassDefs(exprOwner)
116+
// Need to remove from the lambdaClassDefs map: there may be multiple PackageDef for the same
117+
// package when defining a package object. We only add the lambda class to one. See SI-9097.
118+
super.transformStats(stats, exprOwner) ++ lambdaClassDefs.remove(exprOwner).getOrElse(Nil)
117119
}
118120

119121
private def optionSymbol(sym: Symbol): Option[Symbol] = if (sym.exists) Some(sym) else None

test/files/pos/t9097.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Ydelambdafy:method -Ybackend:GenBCode -Xfatal-warnings

test/files/pos/t9097.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package o
2+
package a {
3+
class C {
4+
def hihi = List(1,2).map(_ * 2)
5+
}
6+
}
7+
package object a {
8+
def f = 1
9+
}

test/files/run/t9097.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import scala.tools.partest._
2+
import java.io.{Console => _, _}
3+
4+
object Test extends DirectTest {
5+
6+
override def extraSettings: String = "-usejavacp -Ydelambdafy:method -Xprint:delambdafy -d " + testOutput.path
7+
8+
override def code = """package o
9+
|package a {
10+
| class C {
11+
| def hihi = List(1,2).map(_ * 2)
12+
| }
13+
|}
14+
|package object a {
15+
| def f = 1
16+
|}
17+
|""".stripMargin.trim
18+
19+
override def show(): Unit = {
20+
val baos = new java.io.ByteArrayOutputStream()
21+
Console.withOut(baos)(Console.withErr(baos)(compile()))
22+
val out = baos.toString("UTF-8")
23+
// was 2 before the fix, the two PackageDefs for a would both contain the ClassDef for the closure
24+
assert(out.lines.count(_ contains "class hihi$1") == 1, out)
25+
}
26+
}

0 commit comments

Comments
 (0)