Skip to content

Commit a4a9dff

Browse files
KacperFKorbantgodzik
authored andcommitted
Only check logicalOwners for methods, and not for classes, when looking for proxies (scala#22356)
possible fix for scala#21931 [Cherry-picked 08442e8]
1 parent 0886974 commit a4a9dff

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
@@ -29,7 +29,7 @@ abstract class Dependencies(root: ast.tpd.Tree, @constructorOnly rootContext: Co
2929
def tracked: Iterable[Symbol] = free.keys
3030

3131
/** The outermost class that captures all free variables of a function
32-
* that are captured by enclosinh classes (this means that the function could
32+
* that are captured by enclosing classes (this means that the function could
3333
* be placed in that class without having to add more environment parameters)
3434
*/
3535
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
@@ -127,7 +127,9 @@ object LambdaLift:
127127

128128
private def proxy(sym: Symbol)(using Context): Symbol = {
129129
def liftedEnclosure(sym: Symbol) =
130-
deps.logicalOwner.getOrElse(sym, sym.enclosure)
130+
if sym.is(Method)
131+
then deps.logicalOwner.getOrElse(sym, sym.enclosure)
132+
else sym.enclosure
131133
def searchIn(enclosure: Symbol): Symbol = {
132134
if (!enclosure.exists) {
133135
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)