diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 8822ed2ae90..4c6963bdcf6 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -2040,9 +2040,14 @@ commit_to_conversions: conversionsOrFixes.push_back(Fix::getForcedDowncast(*this, type2)); } + // Look through IUO's. + auto type1WithoutIUO = objectType1; + if (auto elt = type1WithoutIUO->getImplicitlyUnwrappedOptionalObjectType()) + type1WithoutIUO = elt; + // If we could perform a bridging cast, try it. if (isArrayDictionarySetOrString(TC.Context, type2) && - TC.getDynamicBridgedThroughObjCClass(DC, true, objectType1, type2)) { + TC.getDynamicBridgedThroughObjCClass(DC, true, type1WithoutIUO, type2)){ conversionsOrFixes.push_back(Fix::getForcedDowncast(*this, type2)); } diff --git a/test/Constraints/bridging.swift b/test/Constraints/bridging.swift index c3f3ecffdf3..7474d905b0b 100644 --- a/test/Constraints/bridging.swift +++ b/test/Constraints/bridging.swift @@ -275,3 +275,9 @@ func rdar19813772(nsma: NSMutableArray) { func force_cast_fixit(a : [NSString]) -> [NSString] { return a as! [NSString] // expected-warning {{forced cast of '[NSString]' to same type has no effect}} {{12-27=}} } + +// QoI: IUO prevents specific diagnostic + fixit about non-implicitly converted bridge types +func rdar21244068(n: NSString!) -> String { + return n // expected-error {{'NSString!' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?}} {{11-11= as String}} +} +