swiftlang/swift

Bad diagnostic about memberwise `init` not being public

開放

#78,362 建立於 2024年12月24日

 (21 則留言) (0 個反應) (1 位負責人)Swift (10,719 個分叉)batch import
access controlcompilerconformancesdiagnostics qualityfix-itsgood first issuememberwise initswift 6.2type checker

倉庫指標

星標
 (69,989 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Description

No response

Reproduction

public struct Number: RawRepresentable {
  public let rawValue: Int
}
398 | public struct Number: RawRepresentable {
    |               `- error: initializer 'init(rawValue:)' must be declared public because it matches a requirement in public protocol 'RawRepresentable' [witness_not_accessible_proto]
399 |   public let rawValue: Int
400 | }

Expected behavior

This diagnostic is not great:

  1. What initializer? (The implicit memberwise initializer).
  2. How do I or can I at all declare it public? (An implicit memberwise initializer cannot be public).
  3. What should I do to make this work? (Declare an explicit initializer + fix-it).

Environment

Swift version 6.2-dev (LLVM 1a588e5b044c46f, Swift 55189bae8e55169)

Additional information

No response

貢獻者指南