mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[cxx-interop] C++ reference types are not AnyObjects
C++ foreign reference types have custom reference counting mechanisms, so they cannot conform to `AnyObject`. Currently Swift's type system treats C++ FRTs as `AnyObject`s on non-Darwin platforms, which is incorrect. This change makes sure the behavior is consistent with Darwin platform, i.e. a cast of C++ FRT to `AnyObject` is rejected by the typechecker. rdar://136664617
This commit is contained in:
@@ -7580,6 +7580,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
// Class and protocol metatypes are interoperable with certain Objective-C
|
||||
// runtime classes, but only when ObjC interop is enabled.
|
||||
|
||||
// Foreign reference types do *not* conform to AnyObject.
|
||||
if (type1->isForeignReferenceType() && type2->isAnyObject())
|
||||
return getTypeMatchFailure(locator);
|
||||
|
||||
if (getASTContext().LangOpts.EnableObjCInterop) {
|
||||
// These conversions are between concrete types that don't need further
|
||||
// resolution, so we can consider them immediately solved.
|
||||
@@ -7589,10 +7593,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
type1, type2, locator);
|
||||
return getTypeMatchSuccess();
|
||||
};
|
||||
|
||||
// Foreign reference types do *not* conform to AnyObject.
|
||||
if (type1->isForeignReferenceType() && type2->isAnyObject())
|
||||
return getTypeMatchFailure(locator);
|
||||
|
||||
if (auto meta1 = type1->getAs<MetatypeType>()) {
|
||||
if (meta1->getInstanceType()->mayHaveSuperclass()
|
||||
|
||||
Reference in New Issue
Block a user