diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala b/compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala index 4027cf9fb564..e1ff94be6362 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala @@ -60,7 +60,7 @@ final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) { assert(classSym.isClass, classSym) def enclosingMethod(sym: Symbol): Option[Symbol] = { if (sym.isClass || sym == NoSymbol) None - else if (sym.is(Method)) Some(sym) + else if (sym.is(Method, butNot=Synthetic)) Some(sym) else enclosingMethod(sym.originalOwner) } enclosingMethod(classSym.originalOwner) diff --git a/tests/run/i18701.check b/tests/run/i18701.check new file mode 100644 index 000000000000..2c0264028887 --- /dev/null +++ b/tests/run/i18701.check @@ -0,0 +1 @@ +public TB A$$anon$1.tb() diff --git a/tests/run/i18701.fixed.check b/tests/run/i18701.fixed.check new file mode 100644 index 000000000000..6d18ba0cbb0e --- /dev/null +++ b/tests/run/i18701.fixed.check @@ -0,0 +1 @@ +public TB A$$anon$2.apply() diff --git a/tests/run/i18701.fixed.scala b/tests/run/i18701.fixed.scala new file mode 100644 index 000000000000..361f3f40dc2b --- /dev/null +++ b/tests/run/i18701.fixed.scala @@ -0,0 +1,15 @@ +abstract class TA { def tb(): TB } +abstract class TB { def chk(): Unit } +class A: + def a(): TA = + new TA { + def tb(): TB = + val fn: () => TB = new Function0[TB]: + def apply(): TB = new TB { + def chk() = println(getClass.getEnclosingMethod()) + } + fn() + } + +object Test: + def main(args: Array[String]): Unit = new A().a().tb().chk() diff --git a/tests/run/i18701.scala b/tests/run/i18701.scala new file mode 100644 index 000000000000..45df41af8f06 --- /dev/null +++ b/tests/run/i18701.scala @@ -0,0 +1,14 @@ +abstract class TA { def tb(): TB } +abstract class TB { def chk(): Unit } +class A: + def a(): TA = + new TA { + def tb(): TB = + val fn: () => TB = () => new TB { + def chk() = println(getClass.getEnclosingMethod()) + } + fn() + } + +object Test: + def main(args: Array[String]): Unit = new A().a().tb().chk()