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-14270] Add test case for diagnostic note 'because_rethrows_default_argument_throws' #56630

Closed
typesanitizer opened this issue Feb 24, 2021 · 7 comments
Labels
compiler The Swift compiler in itself good first issue Good for newcomers task

Comments

@typesanitizer
Copy link

Previous ID SR-14270
Radar rdar://problem/74705982
Original Reporter @typesanitizer
Type Task
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Task, StarterBug
Assignee kthchew (JIRA)
Priority Medium

md5: 083b76192dd95f0bbee3ed778bd3fc85

relates to:

  • SR-1534 Error: Call is to rethrows function, but a defaulted argument function can throw

Issue Description:

This diagnostic does have some code, but from what I can tell, it has no associated test cases. We should at least have 1 test case so it is clearer when exactly this diagnostic is emitted.

@typesanitizer
Copy link
Author

@swift-ci create

@typesanitizer
Copy link
Author

Here is an example test case:

func f(_ k: () throws -> () = { }) rethrows {
  try k()
}
let x = f()

I think this should be added alongside related tests on diagnostics for rethrows.

@typesanitizer
Copy link
Author

It seems like this diagnostic is a stop-gap until we fix the problem.

@swift-ci
Copy link
Collaborator

Comment by Kenneth Chew (JIRA)

For clarification, there should not be any expected error and diagnostic here, correct? The error that shows up ("Call is to rethrows function, but a defaulted argument function can throw") should not appear? This seems to be what I gather from looking through SR-1534. Meanwhile something like

func x(_ f: () throws -> () = { throw SomeError.Badness }) rethrows {
  try f()
}
x()

should have the error and diagnostic?

@typesanitizer
Copy link
Author

For clarification, there should not be any expected error and diagnostic here, correct? The error that shows up ("Call is to rethrows function, but a defaulted argument function can throw") should not appear?

In an ideal world where SR-1534 is fixed, yes. However, I think that fixing SR-1534 is probably complicated and beyond the scope of a StarterBug. The task in this bug report is to add the test case along with the diagnostic to "pin down" the compiler's behavior today; in case someone else tries to understand when that diagnostic is emitted, they can take a look at the test case. If/When someone fixes SR-1534 in the future, they can change this test case from "error" to "works okay". So you can add two test cases like so:

// Should continue to emit an error after SR-1534 is fixed.
func f1(_ k: () throws -> () = { throw SomeError.Badness }) rethrows {
  // expected-error@-1{{ blah }}
  try k()
}
f1()

// Once SR-1534 is fixed, this code should compile instead of emitting an error.
func f2(_ k: () throws -> () = { }) rethrows {
  // expected-error@-1{{ blah }}
  try k()
}
f2()

Does that help?

@swift-ci
Copy link
Collaborator

Comment by Kenneth Chew (JIRA)

Yes, that's very helpful, thank you! I made a PR at #36455 - could you look at it when you get a chance, please?

@swift-ci
Copy link
Collaborator

Comment by Kenneth Chew (JIRA)

Added in #36455

@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
Labels
compiler The Swift compiler in itself good first issue Good for newcomers task
Projects
None yet
Development

No branches or pull requests

2 participants