protocol P {
associatedtype T
func req()
}
extension P {
func req() {}
}
extension P where T == Self {
@available(*, unavailable, message: "write it yourself") func req() {}
}
struct NonSelfT: P {
typealias T = Int
}
struct SelfT: P {
typealias T = SelfT
}
We produce this output:
<stdin>:15:8: error: type 'SelfT' does not conform to protocol 'P'
struct SelfT: P {
^
<stdin>:15:8: error: unavailable instance method 'req()' was used to satisfy a requirement of protocol 'P'
struct SelfT: P {
^
<stdin>:9:65: note: 'req()' declared here
@available(*, unavailable, message: "write it yourself") func req() {}
^
<stdin>:3:8: note: requirement 'req()' declared here
func req()
^
Note that “write it yourself” does not appear in any of the diagnostics, and we wouldn’t see it at all if @available hadn’t been on the same line. It should probably appear in the second diagnostic, perhaps like this:
<stdin>:15:8: error: unavailable instance method 'req()' was used to satisfy a requirement of protocol ‘P’: write it yourself
The text was updated successfully, but these errors were encountered:
The diagnostic in question is called witness_unavailable; you can see where it's defined and emitted by searching the Swift repository for that string.
To understand what you might need to do, search the code base for availability_decl_unavailable, the diagnostic we use for @available(*, unavailable) in most other scenarios, and look at we're handling the Message member of AvailableAttr. The use site in ExprAvailabilityWalker::diagnoseMemoryLayoutMigration() is particularly straightforward in this respect—the others have complications you won't need to worry about.
If you're new to Swift, the documentation in docs/Diagnostics.md will give you some useful background on how to specify diagnostic messages.
@beccadax I was able to get the compiler diagnostics for unavailability. This is the output I get for running the above program. Can you please take a look and let me know if output should be changed?
Attachment: Download
Additional Detail from JIRA
md5: 847db0d4ebc811926f2c7650cf658dc0
Issue Description:
Given this code:
We produce this output:
Note that “write it yourself” does not appear in any of the diagnostics, and we wouldn’t see it at all if @available hadn’t been on the same line. It should probably appear in the second diagnostic, perhaps like this:
The text was updated successfully, but these errors were encountered: