Skip to content

Commit 41cee92

Browse files
committed
Merge pull request scala#4263 from lrytz/t9097
SI-9097 Remove spurious warning about conflicting filenames
2 parents 27988ca + 486f92c commit 41cee92

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ abstract class Flatten extends InfoTransform {
166166
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
167167
val stats1 = super.transformStats(stats, exprOwner)
168168
if (currentOwner.isPackageClass) {
169-
val lifted = liftedDefs(currentOwner).toList
169+
val lifted = liftedDefs.remove(currentOwner).toList.flatten
170170
stats1 ::: lifted
171171
}
172172
else stats1

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,11 @@ abstract class LambdaLift extends InfoTransform {
539539
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
540540
def addLifted(stat: Tree): Tree = stat match {
541541
case ClassDef(_, _, _, _) =>
542-
val lifted = liftedDefs get stat.symbol match {
542+
val lifted = liftedDefs remove stat.symbol match {
543543
case Some(xs) => xs reverseMap addLifted
544544
case _ => log("unexpectedly no lifted defs for " + stat.symbol) ; Nil
545545
}
546-
try deriveClassDef(stat)(impl => deriveTemplate(impl)(_ ::: lifted))
547-
finally liftedDefs -= stat.symbol
546+
deriveClassDef(stat)(impl => deriveTemplate(impl)(_ ::: lifted))
548547

549548
case DefDef(_, _, _, _, _, Block(Nil, expr)) if !stat.symbol.isConstructor =>
550549
deriveDefDef(stat)(_ => expr)

test/files/run/t9097.scala

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

0 commit comments

Comments
 (0)