|
| 1 | +/// The order of imports in sources shouldn't matter for access-levels. |
| 2 | + |
| 3 | +// RUN: %empty-directory(%t) |
| 4 | +// RUN: split-file %s %t --leading-lines |
| 5 | + |
| 6 | +/// Build the libraries. |
| 7 | +// RUN: %target-swift-frontend -emit-module %t/Lib1.swift -module-name Lib1 -o %t |
| 8 | +// RUN: %target-swift-frontend -emit-module %t/Lib2.swift -module-name Lib2 -o %t |
| 9 | + |
| 10 | +/// Test main cases. |
| 11 | +// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t -package-name pkg \ |
| 12 | +// RUN: -verify -verify-ignore-unrelated |
| 13 | +// RUN: %target-swift-frontend -typecheck %t/Client_Clang.swift -I %t \ |
| 14 | +// RUN: -verify -verify-ignore-unrelated |
| 15 | +// RUN: %target-swift-frontend -typecheck %t/Client_Clang.swift -I %t -DINVERT \ |
| 16 | +// RUN: -verify -verify-ignore-unrelated |
| 17 | +// RUN: %target-swift-frontend -typecheck %t/Client_Clang_Submodules.swift -I %t \ |
| 18 | +// RUN: -verify -verify-ignore-unrelated |
| 19 | +// RUN: %target-swift-frontend -typecheck %t/Client_Clang_Submodules.swift -I %t -DINVERT \ |
| 20 | +// RUN: -verify -verify-ignore-unrelated |
| 21 | + |
| 22 | +// REQUIRES: VENDOR=apple |
| 23 | + |
| 24 | +//--- Lib1.swift |
| 25 | +public struct Type1 {} |
| 26 | + |
| 27 | +//--- Lib2.swift |
| 28 | +public struct Type2 {} |
| 29 | + |
| 30 | +//--- Client.swift |
| 31 | + |
| 32 | +/// Simple public vs internal. |
| 33 | +package import Lib1 // expected-note {{imported 'package' here}} |
| 34 | +// expected-note @-1 {{struct 'Type1' imported as 'package' from 'Lib1' here}} |
| 35 | +internal import Lib1 // expected-warning {{module 'Lib1' is imported as 'package' from the same file; this 'internal' access level will be ignored}} |
| 36 | + |
| 37 | +/// Simple package vs internal, inverted. |
| 38 | +internal import Lib2 // expected-warning {{module 'Lib2' is imported as 'package' from the same file; this 'internal' access level will be ignored}} |
| 39 | +package import Lib2 // expected-note {{imported 'package' here}} |
| 40 | +// expected-note @-1 {{struct 'Type2' imported as 'package' from 'Lib2' here}} |
| 41 | + |
| 42 | +public func dummyAPI(t1: Type1) {} // expected-error {{function cannot be declared public because its parameter uses a package type}} |
| 43 | +// expected-note @-1 {{struct 'Type1' is imported by this file as 'package' from 'Lib1'}} |
| 44 | + |
| 45 | +public func dummyAPI(t2: Type2) {} // expected-error {{function cannot be declared public because its parameter uses a package type}} |
| 46 | +// expected-note @-1 {{struct 'Type2' is imported by this file as 'package' from 'Lib2'}} |
| 47 | + |
| 48 | +//--- Client_Clang.swift |
| 49 | + |
| 50 | +#if INVERT |
| 51 | +private import ClangLib |
| 52 | +#endif |
| 53 | + |
| 54 | +internal import ClangLib2 // expected-note {{struct 'ClangType' imported as 'internal' from 'ClangLib2' here}} |
| 55 | + |
| 56 | +#if !INVERT |
| 57 | +private import ClangLib |
| 58 | +#endif |
| 59 | + |
| 60 | +public func dummyAPI(t2: ClangType) {} |
| 61 | +// expected-error @-1 {{function cannot be declared public because its parameter uses an internal type}} |
| 62 | +// expected-note @-2 {{struct 'ClangType' is imported by this file as 'internal' from 'ClangLib2'}} |
| 63 | + |
| 64 | +//--- Client_Clang_Submodules.swift |
| 65 | + |
| 66 | +#if INVERT |
| 67 | +private import ClangLib.Sub1 |
| 68 | +#endif |
| 69 | + |
| 70 | +internal import ClangLib.Sub2 // expected-note {{struct 'SubType' imported as 'internal' from 'Sub2' here}} |
| 71 | + |
| 72 | +#if !INVERT |
| 73 | +private import ClangLib.Sub1 |
| 74 | +#endif |
| 75 | + |
| 76 | +public func dummyAPI(t2: SubType) {} |
| 77 | +// expected-error @-1 {{function cannot be declared public because its parameter uses an internal type}} |
| 78 | +// expected-note @-2 {{struct 'SubType' is imported by this file as 'internal' from 'Sub2'}} |
| 79 | + |
| 80 | +//--- module.modulemap |
| 81 | + |
| 82 | +module ClangLib { |
| 83 | + header "ClangLib1.h" |
| 84 | + |
| 85 | + explicit module Sub1 { |
| 86 | + header "Sub1.h" |
| 87 | + } |
| 88 | + |
| 89 | + explicit module Sub2 { |
| 90 | + header "Sub2.h" |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +module ClangLib2 { |
| 95 | + header "ClangLib2.h" |
| 96 | + export * |
| 97 | +} |
| 98 | + |
| 99 | +//--- ClangLib1.h |
| 100 | +struct ClangType {}; |
| 101 | + |
| 102 | +//--- ClangLib2.h |
| 103 | +#include <ClangLib1.h> |
| 104 | + |
| 105 | +//--- Sub1.h |
| 106 | +struct SubType {}; |
| 107 | + |
| 108 | +//--- Sub2.h |
| 109 | +#include "Sub1.h" |
0 commit comments