File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -612,3 +612,19 @@ func rdar_47550715() {
612
612
func foo( _: A < F > ? = nil ) { } // Ok
613
613
func bar( _: A < F > ? = . none) { } // Ok
614
614
}
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}}
You can’t perform that action at this time.
0 commit comments