@@ -336,13 +336,64 @@ static ConstructorDecl *createImplicitConstructor(NominalTypeDecl *decl,
336336 ctor->setSynthesized ();
337337 ctor->setAccess (accessLevel);
338338
339+ if (ctx.LangOpts .hasFeature (Feature::IsolatedDefaultValues)) {
340+ // If any of the type's actor-isolated properties:
341+ // 1. Have non-Sendable type, or
342+ // 2. Have an isolated initial value
343+ // then the initializer must also be actor-isolated. If all
344+ // isolated properties have Sendable type and a nonisolated
345+ // default value, then the initializer can be nonisolated.
346+ //
347+ // These rules only apply for global actor isolation, because actor
348+ // initializers apply Sendable checking to arguments at the call-site,
349+ // and actor initializers do not run on the actor, so initial values
350+ // cannot be actor-instance-isolated.
351+ bool shouldAddNonisolated = true ;
352+ llvm::Optional<ActorIsolation> existingIsolation = llvm::None;
353+ VarDecl *previousVar = nullptr ;
354+
355+ // The memberwise init properties are also effectively what the
356+ // default init uses, e.g. default initializers initialize via
357+ // properties wrapped and init accessors.
358+ for (auto var : decl->getMemberwiseInitProperties ()) {
359+ auto type = var->getTypeInContext ();
360+ auto isolation = getActorIsolation (var);
361+ if (isolation.isGlobalActor ()) {
362+ if (!isSendableType (decl->getModuleContext (), type) ||
363+ var->getInitializerIsolation ().isGlobalActor ()) {
364+ // If different isolated stored properties require different
365+ // global actors, it is impossible to initialize this type.
366+ if (existingIsolation &&
367+ *existingIsolation != isolation) {
368+ ctx.Diags .diagnose (decl->getLoc (),
369+ diag::conflicting_stored_property_isolation,
370+ ICK == ImplicitConstructorKind::Memberwise,
371+ decl->getDeclaredType (), *existingIsolation, isolation);
372+ previousVar->diagnose (
373+ diag::property_requires_actor,
374+ previousVar->getDescriptiveKind (),
375+ previousVar->getName (), *existingIsolation);
376+ var->diagnose (
377+ diag::property_requires_actor,
378+ var->getDescriptiveKind (),
379+ var->getName (), isolation);
380+ }
381+
382+ existingIsolation = isolation;
383+ previousVar = var;
384+ shouldAddNonisolated = false ;
385+ }
386+ }
387+ }
388+
389+ if (shouldAddNonisolated) {
390+ addNonIsolatedToSynthesized (decl, ctor);
391+ }
392+ }
393+
339394 if (ICK == ImplicitConstructorKind::Memberwise) {
340395 ctor->setIsMemberwiseInitializer ();
341396
342- // FIXME: If 'IsolatedDefaultValues' is enabled, the memberwise init
343- // should be 'nonisolated' if none of the memberwise-initialized properties
344- // are global actor isolated and have non-Sendable type, and none of the
345- // initial values require global actor isolation.
346397 if (!ctx.LangOpts .hasFeature (Feature::IsolatedDefaultValues)) {
347398 addNonIsolatedToSynthesized (decl, ctor);
348399 }
0 commit comments