Skip to content

Commit f836188

Browse files
committed
[Type checker] Handle explicit conversion of bridged generic types.
The type checker had some logic for performing specific checking for explicit bridging casts of generic types based on knowledge of Array/Dictionary/Set, but pretended no other bridged generic types existed. That's incorrect now; simply require them to match exactly. Fixes rdar://problem/27539951. (cherry picked from commit 6b91c5b)
1 parent 8db7b08 commit f836188

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,7 +4176,7 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
41764176
}
41774177

41784178
// If the bridged value type is generic, the generic arguments
4179-
// must match the
4179+
// must either match or be bridged.
41804180
// FIXME: This should be an associated type of the protocol.
41814181
if (auto bgt1 = type2->getAs<BoundGenericType>()) {
41824182
if (bgt1->getDecl() == TC.Context.getArrayDecl()) {
@@ -4219,7 +4219,7 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
42194219
locator.withPathElement(
42204220
LocatorPathElt::getGenericArgument(0))));
42214221
} else {
4222-
llvm_unreachable("unhandled generic bridged type");
4222+
// Nothing special to do; matchTypes will match generic arguments.
42234223
}
42244224
}
42254225

test/ClangModules/objc_bridging_custom.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,18 @@ class TestObjCProtoImpl : NSObject, TestObjCProto {
211211
return nil
212212
}
213213
}
214+
215+
// Check explicit conversions for bridged generic types.
216+
// rdar://problem/27539951
217+
func testExplicitConversion(objc: APPManufacturerInfo<NSString>,
218+
swift: ManufacturerInfo<NSString>) {
219+
// Bridging to Swift
220+
let _ = objc as ManufacturerInfo<NSString>
221+
let _ = objc as ManufacturerInfo<NSNumber> // expected-error{{cannot convert value of type 'APPManufacturerInfo<NSString>' to type 'ManufacturerInfo<NSNumber>' in coercion}}
222+
let _ = objc as ManufacturerInfo<NSObject> // expected-error{{cannot convert value of type 'APPManufacturerInfo<NSString>' to type 'ManufacturerInfo<NSObject>' in coercion}}
223+
224+
// Bridging to Objective-C
225+
let _ = swift as APPManufacturerInfo<NSString>
226+
let _ = swift as APPManufacturerInfo<NSNumber> // expected-error{{cannot convert value of type 'ManufacturerInfo<NSString>' to type 'APPManufacturerInfo<NSNumber>' in coercion}}
227+
let _ = swift as APPManufacturerInfo<NSObject> // expected-error{{cannot convert value of type 'ManufacturerInfo<NSString>' to type 'APPManufacturerInfo<NSObject>' in coercion}}
228+
}

0 commit comments

Comments
 (0)