Skip to content

Commit

Permalink
Merge pull request scala#4263 from lrytz/t9097
Browse files Browse the repository at this point in the history
SI-9097 Remove spurious warning about conflicting filenames
  • Loading branch information
adriaanm committed Feb 9, 2015
2 parents 27988ca + 486f92c commit 41cee92
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/nsc/transform/Delambdafy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/transform/Flatten.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/scala/tools/nsc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions test/files/run/t9097.scala
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 41cee92

Please sign in to comment.