@@ -146,6 +146,28 @@ const ParamDecl *getParamDeclFromOperand(SILValue value) {
146
146
return nullptr ;
147
147
}
148
148
149
+ bool isUseOfSelfInInitializer (Operand *oper) {
150
+ if (auto *PBI = dyn_cast<ProjectBoxInst>(oper->get ())) {
151
+ if (auto *MUI = dyn_cast<MarkUninitializedInst>(PBI->getOperand ())) {
152
+ switch (MUI->getKind ()) {
153
+ case MarkUninitializedInst::Kind::Var:
154
+ return false ;
155
+ case MarkUninitializedInst::Kind::RootSelf:
156
+ case MarkUninitializedInst::Kind::CrossModuleRootSelf:
157
+ case MarkUninitializedInst::Kind::DerivedSelf:
158
+ case MarkUninitializedInst::Kind::DerivedSelfOnly:
159
+ case MarkUninitializedInst::Kind::DelegatingSelf:
160
+ case MarkUninitializedInst::Kind::DelegatingSelfAllocated:
161
+ return true ;
162
+ }
163
+
164
+ llvm_unreachable (" Bad MarkUninitializedInst::Kind" );
165
+ }
166
+ }
167
+
168
+ return false ;
169
+ }
170
+
149
171
static bool checkForEscapingPartialApplyUses (PartialApplyInst *PAI) {
150
172
// Avoid exponential path exploration.
151
173
SmallVector<Operand *, 8 > uses;
@@ -301,14 +323,18 @@ static void checkPartialApply(ASTContext &Context, DeclContext *DC,
301
323
302
324
// First, diagnose the inout captures, if any.
303
325
for (auto inoutCapture : inoutCaptures) {
304
- auto *param = getParamDeclFromOperand (inoutCapture->get ());
305
- if (param->isSelfParameter ())
326
+ if (isUseOfSelfInInitializer (inoutCapture)) {
306
327
diagnose (Context, PAI->getLoc (), diag::escaping_mutable_self_capture);
307
- else {
308
- diagnose (Context, PAI->getLoc (), diag::escaping_inout_capture,
309
- param->getName ());
310
- diagnose (Context, param->getLoc (), diag::inout_param_defined_here,
311
- param->getName ());
328
+ } else {
329
+ auto *param = getParamDeclFromOperand (inoutCapture->get ());
330
+ if (param->isSelfParameter ())
331
+ diagnose (Context, PAI->getLoc (), diag::escaping_mutable_self_capture);
332
+ else {
333
+ diagnose (Context, PAI->getLoc (), diag::escaping_inout_capture,
334
+ param->getName ());
335
+ diagnose (Context, param->getLoc (), diag::inout_param_defined_here,
336
+ param->getName ());
337
+ }
312
338
}
313
339
314
340
diagnoseCaptureLoc (Context, DC, PAI, inoutCapture);
0 commit comments