Skip to content

Impossible to extend macro-generated type with public memberwise initializer #90519

Description

@stephencelis

Description

An existing diagnostic prevents you from defining a public memberwise initializer for a type in an extension:

invalid redeclaration of synthesized memberwise 'init'

…but this is the only reasonable way to do so for a type generated by a macro.

Six years ago a suggestion was made on the forums that same-file extensions should be able to define memberwise initializers: https://forums.swift.org/t/why-doesn-t-an-init-in-an-extension-suppress-the-synthesized-init/35182/ It didn't get traction but it also didn't have pushback.

This limitation seems more relevant than ever with macros now in the language.

Reproduction

public struct A {
}

extension A {
  public init() {}  // 🛑
}

Expected behavior

I expect a same-file extension to be able to define the memberwise initializer publicly.

Environment

swift-driver version: 1.168.4 Apple Swift version 6.4 (swiftlang-6.4.0.25.4 clang-2100.3.25.1)
Target: arm64-apple-macosx26.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerThe Swift compiler itselfswift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposaltype checkerArea → compiler: Semantic analysis

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions