@@ -1120,18 +1120,23 @@ class CheckCaptures extends Recheck, SymTransformer:
1120
1120
}
1121
1121
if ! canUseInferred then
1122
1122
val inferred = t.tpt.knownType
1123
- def checkPure (tp : Type ) = tp match
1124
- case CapturingType (_, refs)
1125
- if ! refs.elems.filter(isNotPureThis).isEmpty =>
1126
- val resultStr = if t.isInstanceOf [DefDef ] then " result" else " "
1127
- report.error(
1128
- em """ Non-local $sym cannot have an inferred $resultStr type
1129
- | $inferred
1130
- |with non-empty capture set $refs.
1131
- |The type needs to be declared explicitly. """ .withoutDisambiguation(),
1132
- t.srcPos)
1133
- case _ =>
1134
- inferred.foreachPart(checkPure, StopAt .Static )
1123
+ val checkPure = new TypeTraverser :
1124
+ def traverse (tp : Type ) = tp match
1125
+ case CapturingType (_, refs)
1126
+ if ! refs.elems.filter(isNotPureThis).isEmpty =>// && variance >= 0 =>
1127
+ val resultStr = if t.isInstanceOf [DefDef ] then " result" else " "
1128
+ val partStr =
1129
+ if tp eq inferred then " with non-empty capture set"
1130
+ else i " since its part $tp has non-empty capture set "
1131
+ report.error(
1132
+ em """ Non-local $sym cannot have an inferred $resultStr type
1133
+ | $inferred
1134
+ | $partStr $refs.
1135
+ |The type needs to be declared explicitly. """ .withoutDisambiguation(),
1136
+ t.srcPos)
1137
+ case _ =>
1138
+ traverseChildren(tp)
1139
+ checkPure.traverse(inferred)
1135
1140
case t @ TypeApply (fun, args) =>
1136
1141
fun.knownType.widen match
1137
1142
case tl : PolyType =>
0 commit comments