diff --git a/test/Interop/C/implementation-only-imports/Inputs/helper.h b/test/Interop/C/implementation-only-imports/Inputs/helper.h new file mode 100644 index 0000000000000..6eb11f5dbcb38 --- /dev/null +++ b/test/Interop/C/implementation-only-imports/Inputs/helper.h @@ -0,0 +1,8 @@ +#ifndef TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_HELPER_H +#define TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_HELPER_H + +inline int getFortyTwo() { + return 42; +}; + +#endif // TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_HELPER_H diff --git a/test/Interop/C/implementation-only-imports/Inputs/module.modulemap b/test/Interop/C/implementation-only-imports/Inputs/module.modulemap new file mode 100644 index 0000000000000..dd845b25d568c --- /dev/null +++ b/test/Interop/C/implementation-only-imports/Inputs/module.modulemap @@ -0,0 +1,9 @@ +module UserA { + header "user_a.h" + export * +} + +module UserB { + header "user_b.h" + export * +} diff --git a/test/Interop/C/implementation-only-imports/Inputs/user_a.h b/test/Interop/C/implementation-only-imports/Inputs/user_a.h new file mode 100644 index 0000000000000..bebbd757c5561 --- /dev/null +++ b/test/Interop/C/implementation-only-imports/Inputs/user_a.h @@ -0,0 +1,6 @@ +#ifndef TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_USERA_H +#define TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_USERA_H + +#include "helper.h" + +#endif // TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_USERA_H diff --git a/test/Interop/C/implementation-only-imports/Inputs/user_b.h b/test/Interop/C/implementation-only-imports/Inputs/user_b.h new file mode 100644 index 0000000000000..2beac678bf1d2 --- /dev/null +++ b/test/Interop/C/implementation-only-imports/Inputs/user_b.h @@ -0,0 +1,6 @@ +#ifndef TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_USERB_H +#define TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_USERB_H + +#include "helper.h" + +#endif // TEST_INTEROP_C_IMPLEMENTATION_ONLY_IMPORTS_INPUTS_USERB_H diff --git a/test/Interop/C/implementation-only-imports/prefer-a-visible-symbol-over-implementation-only-ones.swift b/test/Interop/C/implementation-only-imports/prefer-a-visible-symbol-over-implementation-only-ones.swift new file mode 100644 index 0000000000000..a7a04c655547c --- /dev/null +++ b/test/Interop/C/implementation-only-imports/prefer-a-visible-symbol-over-implementation-only-ones.swift @@ -0,0 +1,27 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s + +// REQUIRES: SR-13785 + +// TODO: Fix @_implementationOnly to consider all symbol sources + +// If a symbol comes from two modules, one of which is marked as +// @_implementationOnly, Swift may choose the @_implementationOnly source +// and then error out due to the symbol being hidden. + +// Swift should consider all sources for the symbol and recognize that the +// symbol is not hidden behind @_implementationOnly in all modules. + +// E.g: +// In this test case, UserA and UserB both textually include `helper.h`, +// therefore both export `getFortyTwo()`. +// This test verifies that even though Swift chooses UserA.getFortyTwo(), we +// shouldn't get an error, because the symbol is also exported from UserB. + +@_implementationOnly import UserA +import UserB + +@_inlineable +public func callFortyTwo() -> CInt { + return getFortyTwo() +}