Skip to content

Commit 5e2e34b

Browse files
committed
Allow all private definitions to have inferred types
1 parent c3b1660 commit 5e2e34b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -871,12 +871,13 @@ class CheckCaptures extends Recheck, SymTransformer:
871871
val isLocal =
872872
sym.owner.ownersIterator.exists(_.isTerm)
873873
|| sym.accessBoundary(defn.RootClass).isContainedIn(sym.topLevelClass)
874-
875-
// The following classes of definitions need explicit capture types ...
876-
if !isLocal // ... since external capture types are not inferred
877-
|| sym.owner.is(Trait) // ... since we do OverridingPairs checking before capture inference
878-
|| sym.allOverriddenSymbols.nonEmpty // ... since we do override checking before capture inference
879-
then
874+
def canUseInferred = // If canUseInferred is false, all capturing types in the type of `sym` need to be given explicitly
875+
sym.is(Private) // private symbols can always have inferred types
876+
|| // non-local symbols cannot have inferred types since external capture types are not inferred
877+
isLocal // local symbols still need an explicit types if
878+
&& !sym.owner.is(Trait) // - they are defined in a trait, since we do OverridingPairs checking before capture inference
879+
&& !sym.allOverriddenSymbols.nonEmpty // - they override some other symbol, since we do override checking before capture inference
880+
if !canUseInferred then
880881
val inferred = t.tpt.knownType
881882
def checkPure(tp: Type) = tp match
882883
case CapturingType(_, refs) if !refs.elems.isEmpty =>

0 commit comments

Comments
 (0)