@@ -672,17 +672,13 @@ class CheckCaptures extends Recheck, SymTransformer:
672
672
def checkInferredResult (tp : Type , tree : ValOrDefDef )(using Context ): Type =
673
673
val sym = tree.symbol
674
674
675
- def isLocal =
676
- sym.owner.ownersIterator.exists(_.isTerm)
677
- || sym.accessBoundary(defn.RootClass ).isContainedIn(sym.topLevelClass)
678
-
679
675
def canUseInferred = // If canUseInferred is false, all capturing types in the type of `sym` need to be given explicitly
680
676
sym.is(Private ) // private symbols can always have inferred types
681
677
|| sym.name.is(DefaultGetterName ) // default getters are exempted since otherwise it would be
682
678
// too annoying. This is a hole since a defualt getter's result type
683
679
// might leak into a type variable.
684
680
|| // 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
686
682
&& ! sym.owner.is(Trait ) // they are defined in a trait, since we do OverridingPairs checking before capture inference
687
683
688
684
def addenda (expected : Type ) = new Addenda :
@@ -1182,7 +1178,7 @@ class CheckCaptures extends Recheck, SymTransformer:
1182
1178
/** Check that self types of subclasses conform to self types of super classes.
1183
1179
* (See comment below how this is achieved). The check assumes that classes
1184
1180
* 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 `
1186
1182
* it is checked that the inferred self type is universal, in order to assure
1187
1183
* that joint and separate compilation give the same result.
1188
1184
*/
@@ -1212,23 +1208,20 @@ class CheckCaptures extends Recheck, SymTransformer:
1212
1208
checkSelfAgainstParents(root, root.baseClasses)
1213
1209
val selfType = root.asClass.classInfo.selfType
1214
1210
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 _ =>
1232
1225
parentTrees -= root
1233
1226
capt.println(i " checked $root with $selfType" )
1234
1227
end checkSelfTypes
0 commit comments