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