|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | + |
| 4 | +/// Build the library. |
| 5 | +// RUN: %target-swift-frontend -emit-module %t/Lib.swift -module-name Lib1 -o %t |
| 6 | +// RUN: %target-swift-frontend -emit-module %t/Lib.swift -module-name Lib2 -o %t |
| 7 | +// RUN: %target-swift-frontend -emit-module %t/Lib.swift -module-name Lib3 -o %t |
| 8 | +// RUN: %target-swift-frontend -emit-module %t/Lib.swift -module-name Lib4 -o %t |
| 9 | +// RUN: %target-swift-frontend -emit-module %t/Lib.swift -module-name Lib5 -o %t |
| 10 | + |
| 11 | +/// Test main cases. |
| 12 | +// RUN: %target-swift-frontend -typecheck -verify %t/Client.swift -I %t |
| 13 | +// RUN: %target-swift-frontend -typecheck -verify %t/Client_Scoped.swift -I %t |
| 14 | +// RUN: %target-swift-frontend -typecheck -verify %t/Client_Clang.swift -I %t |
| 15 | + |
| 16 | +/// Test language mode specific variants. |
| 17 | +// RUN: %target-swift-frontend -typecheck -verify %t/Client_Swift6.swift -I %t \ |
| 18 | +// RUN: -enable-upcoming-feature InternalImportsByDefault |
| 19 | +// RUN: %target-swift-frontend -typecheck -verify %t/Client_Swift5.swift -I %t \ |
| 20 | +// RUN: -swift-version 5 |
| 21 | + |
| 22 | +//--- Lib.swift |
| 23 | + |
| 24 | +public struct Type1 {} |
| 25 | +public struct Type2 {} |
| 26 | + |
| 27 | +//--- Client.swift |
| 28 | + |
| 29 | +/// Simple public vs internal. |
| 30 | +public import Lib1 // expected-note {{imported 'public' here}} |
| 31 | +internal import Lib1 // expected-warning {{module 'Lib1' is imported as 'public' from the same file; this 'internal' access level will be ignored}} |
| 32 | + |
| 33 | +/// Simple public vs internal, inverted. |
| 34 | +internal import Lib2 // expected-warning {{module 'Lib2' is imported as 'public' from the same file; this 'internal' access level will be ignored}} |
| 35 | +public import Lib2 // expected-note {{imported 'public' here}} |
| 36 | + |
| 37 | +/// 3 different ones. |
| 38 | +public import Lib3 // expected-note 2 {{imported 'public' here}} |
| 39 | +internal import Lib3 // expected-warning {{module 'Lib3' is imported as 'public' from the same file; this 'internal' access level will be ignored}} |
| 40 | +private import Lib3 // expected-warning {{module 'Lib3' is imported as 'public' from the same file; this 'private' access level will be ignored}} |
| 41 | + |
| 42 | +/// private vs fileprivate, we don't really need this warning but it may point to unintended stylistic inconsistencies. |
| 43 | +fileprivate import Lib4 // expected-note {{imported 'fileprivate' here}} |
| 44 | +private import Lib4 // expected-warning {{module 'Lib4' is imported as 'fileprivate' from the same file; this 'private' access level will be ignored}} |
| 45 | + |
| 46 | +// Don't complain about repeated imports. As far as this diagnostic |
| 47 | +// is concerned we may see this with scoped imports. |
| 48 | +internal import Lib5 |
| 49 | +internal import Lib5 |
| 50 | +internal import Lib5 |
| 51 | +internal import Lib5 |
| 52 | + |
| 53 | +public func dummyAPI(t1: Lib1.Type1, t2: Lib2.Type1, t3: Lib3.Type1) {} |
| 54 | + |
| 55 | +//--- Client_Swift5.swift |
| 56 | + |
| 57 | +/// Simple public vs internal, imports defaults to public. |
| 58 | +import Lib1 // expected-note {{imported 'public' here}} |
| 59 | +// expected-error @-1 {{ambiguous implicit access level for import of 'Lib1'; it is imported as 'internal' elsewhere}} |
| 60 | +internal import Lib1 // expected-warning {{module 'Lib1' is imported as 'public' from the same file; this 'internal' access level will be ignored}} |
| 61 | +// expected-note @-1 {{imported 'internal' here}} |
| 62 | + |
| 63 | +// There's no warning about "will be ignored" for a matching implicit access level. |
| 64 | +public import Lib2 |
| 65 | +// expected-note @-1 {{imported 'public' here}} |
| 66 | +import Lib2 |
| 67 | +// expected-error @-1 {{ambiguous implicit access level for import of 'Lib2'; it is imported as 'public' elsewhere}} |
| 68 | + |
| 69 | +public func dummyAPI(t: Lib1.Type1, t2: Lib2.Type1) {} |
| 70 | + |
| 71 | +//--- Client_Swift6.swift |
| 72 | + |
| 73 | +/// Simple public vs internal, imports default to internal. |
| 74 | +public import Lib1 // expected-note {{imported 'public' here}} |
| 75 | +import Lib1 // expected-warning {{module 'Lib1' is imported as 'public' from the same file; this 'internal' access level will be ignored}} |
| 76 | + |
| 77 | +// There's no warning about "will be ignored" for a matching implicit access level. |
| 78 | +import Lib2 |
| 79 | +internal import Lib2 |
| 80 | + |
| 81 | +public func dummyAPI(t: Lib1.Type1) {} |
| 82 | + |
| 83 | +//--- Client_Scoped.swift |
| 84 | + |
| 85 | +/// Access level on scoped imports still import the whole module. |
| 86 | +public import struct Lib1.Type1 // expected-note {{imported 'public' here}} |
| 87 | +internal import struct Lib1.Type2 // expected-warning {{module 'Lib1' is imported as 'public' from the same file; this 'internal' access level will be ignored}} |
| 88 | + |
| 89 | +public func dummyAPI(t: Lib1.Type1) {} |
| 90 | + |
| 91 | +//--- Client_Clang.swift |
| 92 | + |
| 93 | +public import ClangLib.Sub1 // expected-note {{imported 'public' here}} |
| 94 | +// expected-warning @-1 {{public import of 'Sub1' was not used in public declarations or inlinable code}} |
| 95 | +private import ClangLib.Sub1 // expected-warning {{module 'Sub1' is imported as 'public' from the same file; this 'private' access level will be ignored}} |
| 96 | +internal import ClangLib.Sub2 |
| 97 | + |
| 98 | +public func dummyAPI(t1: ClangType1, t2: ClangType2) {} |
| 99 | + |
| 100 | +//--- module.modulemap |
| 101 | + |
| 102 | +module ClangLib { |
| 103 | + header "ClangLib1.h" |
| 104 | + |
| 105 | + explicit module Sub1 { |
| 106 | + header "ClangLib2.h" |
| 107 | + } |
| 108 | + |
| 109 | + explicit module Sub2 { |
| 110 | + header "ClangLib3.h" |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +//--- ClangLib1.h |
| 115 | +struct ClangType1 {}; |
| 116 | +//--- ClangLib2.h |
| 117 | +struct ClangType2 {}; |
| 118 | +//--- ClangLib3.h |
0 commit comments