Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1703,9 +1703,14 @@ SynthesizeDefaultInitRequest::evaluate(Evaluator &evaluator,
ImplicitConstructorKind::DefaultDistributedActor :
ImplicitConstructorKind::Default;
if (auto ctor = createImplicitConstructor(decl, ctorKind, ctx)) {
if (auto isolation = decl->getDefaultActorIsolation()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a getDefaultActorIsolation method also I don't think we want a "default" here we want to match isolation of the type, that's the isolation we need to get.

/// Ensure the synthesized default initializer inherits the class's
/// default actor isolation (e.g., @MainActor) to avoid
/// override-isolation mismatches in subclasses.
ctor->setActorIsolation(isolation);
}
// Add the constructor.
decl->addMember(ctor);

// Lazily synthesize an empty body for the default constructor.
ctor->setBodySynthesizer(synthesizeSingleReturnFunctionBody);
return ctor;
Expand Down
7 changes: 7 additions & 0 deletions test/Concurrency/default_actor_isolation_initializer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature GlobalActorIsMainActor -enable-upcoming-feature RegionBasedIsolation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have GlobalActorIsMainActor, it's actually spelled as -default-isolation MainActor, also I don't think you need RegionBasedIsolation here either.

// expected-no-diagnostics

@MainActor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the main-actor mode is on by default, this annotation is not needed.

class Thing {}

class SubThing: Thing {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check SILGen output to make sure that initializers are isolated correctly, both initializers should be marked as MainActor in the output. I think you can move this to test/Concurrency/assume_mainactor.swift and add the checks there (it already checks for deinit).