Skip to content

Commit c126bab

Browse files
authored
Merge pull request #74185 from swiftlang/egorzhdan/frt-test-nonobjc
[cxx-interop] C++ reference types are not `AnyObject`s
2 parents 8c5d7ee + 82c076c commit c126bab

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7568,6 +7568,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
75687568
// Class and protocol metatypes are interoperable with certain Objective-C
75697569
// runtime classes, but only when ObjC interop is enabled.
75707570

7571+
// Foreign reference types do *not* conform to AnyObject.
7572+
if (type1->isForeignReferenceType() && type2->isAnyObject())
7573+
return getTypeMatchFailure(locator);
7574+
75717575
if (getASTContext().LangOpts.EnableObjCInterop) {
75727576
// These conversions are between concrete types that don't need further
75737577
// resolution, so we can consider them immediately solved.
@@ -7577,10 +7581,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
75777581
type1, type2, locator);
75787582
return getTypeMatchSuccess();
75797583
};
7580-
7581-
// Foreign reference types do *not* conform to AnyObject.
7582-
if (type1->isForeignReferenceType() && type2->isAnyObject())
7583-
return getTypeMatchFailure(locator);
75847584

75857585
if (auto meta1 = type1->getAs<MetatypeType>()) {
75867586
if (meta1->getInstanceType()->mayHaveSuperclass()

test/Interop/Cxx/foreign-reference/not-any-object.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
// RUN: split-file %s %t
33
// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unknown -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop
44

5-
// REQUIRES: objc_interop
6-
75
//--- Inputs/module.modulemap
86
module Test {
97
header "test.h"
108
requires cplusplus
119
}
1210

1311
//--- Inputs/test.h
14-
#include <stdlib.h>
15-
16-
inline void* operator new(unsigned long, void* p) { return p; }
17-
1812
struct __attribute__((swift_attr("import_reference")))
1913
__attribute__((swift_attr("retain:immortal")))
2014
__attribute__((swift_attr("release:immortal"))) Empty {
21-
static Empty *create() { return new (malloc(sizeof(Empty))) Empty(); }
15+
static Empty *create() { return new Empty(); }
2216
};
2317

2418
//--- test.swift

0 commit comments

Comments
 (0)