Skip to content

Commit 289840b

Browse files
committed
Add test case for diagnostic 'because_rethrows_default_argument_throws'
The first test case added ideally shouldn't have any expected error or diagnostic. However, due to SR-1534, there is an error emitted here. Thus, an expected error is used here to show the compiler's behavior today. If SR-1534 is fixed in the future, the first test case should no longer have any expected error nor an expected note. However, the second test case should still be left alone. Addresses SR-14270
1 parent 5871025 commit 289840b

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)