File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments