Skip to content

Commit 6b91c5b

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.
1 parent a4dafa3 commit 6b91c5b

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
@@ -3938,7 +3938,7 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
39383938
}
39393939

39403940
// If the bridged value type is generic, the generic arguments
3941-
// must match the
3941+
// must either match or be bridged.
39423942
// FIXME: This should be an associated type of the protocol.
39433943
if (auto bgt1 = type2->getAs<BoundGenericType>()) {
39443944
if (bgt1->getDecl() == TC.Context.getArrayDecl()) {
@@ -3981,7 +3981,7 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
39813981
locator.withPathElement(
39823982
LocatorPathElt::getGenericArgument(0))));
39833983
} else {
3984-
llvm_unreachable("unhandled generic bridged type");
3984+
// Nothing special to do; matchTypes will match generic arguments.
39853985
}
39863986
}
39873987

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)