@@ -42,7 +42,8 @@ class FindCapturedVars : public ASTWalker {
42
42
OpaqueValueExpr *OpaqueValue = nullptr ;
43
43
SourceLoc CaptureLoc;
44
44
DeclContext *CurDC;
45
- bool NoEscape, ObjC, IsGenericFunction;
45
+ bool NoEscape, ObjC;
46
+ bool HasGenericParamCaptures;
46
47
47
48
public:
48
49
FindCapturedVars (SourceLoc CaptureLoc,
@@ -51,23 +52,23 @@ class FindCapturedVars : public ASTWalker {
51
52
bool ObjC,
52
53
bool IsGenericFunction)
53
54
: Context(CurDC->getASTContext ()), CaptureLoc(CaptureLoc), CurDC(CurDC),
54
- NoEscape(NoEscape), ObjC(ObjC), IsGenericFunction (IsGenericFunction) {}
55
+ NoEscape(NoEscape), ObjC(ObjC), HasGenericParamCaptures (IsGenericFunction) {}
55
56
56
57
CaptureInfo getCaptureInfo () const {
57
58
DynamicSelfType *dynamicSelfToRecord = nullptr ;
58
- bool hasGenericParamCaptures = IsGenericFunction;
59
59
60
60
// Only local functions capture dynamic 'Self'.
61
61
if (CurDC->getParent ()->isLocalContext ()) {
62
- if (GenericParamCaptureLoc.isValid ())
63
- hasGenericParamCaptures = true ;
64
-
65
62
if (DynamicSelfCaptureLoc.isValid ())
66
63
dynamicSelfToRecord = DynamicSelf;
67
64
}
68
65
69
66
return CaptureInfo (Context, Captures, dynamicSelfToRecord, OpaqueValue,
70
- hasGenericParamCaptures);
67
+ HasGenericParamCaptures);
68
+ }
69
+
70
+ bool hasGenericParamCaptures () const {
71
+ return HasGenericParamCaptures;
71
72
}
72
73
73
74
SourceLoc getGenericParamCaptureLoc () const {
@@ -148,17 +149,19 @@ class FindCapturedVars : public ASTWalker {
148
149
if ((t->is <ArchetypeType>() ||
149
150
t->is <GenericTypeParamType>()) &&
150
151
!t->isOpenedExistential () &&
151
- GenericParamCaptureLoc. isInvalid () ) {
152
+ !HasGenericParamCaptures ) {
152
153
GenericParamCaptureLoc = loc;
154
+ HasGenericParamCaptures = true ;
153
155
}
154
156
}));
155
157
}
156
158
157
159
if (auto *gft = type->getAs <GenericFunctionType>()) {
158
160
TypeCaptureWalker walker (ObjC, [&](Type t) {
159
161
if (t->is <GenericTypeParamType>() &&
160
- GenericParamCaptureLoc. isInvalid () ) {
162
+ !HasGenericParamCaptures ) {
161
163
GenericParamCaptureLoc = loc;
164
+ HasGenericParamCaptures = true ;
162
165
}
163
166
});
164
167
@@ -339,9 +342,12 @@ class FindCapturedVars : public ASTWalker {
339
342
addCapture (CapturedValue (capture.getDecl (), Flags, capture.getLoc ()));
340
343
}
341
344
342
- if (GenericParamCaptureLoc. isInvalid ())
343
- if (captureInfo.hasGenericParamCaptures ())
345
+ if (!HasGenericParamCaptures) {
346
+ if (captureInfo.hasGenericParamCaptures ()) {
344
347
GenericParamCaptureLoc = loc;
348
+ HasGenericParamCaptures = true ;
349
+ }
350
+ }
345
351
346
352
if (DynamicSelfCaptureLoc.isInvalid ()) {
347
353
if (captureInfo.hasDynamicSelfCapture ()) {
@@ -631,7 +637,7 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
631
637
632
638
// Extensions of generic ObjC functions can't use generic parameters from
633
639
// their context.
634
- if (AFD && finder.getGenericParamCaptureLoc (). isValid ()) {
640
+ if (AFD && finder.hasGenericParamCaptures ()) {
635
641
if (auto Clas = AFD->getParent ()->getSelfClassDecl ()) {
636
642
if (Clas->usesObjCGenericsModel ()) {
637
643
AFD->diagnose (diag::objc_generic_extension_using_type_parameter);
0 commit comments