@@ -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 :
@@ -1182,7 +1178,7 @@ class CheckCaptures extends Recheck, SymTransformer:
11821178 /** Check that self types of subclasses conform to self types of super classes.
11831179 * (See comment below how this is achieved). The check assumes that classes
11841180 * without an explicit self type have the universal capture set `{cap}` on the
1185- * self type. If a class without explicit self type is not `effectivelyFinal `
1181+ * self type. If a class without explicit self type is not `effectivelySealed `
11861182 * it is checked that the inferred self type is universal, in order to assure
11871183 * that joint and separate compilation give the same result.
11881184 */
@@ -1212,23 +1208,20 @@ class CheckCaptures extends Recheck, SymTransformer:
12121208 checkSelfAgainstParents(root, root.baseClasses)
12131209 val selfType = root.asClass.classInfo.selfType
12141210 interpolator(startingVariance = - 1 ).traverse(selfType)
1215- if ! root.isEffectivelySealed then
1216- def matchesExplicitRefsInBaseClass (refs : CaptureSet , cls : ClassSymbol ): Boolean =
1217- cls.baseClasses.tail.exists { psym =>
1218- val selfType = psym.asClass.givenSelfType
1219- selfType.exists && selfType.captureSet.elems == refs.elems
1220- }
1221- selfType match
1222- case CapturingType (_, refs : CaptureSet .Var )
1223- if ! refs.elems.exists(_.isRootCapability) && ! matchesExplicitRefsInBaseClass(refs, root) =>
1224- // Forbid inferred self types unless they are already implied by an explicit
1225- // self type in a parent.
1226- report.error(
1227- em """ $root needs an explicitly declared self type since its
1228- |inferred self type $selfType
1229- |is not visible in other compilation units that define subclasses. """ ,
1230- root.srcPos)
1231- case _ =>
1211+ selfType match
1212+ case CapturingType (_, refs : CaptureSet .Var )
1213+ if ! root.isEffectivelySealed
1214+ && ! refs.elems.exists(_.isRootCapability)
1215+ && ! root.matchesExplicitRefsInBaseClass(refs)
1216+ =>
1217+ // Forbid inferred self types unless they are already implied by an explicit
1218+ // self type in a parent.
1219+ report.error(
1220+ em """ $root needs an explicitly declared self type since its
1221+ |inferred self type $selfType
1222+ |is not visible in other compilation units that define subclasses. """ ,
1223+ root.srcPos)
1224+ case _ =>
12321225 parentTrees -= root
12331226 capt.println(i " checked $root with $selfType" )
12341227 end checkSelfTypes
0 commit comments