Skip to content

[Concurrency] Fix a false-positive metatype capture diagnostic. #81860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2025

Conversation

hborla
Copy link
Member

@hborla hborla commented May 30, 2025

Don't diagnose metatype captures in closures that are isolated to the same actor as the enclosing context, because the metatype is not used concurrently. For example, the following code is safe even if the conformance to P is isolated because T never crosses an isolation boundary:

protocol P {}

func acceptClosure(_: () -> Void) {}

@MainActor
func f<T: P>(_: T.Type) {
  acceptClosure {
    Task {
      _ = T.self // okay to capture T.Type in this closure.
    }
  }
}

This code is no longer used given that region isolation is always enabled
along with strict concurrency checking.
@hborla
Copy link
Member Author

hborla commented May 30, 2025

@swift-ci please smoke test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM

isolated to the same actor as the enclosing context.
@hborla hborla force-pushed the isolated-capture-fixes branch from a492ccc to f0e77c7 Compare May 30, 2025 17:58
@hborla
Copy link
Member Author

hborla commented May 30, 2025

@swift-ci please smoke test

@hborla hborla merged commit 214b8d8 into swiftlang:main May 30, 2025
3 checks passed
@hborla hborla deleted the isolated-capture-fixes branch May 31, 2025 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants