From 08442e883b0dacdbc60c6f697e2467bfdf1643cd Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Mon, 20 Jan 2025 12:03:28 +0100 Subject: [PATCH] Only check logicalOwners for methods, and not for classes, when looking for proxies (#22356) possible fix for #21931 --- .../dotty/tools/dotc/transform/Dependencies.scala | 2 +- .../src/dotty/tools/dotc/transform/LambdaLift.scala | 4 +++- tests/pos/i21931.scala | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i21931.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Dependencies.scala b/compiler/src/dotty/tools/dotc/transform/Dependencies.scala index 523ea75be912..1270c13460f4 100644 --- a/compiler/src/dotty/tools/dotc/transform/Dependencies.scala +++ b/compiler/src/dotty/tools/dotc/transform/Dependencies.scala @@ -30,7 +30,7 @@ abstract class Dependencies(root: ast.tpd.Tree, @constructorOnly rootContext: Co def tracked: Iterable[Symbol] = free.keys /** The outermost class that captures all free variables of a function - * that are captured by enclosinh classes (this means that the function could + * that are captured by enclosing classes (this means that the function could * be placed in that class without having to add more environment parameters) */ def logicalOwner: collection.Map[Symbol, Symbol] = logicOwner diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 47a280af6abc..c43392f14f06 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -129,7 +129,9 @@ object LambdaLift: private def proxy(sym: Symbol)(using Context): Symbol = { def liftedEnclosure(sym: Symbol) = - deps.logicalOwner.getOrElse(sym, sym.enclosure) + if sym.is(Method) + then deps.logicalOwner.getOrElse(sym, sym.enclosure) + else sym.enclosure def searchIn(enclosure: Symbol): Symbol = { if (!enclosure.exists) { def enclosures(encl: Symbol): List[Symbol] = diff --git a/tests/pos/i21931.scala b/tests/pos/i21931.scala new file mode 100644 index 000000000000..6765768874af --- /dev/null +++ b/tests/pos/i21931.scala @@ -0,0 +1,13 @@ +def f() = + val NotFound: Char = 'a' + class crashing() { + class issue() { + NotFound + } + class Module() { + val obligatory = + class anonIssue() { + issue() + } + } + }