Skip to content

[Type checker] Handle explicit conversion of bridged generic types. #4764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3938,7 +3938,7 @@ ConstraintSystem::simplifyRestrictedConstraint(ConversionRestrictionKind restric
}

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

Expand Down
15 changes: 15 additions & 0 deletions test/ClangModules/objc_bridging_custom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,18 @@ class TestObjCProtoImpl : NSObject, TestObjCProto {
return nil
}
}

// Check explicit conversions for bridged generic types.
// rdar://problem/27539951
func testExplicitConversion(objc: APPManufacturerInfo<NSString>,
swift: ManufacturerInfo<NSString>) {
// Bridging to Swift
let _ = objc as ManufacturerInfo<NSString>
let _ = objc as ManufacturerInfo<NSNumber> // expected-error{{cannot convert value of type 'APPManufacturerInfo<NSString>' to type 'ManufacturerInfo<NSNumber>' in coercion}}
let _ = objc as ManufacturerInfo<NSObject> // expected-error{{cannot convert value of type 'APPManufacturerInfo<NSString>' to type 'ManufacturerInfo<NSObject>' in coercion}}

// Bridging to Objective-C
let _ = swift as APPManufacturerInfo<NSString>
let _ = swift as APPManufacturerInfo<NSNumber> // expected-error{{cannot convert value of type 'ManufacturerInfo<NSString>' to type 'APPManufacturerInfo<NSNumber>' in coercion}}
let _ = swift as APPManufacturerInfo<NSObject> // expected-error{{cannot convert value of type 'ManufacturerInfo<NSString>' to type 'APPManufacturerInfo<NSObject>' in coercion}}
}