Skip to content

Commit 8f3822e

Browse files
authored
Merge pull request #76717 from swiftlang/egorzhdan/6.0-frt-test-nonobjc
🍒[cxx-interop] C++ reference types are not `AnyObject`s
2 parents 506b3f8 + 2f61118 commit 8f3822e

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
@@ -7704,6 +7704,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
77047704
// Class and protocol metatypes are interoperable with certain Objective-C
77057705
// runtime classes, but only when ObjC interop is enabled.
77067706

7707+
// Foreign reference types do *not* conform to AnyObject.
7708+
if (type1->isForeignReferenceType() && type2->isAnyObject())
7709+
return getTypeMatchFailure(locator);
7710+
77077711
if (getASTContext().LangOpts.EnableObjCInterop) {
77087712
// These conversions are between concrete types that don't need further
77097713
// resolution, so we can consider them immediately solved.
@@ -7713,10 +7717,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
77137717
type1, type2, locator);
77147718
return getTypeMatchSuccess();
77157719
};
7716-
7717-
// Foreign reference types do *not* conform to AnyObject.
7718-
if (type1->isForeignReferenceType() && type2->isAnyObject())
7719-
return getTypeMatchFailure(locator);
77207720

77217721
if (auto meta1 = type1->getAs<MetatypeType>()) {
77227722
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)