diff --git a/test/Interop/Cxx/class/Inputs/module.modulemap b/test/Interop/Cxx/class/Inputs/module.modulemap index 1b740175317d4..daf6d70bf544b 100644 --- a/test/Interop/Cxx/class/Inputs/module.modulemap +++ b/test/Interop/Cxx/class/Inputs/module.modulemap @@ -9,3 +9,7 @@ module MemoryLayout { module MemberVariables { header "member-variables.h" } + +module ProtocolConformance { + header "protocol-conformance.h" +} diff --git a/test/Interop/Cxx/class/Inputs/protocol-conformance.h b/test/Interop/Cxx/class/Inputs/protocol-conformance.h new file mode 100644 index 0000000000000..d607b5a3caa54 --- /dev/null +++ b/test/Interop/Cxx/class/Inputs/protocol-conformance.h @@ -0,0 +1,7 @@ +struct ConformsToProtocol { + int return42() { return 42; } +}; + +struct DoesNotConformToProtocol { + int returnFortyTwo() { return 42; } +}; diff --git a/test/Interop/Cxx/class/protocol-conformance-silgen.swift b/test/Interop/Cxx/class/protocol-conformance-silgen.swift new file mode 100644 index 0000000000000..951f10a0b9ca6 --- /dev/null +++ b/test/Interop/Cxx/class/protocol-conformance-silgen.swift @@ -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 {} diff --git a/test/Interop/Cxx/class/protocol-conformance-typechecker.swift b/test/Interop/Cxx/class/protocol-conformance-typechecker.swift new file mode 100644 index 0000000000000..bafb5809b6d40 --- /dev/null +++ b/test/Interop/Cxx/class/protocol-conformance-typechecker.swift @@ -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}}