Files
swift-mirror/test/Concurrency/transfernonsendable_library_evolution.swift
Michael Gottesman 591a11026d [sil] Use VarDecl's initializer isolation for stored property initializer SILFunctions.
Previously (0a60c93ca5), we fixed an issue where variable initializer
expressions would inherit isolation from their containing type rather than from
their property declaration. For example, in:

    @MainActor struct S {
      @CustomActor var x = NS()
      nonisolated init() {}
    }

the variable initializer SILFunction for `x` would be @MainActor isolated
instead of @CustomActor isolated, causing spurious RBI errors.

That fix made the variable initializer SILFunction adopt the VarDecl's own
actor isolation when explicitly specified. However, this broke cases involving
library evolution with default argument generators:

    @MainActor struct DefaultArgumentInitializerTest<T> {
      var strategy: NonSendableEnum = .case1
    }

Here the default argument generator is nonisolated (matching the initializer),
but it calls the variable initializer expression which was now @MainActor
isolated — producing a legitimate merge error in RBI.

Fix this by using `VarDecl::getInitializerIsolation()` instead of the VarDecl's
own actor isolation. This ensures both the variable initializer expression
SILFunction and any default argument generator match the initializer's isolation.
This is correct because:

1. If the initializer expression is nonisolated from an effects perspective, it
   returns a disconnected value that can be stored into actor-isolated storage.

2. If the initializer expression is actor-isolated, the storage must match that
   isolation, and only matching-isolation initializers can invoke it.

rdar://173530121
2026-03-28 14:28:01 -07:00

27 lines
530 B
Swift

// RUN: %target-swift-frontend -primary-file %s -swift-version 6 -enable-library-evolution -verify -c
////////////////////////
// MARK: Declarations //
////////////////////////
class NonSendableKlass {}
struct NonSendable<T> {
var x: T? = nil
}
public enum NonSendableEnum {
case case1
case case2
}
/////////////////
// MARK: Tests //
/////////////////
@MainActor struct DefaultArgumentInitializerTest<T> {
var strategy: NonSendableEnum = .case1
var strategy2 = NonSendable<T>()
var strategy3 = NonSendableKlass()
}