Skip to content

Commit de35cbb

Browse files
committed
Tweaks to level checking
- In levelOwner, don't skip constructors. These are significant now. - Skip non-static modules when computing the visibility of FreshCaps
1 parent badf872 commit de35cbb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

compiler/src/dotty/tools/dotc/cc/Capability.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ object Capabilities:
489489
case _ /* : GlobalCap | ResultCap | ParamRef */ => NoSymbol
490490

491491
final def visibility(using Context): Symbol = this match
492-
case self: FreshCap => ccOwner.enclosingMethodOrClass
492+
case self: FreshCap => adjustOwner(ccOwner)
493493
case _ =>
494494
val vis = ccOwner
495495
if vis.is(Param) then vis.owner else vis
@@ -500,13 +500,14 @@ object Capabilities:
500500
* - method symbols, but not accessors or constructors
501501
*/
502502
final def levelOwner(using Context): Symbol =
503-
def adjust(owner: Symbol): Symbol =
504-
if !owner.exists
505-
|| owner.isClass && (!owner.is(Flags.Module) || owner.isStatic)
506-
|| owner.is(Flags.Method, butNot = Flags.Accessor) && !owner.isConstructor
507-
then owner
508-
else adjust(owner.owner)
509-
adjust(ccOwner)
503+
adjustOwner(ccOwner)
504+
505+
private def adjustOwner(owner: Symbol)(using Context): Symbol =
506+
if !owner.exists
507+
|| owner.isClass && (!owner.is(Flags.Module) || owner.isStatic)
508+
|| owner.is(Flags.Method, butNot = Flags.Accessor)
509+
then owner
510+
else adjustOwner(owner.owner)
510511

511512
/** Tests whether the capability derives from capability class `cls`. */
512513
def derivesFromCapTrait(cls: ClassSymbol)(using Context): Boolean = this match

0 commit comments

Comments
 (0)