@@ -349,21 +349,31 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
349
349
// initializers apply Sendable checking to arguments at the call-site,
350
350
// and actor initializers do not run on the actor, so initial values
351
351
// cannot be actor-instance-isolated.
352
- bool shouldAddNonisolated = true ;
353
352
ActorIsolation existingIsolation = getActorIsolation (decl);
354
353
VarDecl *previousVar = nullptr ;
354
+ bool hasError = false ;
355
355
356
- for (auto member : decl->getImplementationContext ()->getAllMembers ()) {
357
- bool hasError = false ;
358
- auto pbd = dyn_cast<PatternBindingDecl>(member);
359
- if (!pbd || pbd->isStatic ())
360
- continue ;
356
+ // FIXME: Calling `getAllMembers` here causes issues for conformance
357
+ // synthesis to RawRepresentable and friends. Instead, iterate over
358
+ // both the stored properties and the init accessor properties, as
359
+ // those can participate in implicit initializers.
361
360
362
- for (auto i : range (pbd->getNumPatternEntries ())) {
363
- if (pbd->isInitializerSubsumed (i))
361
+ auto stored = decl->getStoredProperties ();
362
+ auto initAccessor = decl->getInitAccessorProperties ();
363
+
364
+ auto shouldAddNonisolated = [&](ArrayRef<VarDecl *> properties) {
365
+ if (hasError)
366
+ return false ;
367
+
368
+ bool addNonisolated = true ;
369
+ for (auto *var : properties) {
370
+ auto *pbd = var->getParentPatternBinding ();
371
+ if (!pbd)
364
372
continue ;
365
373
366
- auto *var = pbd->getAnchoringVarDecl (i);
374
+ auto i = pbd->getPatternEntryIndexForVarDecl (var);
375
+ if (pbd->isInitializerSubsumed (i))
376
+ continue ;
367
377
368
378
ActorIsolation initIsolation;
369
379
if (var->hasInitAccessor ()) {
@@ -400,21 +410,21 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
400
410
var->getDescriptiveKind (),
401
411
var->getName (), isolation);
402
412
hasError = true ;
403
- break ;
413
+ return false ;
404
414
}
405
415
406
416
existingIsolation = isolation;
407
417
previousVar = var;
408
- shouldAddNonisolated = false ;
418
+ addNonisolated = false ;
409
419
}
410
420
}
411
421
}
412
422
413
- if (hasError)
414
- break ;
415
- }
423
+ return addNonisolated;
424
+ };
416
425
417
- if (shouldAddNonisolated) {
426
+ if (shouldAddNonisolated (stored) &&
427
+ shouldAddNonisolated (initAccessor)) {
418
428
addNonIsolatedToSynthesized (decl, ctor);
419
429
}
420
430
}
0 commit comments