Skip to content

Commit 26831c6

Browse files
Merge pull request #36455 from kthchew/SR-14270
Add test case for rethrows functions with defaulted throwable argument functions
2 parents b534552 + 289840b commit 26831c6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/decl/func/rethrows.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,19 @@ func rdar_47550715() {
612612
func foo(_: A<F>? = nil) {} // Ok
613613
func bar(_: A<F>? = .none) {} // Ok
614614
}
615+
616+
// SR-14270 - test case for diagnostic note 'because_rethrows_default_argument_throws'
617+
func nonThrowableDefaultRethrows(_ f: () throws -> () = {}) rethrows {
618+
try f()
619+
}
620+
// NOTE: This should compile and not emit a diagnostic because ideally the compiler could statically
621+
// know the default argument value could never throw. See SR-1524.
622+
nonThrowableDefaultRethrows() // expected-error {{call can throw but is not marked with 'try'}}
623+
// expected-note@-1 {{call is to 'rethrows' function, but a defaulted argument function can throw}}
624+
625+
func throwableDefaultRethrows(_ f: () throws -> () = { throw SomeError.Badness }) rethrows {
626+
try f()
627+
}
628+
// This should always emit a diagnostic because we can statically know that default argument can throw.
629+
throwableDefaultRethrows() // expected-error {{call can throw but is not marked with 'try'}}
630+
// expected-note@-1 {{call is to 'rethrows' function, but a defaulted argument function can throw}}

0 commit comments

Comments
 (0)