File: access-level-import-inconsistencies.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (90 lines) | stat: -rw-r--r-- 4,473 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/// Import inconsistencies.
///
/// Swift 5 case, with slow adoption of access level on imports.
/// Report default imports if any other import of the same module
/// has an access level below public (the default).
///
/// Swift 6 case, with default imports as internal.
/// Don't report any mismatch.

// RUN: %empty-directory(%t)
// RUN: split-file --leading-lines %s %t

/// Build the library.
// RUN: %target-swift-frontend -emit-module %t/Lib.swift -o %t

/// Check diagnostics.

//--- Lib.swift
public struct LibType {}

// RUN: %target-swift-frontend -typecheck %t/OneFile_AllExplicit.swift -I %t \
// RUN:   -package-name package -verify
//--- OneFile_AllExplicit.swift
public import Lib // expected-warning {{public import of 'Lib' was not used in public declarations or inlinable code}}
// expected-note @-1 4 {{imported 'public' here}}
package import Lib // expected-warning {{package import of 'Lib' was not used in package declarations}}
// expected-warning @-1 {{module 'Lib' is imported as 'public' from the same file; this 'package' access level will be ignored}}
internal import Lib
// expected-warning @-1 {{module 'Lib' is imported as 'public' from the same file; this 'internal' access level will be ignored}}
fileprivate import Lib
// expected-warning @-1 {{module 'Lib' is imported as 'public' from the same file; this 'fileprivate' access level will be ignored}}
private import Lib
// expected-warning @-1 {{module 'Lib' is imported as 'public' from the same file; this 'private' access level will be ignored}}

// RUN: %target-swift-frontend -typecheck %t/ManyFiles_AllExplicit_File?.swift -I %t \
// RUN:   -package-name package -verify
//--- ManyFiles_AllExplicit_FileA.swift
public import Lib // expected-warning {{public import of 'Lib' was not used in public declarations or inlinable code}}
//--- ManyFiles_AllExplicit_FileB.swift
package import Lib // expected-warning {{package import of 'Lib' was not used in package declarations}}
//--- ManyFiles_AllExplicit_FileC.swift
internal import Lib
//--- ManyFiles_AllExplicit_FileD.swift
fileprivate import Lib
//--- ManyFiles_AllExplicit_FileE.swift
private import Lib

// RUN: %target-swift-frontend -typecheck %t/ManyFiles_ImplicitVsInternal_FileB.swift -I %t \
// RUN:   -primary-file %t/ManyFiles_ImplicitVsInternal_FileA.swift -verify
//--- ManyFiles_ImplicitVsInternal_FileA.swift
import Lib // expected-error {{ambiguous implicit access level for import of 'Lib'; it is imported as 'internal' elsewhere}}
// expected-note @-1 {{silence these warnings by adopting the upcoming feature 'InternalImportsByDefault'}}
//--- ManyFiles_ImplicitVsInternal_FileB.swift
internal import Lib // expected-note {{imported 'internal' here}}

// RUN: %target-swift-frontend -typecheck %t/ManyFiles_ImplicitVsPackage_FileB.swift -I %t \
// RUN:   -primary-file %t/ManyFiles_ImplicitVsPackage_FileA.swift -verify
//--- ManyFiles_ImplicitVsPackage_FileA.swift
import Lib // expected-error {{ambiguous implicit access level for import of 'Lib'; it is imported as 'package' elsewhere}}
// expected-note @-1 {{silence these warnings by adopting the upcoming feature 'InternalImportsByDefault'}}
//--- ManyFiles_ImplicitVsPackage_FileB.swift
package import Lib // expected-note {{imported 'package' here}} @:1

// RUN: %target-swift-frontend -typecheck %t/ManyFiles_AmbiguitySwift6_File?.swift -I %t \
// RUN:   -enable-upcoming-feature InternalImportsByDefault -verify
//--- ManyFiles_AmbiguitySwift6_FileA.swift
import Lib
//--- ManyFiles_AmbiguitySwift6_FileB.swift
internal import Lib

/// Don't report an ambiguity between an explicitly vs implicitly public import.
// RUN: %target-swift-frontend -typecheck %t/ManyFiles_AmbiguityPublicExplicitVsImplicit_File?.swift -I %t \
// RUN:  -verify
//--- ManyFiles_AmbiguityPublicExplicitVsImplicit_FileA.swift
import Lib
//--- ManyFiles_AmbiguityPublicExplicitVsImplicit_FileB.swift
public import Lib // expected-warning {{public import of 'Lib' was not used in public declarations or inlinable code}}

/// Don't report inconsistencies from a file generated by Xcode.
// RUN: %target-swift-frontend -typecheck -I %t \
// RUN    -primary-file %t/GeneratedAssetSymbols.swift \
// RUN:   %t/UserWrittenFile.swift -verify
// RUN: %target-swift-frontend -typecheck -I %t \
// RUN    %t/GeneratedAssetSymbols.swift \
// RUN:   -primary-file %t/UserWrittenFile.swift -verify
//--- UserWrittenFile.swift
internal import Lib
//--- GeneratedAssetSymbols.swift
import Lib