Skip to content
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

Strict Concurrency warning false positive: MainActor isolated KeyPath #72181

Closed
tcldr opened this issue Mar 8, 2024 · 9 comments · Fixed by #75091
Closed

Strict Concurrency warning false positive: MainActor isolated KeyPath #72181

tcldr opened this issue Mar 8, 2024 · 9 comments · Fixed by #75091
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features

Comments

@tcldr
Copy link

tcldr commented Mar 8, 2024

Description

When declaring a property wrapper on a MainActor isolated type that takes a MainActor isolated KeyPath, the 5.10 compiler flags a concurrency warning: 'Cannot form key path to main actor-isolated property 'requestReview'; this is an error in Swift 6'

Reproduction

import StoreKit

@MainActor
struct MyView: View {
  // Cannot form key path to main actor-isolated property 'requestReview'; this is an error in Swift 6
  @Environment(\.requestReview) private var requestReview

  var body: some View {
    Text("Cannot form key path to main actor-isolated property")
  }
}

Expected behavior

No warning.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

First flagged here: https://forums.swift.org/t/swift-5-10-concurrency-and-xctest/69929/11

@tcldr tcldr added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 8, 2024
@tcldr tcldr changed the title Strict Concurrency: MainActor isolated KeyPath warning False Positive Strict Concurrency warning false positive: MainActor isolated KeyPath Mar 8, 2024
@wmorgue
Copy link

wmorgue commented Jun 11, 2024

Xcode 16 still has this 🐞
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0

@NachoSoto
Copy link
Contributor

Filed as #74636 too

@NachoSoto
Copy link
Contributor

Filed 4 months ago and still unfixed in Swift 6. Meaning you can't use this environment variable while compiling with Swift 6.

@radude89
Copy link

radude89 commented Jul 5, 2024

Are there any workarounds available?

@hborla hborla added concurrency Feature: umbrella label for concurrency language features and removed triage needed This issue needs more specific labels labels Jul 7, 2024
@hborla
Copy link
Member

hborla commented Jul 7, 2024

Sorry I missed this - if that happens again, please feel free to add the concurrency label yourself, after which it'll get added to my queue of concurrency issues to montior/triage/fix.

@hborla
Copy link
Member

hborla commented Jul 7, 2024

@xedin I think isolated key paths need to understand isolated default values. This code is valid because var requestReview, and thus its initial value, are isolated to the main actor.

@hborla
Copy link
Member

hborla commented Jul 7, 2024

Are there any workarounds available?

You should be able to work around this by initializing the property wrapper in a @MainActor-isolated initializer, like this

import SwiftUI
import StoreKit

@MainActor
struct MyView: View {
  @Environment private var requestReview: RequestReviewAction

  init() {
    self._requestReview = Environment(\.requestReview)
  }

  var body: some View { ... }
}

@NachoSoto
Copy link
Contributor

NachoSoto commented Jul 7, 2024

@hborla I appreciate that, but as an external contributor I'm not allowed to add labels to issues I file unfortunately.

@hborla
Copy link
Member

hborla commented Jul 10, 2024

@hborla I appreciate that, but as an external contributor I'm not allowed to add labels to issues I file unfortunately.

That is annoying! I didn't realize that. It's fine to tag me and I can triage the issue directly. I'm also looking to put a process in place to fill the gaps in issue triage, as I know this isn't the first time an issue has been missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features
Projects
None yet
5 participants