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 {
76777677
76787678 bool isBridged = CastKind == CheckedCastKind::BridgingCoercion;
76797679 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+ }
76827685 }
76837686
76847687 std::string extraFromOptionalsStr (extraFromOptionals, ' !' );
@@ -7776,7 +7779,8 @@ bool NoopCheckedCast::diagnoseForcedCastExpr() const {
77767779 auto diagLoc = expr->getLoc ();
77777780
77787781 if (isCastTypeIUO ()) {
7779- toType = toType->getOptionalObjectType ();
7782+ if (auto objType = toType->getOptionalObjectType ())
7783+ toType = objType;
77807784 }
77817785
77827786 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