Skip to content

Add a test that imported C++ classes can conform to protocols #31617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/Interop/Cxx/class/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ module MemoryLayout {
module MemberVariables {
header "member-variables.h"
}

module ProtocolConformance {
header "protocol-conformance.h"
}
7 changes: 7 additions & 0 deletions test/Interop/Cxx/class/Inputs/protocol-conformance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct ConformsToProtocol {
int return42() { return 42; }
};

struct DoesNotConformToProtocol {
int returnFortyTwo() { return 42; }
};
15 changes: 15 additions & 0 deletions test/Interop/Cxx/class/protocol-conformance-silgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Tests that a C++ class can conform to a Swift protocol.

// RUN: %target-swift-emit-silgen -I %S/Inputs -enable-cxx-interop %s

import ProtocolConformance

protocol HasReturn42 {
mutating func return42() -> CInt
}

// FIXME:
// https://bugs.swift.org/browse/SR-12750
// SILGen currently hits an assertion failure in getParameterTypes() when the
// following protocol conformance is declared.
// extension ConformsToProtocol : HasReturn42 {}
13 changes: 13 additions & 0 deletions test/Interop/Cxx/class/protocol-conformance-typechecker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Tests that a C++ class can conform to a Swift protocol.

// RUN: %target-typecheck-verify-swift -I %S/Inputs -enable-cxx-interop

import ProtocolConformance

protocol HasReturn42 {
mutating func return42() -> CInt // expected-note {{requires function 'return42()'}}
}

extension ConformsToProtocol : HasReturn42 {}

extension DoesNotConformToProtocol : HasReturn42 {} // expected-error {{'DoesNotConformToProtocol' does not conform to protocol}}