swift: Bad diagnostic about memberwise `init` not being public
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:
- What initializer? (The implicit memberwise initializer).
- How do I or can I at all declare it public? (An implicit memberwise initializer cannot be public).
- 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
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 21 (1 by maintainers)
I am still working on the issue and very close to getting the fix.
The first two things I think you should check off the list when dealing with issues that require code changes are:
Then you know the issue is still relevant and are equipped to start debugging. In this case, you can start off by using the
-debug-diagnostic-namesflag to show the IDs of emitted diagnostics, and locate both their definition and emission sites in the codebase. For understanding diagnostic templates and how to write and test diagnostics, refer to Diagnostics.md.it can be a little tricky at first to reverse lookup the source from the diagnostic text because many of them are string ‘templates’ and the nouns & adjectives get substituted in. in this case the relevant diagnostic message is likely this one. you can then use the diagnostic ID (
type_witness_not_accessible_protoin this case) to better determine where the relevant callsites for addressing this issue are.