File tree Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -2828,13 +2828,24 @@ namespace {
2828
2828
}
2829
2829
2830
2830
if (auto *ntd = dyn_cast<NominalTypeDecl>(result))
2831
- addExplicitProtocolConformances (ntd);
2831
+ addExplicitProtocolConformances (ntd, decl );
2832
2832
2833
2833
return result;
2834
2834
}
2835
2835
2836
- void addExplicitProtocolConformances (NominalTypeDecl *decl) {
2837
- auto clangDecl = decl->getClangDecl ();
2836
+ void
2837
+ addExplicitProtocolConformances (NominalTypeDecl *decl,
2838
+ const clang::CXXRecordDecl *clangDecl) {
2839
+ if (Impl.isCxxInteropCompatVersionAtLeast (
2840
+ version::getUpcomingCxxInteropCompatVersion ())) {
2841
+ // Propagate conforms_to attribute from public base classes.
2842
+ for (auto base : clangDecl->bases ()) {
2843
+ if (base.getAccessSpecifier () != clang::AccessSpecifier::AS_public)
2844
+ continue ;
2845
+ if (auto *baseClangDecl = base.getType ()->getAsCXXRecordDecl ())
2846
+ addExplicitProtocolConformances (decl, baseClangDecl);
2847
+ }
2848
+ }
2838
2849
2839
2850
if (!clangDecl->hasAttrs ())
2840
2851
return ;
Original file line number Diff line number Diff line change @@ -22,4 +22,19 @@ struct
22
22
void testImported () const ;
23
23
};
24
24
25
+ struct DerivedFromHasTest : HasTest {};
26
+ struct DerivedFromDerivedFromHasTest : HasTest {};
27
+
28
+ struct __attribute__((swift_attr ("conforms_to:SwiftTest.Testable" )))
29
+ DerivedFromDerivedFromHasTestWithDuplicateArg : HasTest {};
30
+
31
+ struct DerivedFromHasPlay : HasPlay {};
32
+ struct DerivedFromDerivedFromHasPlay : HasPlay {};
33
+
34
+ struct HasTestAndPlay : HasPlay , HasTest {};
35
+ struct DerivedFromHasTestAndPlay : HasPlay , HasTest {};
36
+
37
+ struct DerivedFromHasImportedConf : HasImportedConf {};
38
+ struct DerivedFromDerivedFromHasImportedConf : HasImportedConf {};
39
+
25
40
#endif // TEST_INTEROP_CXX_CLASS_INPUTS_DESTRUCTORS_H
Original file line number Diff line number Diff line change 2
2
// RUN: %target-swift-frontend %S/Inputs/conforms-to-imported.swift -module-name ImportedModule -emit-module -emit-module-path %t/ImportedModule.swiftmodule
3
3
4
4
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %t -I %S/Inputs -module-name SwiftTest -enable-experimental-cxx-interop
5
+ // RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %t -I %S/Inputs -module-name SwiftTest -cxx-interoperability-mode=upcoming-swift -D UPCOMING_SWIFT
5
6
6
7
import ConformsTo
7
8
import ImportedModule
@@ -21,6 +22,11 @@ func callee(_ _: Testable) {
21
22
func caller( _ x: HasTest ) {
22
23
callee ( x)
23
24
}
25
+ #if UPCOMING_SWIFT
26
+ func caller( _ x: DerivedFromHasTest ) { callee ( x) }
27
+ func caller( _ x: DerivedFromDerivedFromHasTest ) { callee ( x) }
28
+ func caller( _ x: DerivedFromDerivedFromHasTestWithDuplicateArg ) { callee ( x) }
29
+ #endif
24
30
25
31
func callee( _ _: Playable ) {
26
32
@@ -29,10 +35,27 @@ func callee(_ _: Playable) {
29
35
func caller( _ x: Playable ) {
30
36
callee ( x)
31
37
}
38
+ #if UPCOMING_SWIFT
39
+ func caller( _ x: DerivedFromHasPlay ) { callee ( x) }
40
+ func caller( _ x: DerivedFromDerivedFromHasPlay ) { callee ( x) }
41
+
42
+ func caller( _ x: HasTestAndPlay ) {
43
+ callee ( x as Testable )
44
+ callee ( x as Playable )
45
+ }
46
+ func caller( _ x: DerivedFromHasTestAndPlay ) {
47
+ callee ( x as Testable )
48
+ callee ( x as Playable )
49
+ }
50
+ #endif
32
51
33
52
func callee( _ _: ProtocolFromImportedModule ) {
34
53
}
35
54
36
55
func caller( _ x: HasImportedConf ) {
37
56
callee ( x)
38
57
}
58
+ #if UPCOMING_SWIFT
59
+ func caller( _ x: DerivedFromHasImportedConf ) { callee ( x) }
60
+ func caller( _ x: DerivedFromDerivedFromHasImportedConf ) { callee ( x) }
61
+ #endif
You can’t perform that action at this time.
0 commit comments