Repository navigation
Conversation
In Swift 6 language mode, non-escaping closures automatically inherit the caller's actor isolation. This resolves the type mismatch error when using then/with/do with @MainActor-isolated types such as UIKit classes. Closes #106
|
I restarted before I could confirm a reply to your earlier request. I didn't rerun it automatically — please ask again if you still need it. |
There was a problem hiding this comment.
The core fix needs a regression test covering the function-value conversion reported in #106; the added inline-closure tests do not establish it. GitHub CI passes on all four platforms at 3b2f791, but local compiler/build execution was unavailable during this review.
Out-of-diff findings moved from inline comments:
- Tests/ThenTests/ThenTests.swift:81 (RIGHT): The new tests exercise closure-literal isolation inheritance rather than the actor-qualified method-reference conversion this PR claims to fix.
The test uses MyView().then { $0.title = "hello" }, whereas #106 reports UIStackView().then($0.addSubview) losing MainActor during function-value conversion. Closure inheritance predates Swift 6: SE-0306 states that a non-@Sendable closure formed within an actor-isolated context is actor-isolated. All three public callback signatures remain unchanged, so these tests do not demonstrate why changing the library's language mode resolves the reported error.
Add a Swift 6 consumer regression using the reported method-reference form and its enclosing isolation context. Compile it against the separately built base and head library to demonstrate failure before and success after; if both behave identically, revise the proposed fix and rationale before dropping Swift 5 toolchain support.
Summary
Fix the Swift 6 strict concurrency error when using
then/with/dowith@MainActor-isolated types such as UIKit classes.Closes #106
Problem
In Swift 6 strict concurrency, calling
thenon a@MainActor-isolated type likeUIStackViewproduces:This happens because the library was compiled with
swift-tools-version:5.0(Swift 5 language mode), where non-escaping closures do not inherit the caller's actor isolation.Changes
Package.swift
swift-tools-versionfrom5.0to6.0. In Swift 6 language mode, non-escaping closure parameters automatically inherit the caller's actor isolation — no API changes needed.Tests
@MainActor-annotated tests validating thatthen,with, anddocompile and behave correctly with@MainActor-isolated types.Context
swift-tools-version:6.0requires Swift 6 tooling.Testing
testThen_MainActorIsolated,testWith_MainActorIsolated,testDo_MainActorIsolated) verify the fix.Summary by cubic
Fixes Swift 6 strict concurrency errors when calling
then/with/doon@MainActor-isolated types by buildingThenin Swift 6 mode. Also updates minimum platform versions, adds@MainActortests, and sets TuistSWIFT_VERSIONto 6.0.swift-tools-version: 6.0).Thenrelease.Written for commit 3b2f791. Summary will update on new commits.