Skip to content

Add test case for rethrows functions with defaulted throwable argument functions #36455

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

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/decl/func/rethrows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,19 @@ func rdar_47550715() {
func foo(_: A<F>? = nil) {} // Ok
func bar(_: A<F>? = .none) {} // Ok
}

// SR-14270 - test case for diagnostic note 'because_rethrows_default_argument_throws'
func nonThrowableDefaultRethrows(_ f: () throws -> () = {}) rethrows {
try f()
}
// NOTE: This should compile and not emit a diagnostic because ideally the compiler could statically
// know the default argument value could never throw. See SR-1524.
nonThrowableDefaultRethrows() // expected-error {{call can throw but is not marked with 'try'}}
// expected-note@-1 {{call is to 'rethrows' function, but a defaulted argument function can throw}}

func throwableDefaultRethrows(_ f: () throws -> () = { throw SomeError.Badness }) rethrows {
try f()
}
// This should always emit a diagnostic because we can statically know that default argument can throw.
throwableDefaultRethrows() // expected-error {{call can throw but is not marked with 'try'}}
// expected-note@-1 {{call is to 'rethrows' function, but a defaulted argument function can throw}}