diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 81a114e03fbc..17772df9b91c 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -100,7 +100,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform * Note: During tree transform (which runs at phase LambdaLift + 1), liftedOwner * is also used to decide whether a method had a term owner before. */ - private val liftedOwner = new HashMap[Symbol, Symbol] + private val liftedOwner = new LinkedHashMap[Symbol, Symbol] /** The outer parameter of a constructor */ private val outerParam = new HashMap[Symbol, Symbol] diff --git a/tests/run/i2738.check b/tests/run/i2738.check new file mode 100644 index 000000000000..1261ac914586 --- /dev/null +++ b/tests/run/i2738.check @@ -0,0 +1,8 @@ +foo +bar$1 +foo +bar$2 +baz +Test$qux$2$ +baz +Test$qux$4$ diff --git a/tests/run/i2738.scala b/tests/run/i2738.scala new file mode 100644 index 000000000000..b7c87e0dc8f9 --- /dev/null +++ b/tests/run/i2738.scala @@ -0,0 +1,49 @@ +object Test { + + def main(args: Array[String]): Unit = { + foo(1) + foo("a") + baz(2) + baz("b") + } + + def foo[X <: Int](x: X) = { + def bar = printlnThisMethodName() + printlnThisMethodName() + bar + } + + def foo(x: String) = { + def bar = printlnThisMethodName() + printlnThisMethodName() + bar + } + + def baz[X <: Int](x: X) = { + object qux { + override def toString() = { + printlnThisMethodsClassName() + "a" + } + } + printlnThisMethodName() + qux.toString() + } + + def baz(x: String) = { + object qux { + override def toString() = { + printlnThisMethodsClassName() + "b" + } + } + printlnThisMethodName() + qux.toString() + } + + def printlnThisMethodName() = + println(Thread.currentThread().getStackTrace()(2).getMethodName) + + def printlnThisMethodsClassName() = + println(Thread.currentThread().getStackTrace()(2).getClassName) +}