Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/run/i18701.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public TB A$$anon$1.tb()
1 change: 1 addition & 0 deletions tests/run/i18701.fixed.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public TB A$$anon$2.apply()
17 changes: 17 additions & 0 deletions tests/run/i18701.fixed.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// scalajs: --skip
// Use of Java reflection (getEnclosingMethod)
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()
16 changes: 16 additions & 0 deletions tests/run/i18701.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// scalajs: --skip
// Use of Java reflection (getEnclosingMethod)
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()