@@ -672,17 +672,13 @@ class CheckCaptures extends Recheck, SymTransformer:
672672 def checkInferredResult (tp : Type , tree : ValOrDefDef )(using Context ): Type =
673673 val sym = tree.symbol
674674
675- def isLocal =
676- sym.owner.ownersIterator.exists(_.isTerm)
677- || sym.accessBoundary(defn.RootClass ).isContainedIn(sym.topLevelClass)
678-
679675 def canUseInferred = // If canUseInferred is false, all capturing types in the type of `sym` need to be given explicitly
680676 sym.is(Private ) // private symbols can always have inferred types
681677 || sym.name.is(DefaultGetterName ) // default getters are exempted since otherwise it would be
682678 // too annoying. This is a hole since a defualt getter's result type
683679 // might leak into a type variable.
684680 || // non-local symbols cannot have inferred types since external capture types are not inferred
685- isLocal // local symbols still need explicit types if
681+ sym.isLocalToCompilationUnit // local symbols still need explicit types if
686682 && ! sym.owner.is(Trait ) // they are defined in a trait, since we do OverridingPairs checking before capture inference
687683
688684 def addenda (expected : Type ) = new Addenda :
@@ -1178,7 +1174,7 @@ class CheckCaptures extends Recheck, SymTransformer:
11781174 /** Check that self types of subclasses conform to self types of super classes.
11791175 * (See comment below how this is achieved). The check assumes that classes
11801176 * without an explicit self type have the universal capture set `{cap}` on the
1181- * self type. If a class without explicit self type is not `effectivelyFinal `
1177+ * self type. If a class without explicit self type is not `effectivelySealed `
11821178 * it is checked that the inferred self type is universal, in order to assure
11831179 * that joint and separate compilation give the same result.
11841180 */
@@ -1208,23 +1204,20 @@ class CheckCaptures extends Recheck, SymTransformer:
12081204 checkSelfAgainstParents(root, root.baseClasses)
12091205 val selfType = root.asClass.classInfo.selfType
12101206 interpolator(startingVariance = - 1 ).traverse(selfType)
1211- if ! root.isEffectivelySealed then
1212- def matchesExplicitRefsInBaseClass (refs : CaptureSet , cls : ClassSymbol ): Boolean =
1213- cls.baseClasses.tail.exists { psym =>
1214- val selfType = psym.asClass.givenSelfType
1215- selfType.exists && selfType.captureSet.elems == refs.elems
1216- }
1217- selfType match
1218- case CapturingType (_, refs : CaptureSet .Var )
1219- if ! refs.elems.exists(_.isRootCapability) && ! matchesExplicitRefsInBaseClass(refs, root) =>
1220- // Forbid inferred self types unless they are already implied by an explicit
1221- // self type in a parent.
1222- report.error(
1223- em """ $root needs an explicitly declared self type since its
1224- |inferred self type $selfType
1225- |is not visible in other compilation units that define subclasses. """ ,
1226- root.srcPos)
1227- case _ =>
1207+ selfType match
1208+ case CapturingType (_, refs : CaptureSet .Var )
1209+ if ! root.isEffectivelySealed
1210+ && ! refs.elems.exists(_.isRootCapability)
1211+ && ! root.matchesExplicitRefsInBaseClass(refs)
1212+ =>
1213+ // Forbid inferred self types unless they are already implied by an explicit
1214+ // self type in a parent.
1215+ report.error(
1216+ em """ $root needs an explicitly declared self type since its
1217+ |inferred self type $selfType
1218+ |is not visible in other compilation units that define subclasses. """ ,
1219+ root.srcPos)
1220+ case _ =>
12281221 parentTrees -= root
12291222 capt.println(i " checked $root with $selfType" )
12301223 end checkSelfTypes
0 commit comments