Skip to content

Commit

Permalink
Only check logicalOwners for methods, and not for classes, when looki…
Browse files Browse the repository at this point in the history
…ng for proxies (#22356)

possible fix for #21931
  • Loading branch information
KacperFKorban authored Jan 20, 2025
1 parent fe2e6e9 commit 08442e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i21931.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def f() =
val NotFound: Char = 'a'
class crashing() {
class issue() {
NotFound
}
class Module() {
val obligatory =
class anonIssue() {
issue()
}
}
}

0 comments on commit 08442e8

Please sign in to comment.