Skip to content

Incorrect compilation error when using actor initializer with @preconcurrency import #82178

Open
@igor-makarov

Description

@igor-makarov

Description

When importing a library, with @preconcurrency directive, the intended effect is to suppress sendability errors and treat all types as if they were sendable.

In Swift 6.2 on Xcode 26 beta 1, there's a compilation error when using generics that was not present before. I believe this error is not correct, since similar non-generic code still compiles. I've attached sample code of both.

Reproduction

@preconcurrency import Combine
typealias UnsafeType = PassthroughSubject<Void, Never>

actor FooGeneric<Inner: Sendable> {
    init() {}
    private var inner: Inner?
}

actor FooOk {
    init() {}
    private var unsafe = UnsafeType()
}

struct Bar: Sendable {
    let foo = FooGeneric<String>() // ok
    let fooType = UnsafeType() // ok
    let fooOk = FooOk() // ok
    let fooError = FooGeneric<UnsafeType>() // ❌ Non-Sendable 'FooGeneric<UnsafeType>' (aka 'FooGeneric<PassthroughSubject<(), Never>>')-typed result can not be returned from actor-isolated initializer 'init()' to nonisolated context
}

Expected behavior

Code compiles.

Environment

swift-driver version: 1.127.4.2 Apple Swift version 6.2 (swiftlang-6.2.0.9.909 clang-1700.3.9.907)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions