Skip to content

Commit 53055fa

Browse files
authored
Merge pull request #31617 from martinboehme/cxx-protocol-conformance
Add a test that imported C++ classes can conform to protocols
2 parents 091a6d8 + 6224909 commit 53055fa

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

test/Interop/Cxx/class/Inputs/module.modulemap

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ module MemoryLayout {
99
module MemberVariables {
1010
header "member-variables.h"
1111
}
12+
13+
module ProtocolConformance {
14+
header "protocol-conformance.h"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct ConformsToProtocol {
2+
int return42() { return 42; }
3+
};
4+
5+
struct DoesNotConformToProtocol {
6+
int returnFortyTwo() { return 42; }
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Tests that a C++ class can conform to a Swift protocol.
2+
3+
// RUN: %target-swift-emit-silgen -I %S/Inputs -enable-cxx-interop %s
4+
5+
import ProtocolConformance
6+
7+
protocol HasReturn42 {
8+
mutating func return42() -> CInt
9+
}
10+
11+
// FIXME:
12+
// https://bugs.swift.org/browse/SR-12750
13+
// SILGen currently hits an assertion failure in getParameterTypes() when the
14+
// following protocol conformance is declared.
15+
// extension ConformsToProtocol : HasReturn42 {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Tests that a C++ class can conform to a Swift protocol.
2+
3+
// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-cxx-interop
4+
5+
import ProtocolConformance
6+
7+
protocol HasReturn42 {
8+
mutating func return42() -> CInt // expected-note {{requires function 'return42()'}}
9+
}
10+
11+
extension ConformsToProtocol : HasReturn42 {}
12+
13+
extension DoesNotConformToProtocol : HasReturn42 {} // expected-error {{'DoesNotConformToProtocol' does not conform to protocol}}

0 commit comments

Comments
 (0)