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-1534] Error: Call is to rethrows function, but a defaulted argument function can throw #44143

Open
swift-ci opened this issue May 16, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1534
Radar rdar://problem/40036643
Original Reporter bhargavg (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 3
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: c87cab07c58e67b6d6876c244ca8b69f

is duplicated by:

  • SR-2979 'rethrows' function with non-throwing default requires 'try'
  • SR-7611 Incorrect compiler error to mark try for not throwing function
  • SR-12109 Invalid "call can throw"-error related to default argument of closure type
  • SR-12389 A non-throwing default argument will require try at call site
  • SR-15854 Compiler thinks function closure parameter default value "throws" when it's not

relates to:

  • SR-14270 Add test case for diagnostic note 'because_rethrows_default_argument_throws'

Issue Description:

The following code doesn't work

func foo(f: () throws -> () = {}) rethrows {
    try f()
}

// Fine
foo({ })

// This fails with error:
//    call is to 'rethrows' function,
//    but a defaulted argument function can throw
foo()
@belkadan
Copy link
Contributor

belkadan commented May 7, 2018

Now that default arguments are always emitted into the client, it'd be correct to fix this…but the warning happens in Sema, before we've looked at what the default argument value is. Maybe we should record the type of the default argument before coercion or something?

@swift-ci create

@NevinBR
Copy link
Contributor

NevinBR commented Jul 11, 2020

I just ran into this today. I wrote a method like this:

extension Sequence where Element: BinaryInteger {
  func checksum(using f: (Element,Element)throws->Element = (^)) rethrows -> Element {
    return try self.reduce(0){ try f($0, $1) }
  }
}

And I wanted to call it like this:

extension Sequence {
  func checksum(transform: (Element)->Int) -> Int {
    self.lazy.map(transform).checksum()
    // error: Call can throw but is not marked with 'try'
  }
}

But that code does not compile, so I had to include the xor operator as an argument anyway.

Is there an expected timeline for when this might get fixed?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants