Skip to content

Swift compiler emits an undefined stored-property initialization symbol for split-file init accessors #91700

Description

@Brett-Best

Description

This is a follow-up to #89823, my earlier report of the same general FlagTextField / @State / split-file initializer shape. #89823 was closed as fixed by #89653 ("SILGen: laziness fixes for properties defined in secondary files"). That fix removes the SILGen crash, but the reduced case below still produces a final linker failure.

The library compilation succeeds. Linking a separate client fails because the initializer emitted from the secondary file references a missing stored-property initialization symbol.

Reproduction

These are the complete three source files. They use no SwiftUI or SwiftPM; the first two form a static library and the third is a separate client.

Library.swift:

struct FlagTextField {
    private var __cachedText = 0
    var required: Bool

    private var cachedText: String? {
        @storageRestrictions(initializes: __cachedText)
        init {
            __cachedText = 0
        }
        get { nil }
        set {}
    }
}

public func trigger() {
    _ = FlagTextField()
}

Initializers.swift:

extension FlagTextField {
    init() {
        required = true
    }
}

main.swift:

import ReproLibrary

trigger()

Run these commands with Xcode 27 selected. They do not invoke SwiftPM and do not provide an SDK or target triple:

mkdir -p /tmp/Xcode27LinkerReproSwiftc
SWIFTC_REPRO_DIR=/tmp/Xcode27LinkerReproSwiftc

swiftc \
  -module-name ReproLibrary \
  -emit-library -static \
  -emit-module \
  -emit-module-path "$SWIFTC_REPRO_DIR/ReproLibrary.swiftmodule" \
  -o "$SWIFTC_REPRO_DIR/libReproLibrary.a" \
  Library.swift \
  Initializers.swift

swiftc \
  -I "$SWIFTC_REPRO_DIR" \
  -L "$SWIFTC_REPRO_DIR" \
  -lReproLibrary \
  -module-name ReproApp \
  -o "$SWIFTC_REPRO_DIR/ReproApp" \
  main.swift

The first command succeeds. The second fails with an undefined symbol for the __cachedText initialization expression.

Expected behavior

The client should link successfully. Putting the initializer in the same source file as FlagTextField makes the link succeed.

Environment

  • Xcode 27.0 beta 6, build 27A5252f
  • Apple Swift version 6.4 (swiftlang-6.4.0.33.1 clang-2100.3.33.1)
  • macOS 27.0, arm64
  • 6.4.x-snapshot-2026-08-14: Swift 6.4-dev (LLVM a157c5eb1c32510, Swift 424cae5)
  • main-snapshot-2026-08-21: Swift 6.5-dev (LLVM 64c3046d94ae7cc, Swift 95c5142)

The failure reproduces with the Xcode 27 toolchain, the latest 6.4.x snapshot, and the latest main snapshot tested on 2026-08-25.

Additional information

The original source-faithful case is FlagTextField from Vexil PR #155, with @State private var cachedText: String? and convenience initializers in secondary files. In that form, changing a secondary-file initializer from self = Self(...) to self.init(...) is the workaround. This report is a follow-up to #89823 and the SILGen fix in #89653:

The Xcode 27 @State macro expansion contains a private __cachedText storage property and an accessor with @storageRestrictions(initializes: __cachedText). The no-import reproduction above is a further reduction of that expansion. It shows that LazyState, its generic parameter, the @State wrapper, View, EmptyView, and SwiftUI are not required to expose the linker failure. Neither the storage accessor nor the split-file initializer needs a parameter. The required property only prevents a synthesized FlagTextField.init() so that the secondary-file initializer can remain parameterless; it is not otherwise used by the trigger.

Observed result by toolchain

The two-stage commands above were run separately with each of the following toolchains. The library compilation succeeded in all three cases; the client link failed in all three cases.

Xcode-selected Swift 6.4 (Xcode 27.0 beta 6, build 27A5252f; swiftlang-6.4.0.33.1):

error: link command failed with exit code 1
Undefined symbols for architecture arm64:
  "variable initialization expression of ReproLibrary.FlagTextField.(__cachedText ...): Swift.Int"
ld: symbol(s) not found for architecture arm64

Latest 6.4.x snapshot 6.4.x-snapshot-2026-08-14 (Swift 6.4-dev, LLVM a157c5eb1c32510, Swift 424cae5):

error: link command failed with exit code 1
Undefined symbols for architecture arm64:
  "variable initialization expression of ReproLibrary.FlagTextField.(__cachedText ...): Swift.Int"
ld: symbol(s) not found for architecture arm64

Latest main snapshot main-snapshot-2026-08-21 (Swift 6.5-dev, LLVM 64c3046d94ae7cc, Swift 95c5142):

error: link command failed with exit code 1
Undefined symbols for architecture arm64:
  "variable initialization expression of ReproLibrary.FlagTextField.(__cachedText ...): Swift.Int"
ld: symbol(s) not found for architecture arm64

The fatal linker diagnostic is the same across these three toolchains; the compiler identities and independently reproduced command paths are recorded above.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions