Skip to content

Commit 08442e8

Browse files
Only check logicalOwners for methods, and not for classes, when looking for proxies (#22356)
possible fix for #21931
1 parent fe2e6e9 commit 08442e8

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

compiler/src/dotty/tools/dotc/transform/Dependencies.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class Dependencies(root: ast.tpd.Tree, @constructorOnly rootContext: Co
3030
def tracked: Iterable[Symbol] = free.keys
3131

3232
/** The outermost class that captures all free variables of a function
33-
* that are captured by enclosinh classes (this means that the function could
33+
* that are captured by enclosing classes (this means that the function could
3434
* be placed in that class without having to add more environment parameters)
3535
*/
3636
def logicalOwner: collection.Map[Symbol, Symbol] = logicOwner

compiler/src/dotty/tools/dotc/transform/LambdaLift.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ object LambdaLift:
129129

130130
private def proxy(sym: Symbol)(using Context): Symbol = {
131131
def liftedEnclosure(sym: Symbol) =
132-
deps.logicalOwner.getOrElse(sym, sym.enclosure)
132+
if sym.is(Method)
133+
then deps.logicalOwner.getOrElse(sym, sym.enclosure)
134+
else sym.enclosure
133135
def searchIn(enclosure: Symbol): Symbol = {
134136
if (!enclosure.exists) {
135137
def enclosures(encl: Symbol): List[Symbol] =

tests/pos/i21931.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def f() =
2+
val NotFound: Char = 'a'
3+
class crashing() {
4+
class issue() {
5+
NotFound
6+
}
7+
class Module() {
8+
val obligatory =
9+
class anonIssue() {
10+
issue()
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)