Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14951] diag::witness_unavailable should include the message string from the @available attribute if present #57293

Closed
beccadax opened this issue Jul 21, 2021 · 6 comments

Comments

@beccadax
Copy link
Contributor

@beccadax beccadax commented Jul 21, 2021

Previous ID SR-14951
Radar None
Original Reporter @beccadax
Type Improvement
Status Closed
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee Rajagopalan (JIRA)
Priority Medium

md5: 847db0d4ebc811926f2c7650cf658dc0

Issue Description:

Given this code:

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
@beccadax
Copy link
Contributor Author

@beccadax beccadax commented Jul 21, 2021

Tips for a new contributor:

  • 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.

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jul 23, 2021

Comment by Rajagopalan Gangadharan (JIRA)

Hello @beccadax ![]( I'm new to swift, looking to make some contributions. It would be awesome if I can take this. Thanks)

Edit: I have setup my dev env and started working with the info provided above, as I find it very interesting.

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jul 27, 2021

Comment by Rajagopalan Gangadharan (JIRA)

@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?

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jul 27, 2021

Comment by Rajagopalan Gangadharan (JIRA)

My bad I'm highlighting wrong source loc instead of unavailable function.

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jul 27, 2021

Comment by Rajagopalan Gangadharan (JIRA)

Ok I figured out what to do to get the directed output. Will make a PR soon!

cc: wongzigii (JIRA User) @beccadax

Edit The final output:

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jul 28, 2021

Comment by Rajagopalan Gangadharan (JIRA)

Can you guys please review : #38662

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants