From 6224909d3775e249bc5bf13338f054a2469c7f25 Mon Sep 17 00:00:00 2001 From: Martin Boehme Date: Thu, 7 May 2020 14:39:55 +0200 Subject: [PATCH] Add a test that imported C++ classes can conform to protocols. Currently, trying to do this causes an assertion failure in SILGen, so the corresponding line in the SILGen test is commented out. See https://bugs.swift.org/browse/SR-12750 --- test/Interop/Cxx/class/Inputs/module.modulemap | 4 ++++ .../Cxx/class/Inputs/protocol-conformance.h | 7 +++++++ .../Cxx/class/protocol-conformance-silgen.swift | 15 +++++++++++++++ .../class/protocol-conformance-typechecker.swift | 13 +++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 test/Interop/Cxx/class/Inputs/protocol-conformance.h create mode 100644 test/Interop/Cxx/class/protocol-conformance-silgen.swift create mode 100644 test/Interop/Cxx/class/protocol-conformance-typechecker.swift 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}}