Skip to content

Commit 694f369

Browse files
authored
Merge pull request #250 from scala/backport-lts-3.3-22452
Backport "fix: treat static vals as enclosures in lambdalift" to 3.3 LTS
2 parents 9f6d045 + 65bc5aa commit 694f369

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,15 @@ object SymDenotations {
12181218
else if (this.exists) owner.enclosingMethod
12191219
else NoSymbol
12201220

1221+
/** The closest enclosing method or static symbol containing this definition.
1222+
* A local dummy owner is mapped to the primary constructor of the class.
1223+
*/
1224+
final def enclosingMethodOrStatic(using Context): Symbol =
1225+
if this.is(Method) || this.hasAnnotation(defn.ScalaStaticAnnot) then symbol
1226+
else if this.isClass then primaryConstructor
1227+
else if this.exists then owner.enclosingMethodOrStatic
1228+
else NoSymbol
1229+
12211230
/** The closest enclosing extension method containing this definition,
12221231
* including methods outside the current class.
12231232
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ object LambdaLift:
3434
val liftedDefs: HashMap[Symbol, ListBuffer[Tree]] = new HashMap
3535

3636
val deps = new Dependencies(ctx.compilationUnit.tpdTree, ctx.withPhase(thisPhase)):
37-
def isExpr(sym: Symbol)(using Context): Boolean = sym.is(Method)
38-
def enclosure(using Context) = ctx.owner.enclosingMethod
37+
def isExpr(sym: Symbol)(using Context): Boolean = sym.is(Method) || sym.hasAnnotation(defn.ScalaStaticAnnot)
38+
def enclosure(using Context) = ctx.owner.enclosingMethodOrStatic
3939

4040
override def process(tree: Tree)(using Context): Unit =
4141
super.process(tree)

tests/pos/i22408.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Obj:
2+
@scala.annotation.static
3+
val some_static_value: Int = {
4+
val some_local_value: Int = {
5+
val some_local_value_1 = ???
6+
some_local_value_1
7+
}
8+
some_local_value
9+
}
10+
11+
class Obj

0 commit comments

Comments
 (0)