/// 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

// REQUIRES: swift_feature_InternalImportsByDefault
//--- UserWrittenFile.swift
internal import Lib
//--- GeneratedAssetSymbols.swift
import Lib

