File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
validation-test/Sema/type_checker_crashers_fixed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -7677,8 +7677,11 @@ bool CoercibleOptionalCheckedCastFailure::diagnoseForcedCastExpr() const {
7677
7677
7678
7678
bool isBridged = CastKind == CheckedCastKind::BridgingCoercion;
7679
7679
if (isCastTypeIUO ()) {
7680
- toType = toType->getOptionalObjectType ();
7681
- extraFromOptionals++;
7680
+ // IUO type could either be optional or unwrapped.
7681
+ if (auto objType = toType->getOptionalObjectType ()) {
7682
+ extraFromOptionals++;
7683
+ toType = objType;
7684
+ }
7682
7685
}
7683
7686
7684
7687
std::string extraFromOptionalsStr (extraFromOptionals, ' !' );
@@ -7776,7 +7779,8 @@ bool NoopCheckedCast::diagnoseForcedCastExpr() const {
7776
7779
auto diagLoc = expr->getLoc ();
7777
7780
7778
7781
if (isCastTypeIUO ()) {
7779
- toType = toType->getOptionalObjectType ();
7782
+ if (auto objType = toType->getOptionalObjectType ())
7783
+ toType = objType;
7780
7784
}
7781
7785
7782
7786
if (fromType->isEqual (toType)) {
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift
2
+
3
+ struct A {
4
+ var prop : Bool
5
+
6
+ func test( ) {
7
+ _ = AssertUnwrap ( prop) as! Bool ! // expected-warning {{using '!' here is deprecated and will be removed in a future release}}
8
+ // expected-warning@-1 {{forced cast from 'Bool?' to 'Bool' only unwraps optionals; did you mean to use '!'?}}
9
+ }
10
+
11
+ @discardableResult
12
+ func AssertUnwrap< T> ( _ optional: T ? ) -> T ? {
13
+ return optional
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments