File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -1041,9 +1041,9 @@ void TypeChecker::checkIgnoredExpr(Expr *E) {
1041
1041
return ;
1042
1042
}
1043
1043
1044
- // If the result of this expression is of type "()", then it is safe to
1045
- // ignore.
1046
- if (valueE->getType ()->isVoid () ||
1044
+ // If the result of this expression is of type "()" potentially wrapped in
1045
+ // optionals, then it is safe to ignore.
1046
+ if (valueE->getType ()->lookThroughAllAnyOptionalTypes ()-> isVoid () ||
1047
1047
valueE->getType ()->is <ErrorType>())
1048
1048
return ;
1049
1049
Original file line number Diff line number Diff line change @@ -822,3 +822,12 @@ func rdar24202058(a : Int) {
822
822
return a <= 480 // expected-error {{'<=' produces 'Bool', not the expected contextual result type '()'}}
823
823
}
824
824
825
+ // SR-1752: Warning about unused result with ternary operator
826
+
827
+ struct SR1752 {
828
+ func foo( ) { }
829
+ }
830
+
831
+ let sr1752 : SR1752 ? = nil
832
+
833
+ true ? nil : sr1752? . foo ( ) // don't generate a warning about unused result since foo returns Void
Original file line number Diff line number Diff line change @@ -110,11 +110,11 @@ let _: String = doubleOptional // expected-error {{cannot convert value of type
110
110
func maybeThrow( ) throws { }
111
111
try maybeThrow ( ) // okay
112
112
try ! maybeThrow ( ) // okay
113
- try ? maybeThrow ( ) // expected-warning {{result of 'try?' is unused}}
113
+ try ? maybeThrow ( ) // okay since return type of maybeThrow is Void
114
114
_ = try ? maybeThrow ( ) // okay
115
115
116
116
let _: ( ) -> Void = { try ! maybeThrow ( ) } // okay
117
- let _: ( ) -> Void = { try ? maybeThrow ( ) } // expected-warning {{result of 'try?' is unused}}
117
+ let _: ( ) -> Void = { try ? maybeThrow ( ) } // okay since return type of maybeThrow is Void
118
118
119
119
120
120
if try ? maybeThrow ( ) { // expected-error {{cannot be used as a boolean}} {{4-4=((}} {{21-21=) != nil)}}
You can’t perform that action at this time.
0 commit comments