forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request swiftlang#78718 from xymus/fix-importing-non-visib…
…le-decls-6.1 [6.1] Sema: Ensure access-level on imports only applies to visible imported decls
- Loading branch information
Showing
3 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/// Ensure we only bump down the access-level of imported decls, not up. | ||
|
||
// RUN: %empty-directory(%t) | ||
// RUN: split-file %s %t | ||
|
||
/// Build libraries | ||
// RUN: %target-swift-frontend -emit-module %t/ImportedPrivate.swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -package-name pkg \ | ||
// RUN: -emit-module-path %t/ImportedPrivate.swiftmodule | ||
// RUN: %target-swift-frontend -emit-module %t/ImportedInternal.swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -package-name pkg \ | ||
// RUN: -emit-module-path %t/ImportedInternal.swiftmodule -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/ImportedPackage.swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -package-name pkg \ | ||
// RUN: -emit-module-path %t/ImportedPackage.swiftmodule -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/ImportedPublic.swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -package-name pkg \ | ||
// RUN: -emit-module-path %t/ImportedPublic.swiftmodule -I %t | ||
|
||
/// Build clients | ||
// RUN: %target-swift-frontend -typecheck %t/InPackageClient.swift -I %t \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -package-name pkg -verify | ||
// RUN: %target-swift-frontend -typecheck %t/OutOfPackageClient.swift -I %t \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -verify | ||
|
||
//--- ImportedPrivate.swift | ||
|
||
private func privateFunc() {} | ||
internal func internalFunc() {} | ||
package func packageFunc() {} | ||
public func publicFunc() {} | ||
|
||
//--- ImportedInternal.swift | ||
|
||
private func privateFunc() {} | ||
internal func internalFunc() {} | ||
package func packageFunc() {} | ||
public func publicFunc() {} | ||
|
||
//--- ImportedPackage.swift | ||
|
||
private func privateFunc() {} | ||
internal func internalFunc() {} | ||
package func packageFunc() {} | ||
public func publicFunc() {} | ||
|
||
//--- ImportedPublic.swift | ||
|
||
private func privateFunc() {} | ||
internal func internalFunc() {} | ||
package func packageFunc() {} | ||
public func publicFunc() {} | ||
|
||
//--- InPackageClient.swift | ||
|
||
private import ImportedPrivate | ||
internal import ImportedInternal | ||
private import ImportedPackage | ||
public import ImportedPublic // expected-warning{{public import of 'ImportedPublic' was not used in public declarations or inlinable code}} | ||
|
||
ImportedPrivate.privateFunc() // expected-error {{module 'ImportedPrivate' has no member named 'privateFunc'}} | ||
ImportedPrivate.internalFunc() // expected-error {{module 'ImportedPrivate' has no member named 'internalFunc'}} | ||
ImportedPrivate.packageFunc() | ||
ImportedPrivate.publicFunc() | ||
|
||
ImportedInternal.privateFunc() // expected-error {{module 'ImportedInternal' has no member named 'privateFunc'}} | ||
ImportedInternal.internalFunc() // expected-error {{module 'ImportedInternal' has no member named 'internalFunc'}} | ||
ImportedInternal.packageFunc() | ||
ImportedInternal.publicFunc() | ||
|
||
ImportedPackage.privateFunc() // expected-error {{module 'ImportedPackage' has no member named 'privateFunc'}} | ||
ImportedPackage.internalFunc() // expected-error {{module 'ImportedPackage' has no member named 'internalFunc'}} | ||
ImportedPackage.packageFunc() | ||
ImportedPackage.publicFunc() | ||
|
||
ImportedPublic.privateFunc() // expected-error {{module 'ImportedPublic' has no member named 'privateFunc'}} | ||
ImportedPublic.internalFunc() // expected-error {{module 'ImportedPublic' has no member named 'internalFunc'}} | ||
ImportedPublic.packageFunc() | ||
ImportedPublic.publicFunc() | ||
|
||
func funcContext() { | ||
ImportedPrivate.privateFunc() // expected-error {{module 'ImportedPrivate' has no member named 'privateFunc'}} | ||
ImportedPrivate.internalFunc() // expected-error {{module 'ImportedPrivate' has no member named 'internalFunc'}} | ||
ImportedPrivate.packageFunc() | ||
ImportedPrivate.publicFunc() | ||
|
||
ImportedInternal.privateFunc() // expected-error {{module 'ImportedInternal' has no member named 'privateFunc'}} | ||
ImportedInternal.internalFunc() // expected-error {{module 'ImportedInternal' has no member named 'internalFunc'}} | ||
ImportedInternal.packageFunc() | ||
ImportedInternal.publicFunc() | ||
|
||
ImportedPackage.privateFunc() // expected-error {{module 'ImportedPackage' has no member named 'privateFunc'}} | ||
ImportedPackage.internalFunc() // expected-error {{module 'ImportedPackage' has no member named 'internalFunc'}} | ||
ImportedPackage.packageFunc() | ||
ImportedPackage.publicFunc() | ||
|
||
ImportedPublic.privateFunc() // expected-error {{module 'ImportedPublic' has no member named 'privateFunc'}} | ||
ImportedPublic.internalFunc() // expected-error {{module 'ImportedPublic' has no member named 'internalFunc'}} | ||
ImportedPublic.packageFunc() | ||
ImportedPublic.publicFunc() | ||
} | ||
|
||
//--- OutOfPackageClient.swift | ||
|
||
private import ImportedPrivate | ||
internal import ImportedInternal | ||
private import ImportedPackage | ||
public import ImportedPublic // expected-warning{{public import of 'ImportedPublic' was not used in public declarations or inlinable code}} | ||
|
||
ImportedPrivate.privateFunc() // expected-error {{module 'ImportedPrivate' has no member named 'privateFunc'}} | ||
ImportedPrivate.internalFunc() // expected-error {{module 'ImportedPrivate' has no member named 'internalFunc'}} | ||
ImportedPrivate.packageFunc() // expected-error {{module 'ImportedPrivate' has no member named 'packageFunc'}} | ||
ImportedPrivate.publicFunc() | ||
|
||
ImportedInternal.privateFunc() // expected-error {{module 'ImportedInternal' has no member named 'privateFunc'}} | ||
ImportedInternal.internalFunc() // expected-error {{module 'ImportedInternal' has no member named 'internalFunc'}} | ||
ImportedInternal.packageFunc() // expected-error {{module 'ImportedInternal' has no member named 'packageFunc'}} | ||
ImportedInternal.publicFunc() | ||
|
||
ImportedPackage.privateFunc() // expected-error {{module 'ImportedPackage' has no member named 'privateFunc'}} | ||
ImportedPackage.internalFunc() // expected-error {{module 'ImportedPackage' has no member named 'internalFunc'}} | ||
ImportedPackage.packageFunc() // expected-error {{module 'ImportedPackage' has no member named 'packageFunc'}} | ||
ImportedPackage.publicFunc() | ||
|
||
ImportedPublic.privateFunc() // expected-error {{module 'ImportedPublic' has no member named 'privateFunc'}} | ||
ImportedPublic.internalFunc() // expected-error {{module 'ImportedPublic' has no member named 'internalFunc'}} | ||
ImportedPublic.packageFunc() // expected-error {{module 'ImportedPublic' has no member named 'packageFunc'}} | ||
ImportedPublic.publicFunc() | ||
|
||
func funcContext() { | ||
ImportedPrivate.privateFunc() // expected-error {{module 'ImportedPrivate' has no member named 'privateFunc'}} | ||
ImportedPrivate.internalFunc() // expected-error {{module 'ImportedPrivate' has no member named 'internalFunc'}} | ||
ImportedPrivate.packageFunc() // expected-error {{module 'ImportedPrivate' has no member named 'packageFunc'}} | ||
ImportedPrivate.publicFunc() | ||
|
||
ImportedInternal.privateFunc() // expected-error {{module 'ImportedInternal' has no member named 'privateFunc'}} | ||
ImportedInternal.internalFunc() // expected-error {{module 'ImportedInternal' has no member named 'internalFunc'}} | ||
ImportedInternal.packageFunc() // expected-error {{module 'ImportedInternal' has no member named 'packageFunc'}} | ||
ImportedInternal.publicFunc() | ||
|
||
ImportedPackage.privateFunc() // expected-error {{module 'ImportedPackage' has no member named 'privateFunc'}} | ||
ImportedPackage.internalFunc() // expected-error {{module 'ImportedPackage' has no member named 'internalFunc'}} | ||
ImportedPackage.packageFunc() // expected-error {{module 'ImportedPackage' has no member named 'packageFunc'}} | ||
ImportedPackage.publicFunc() | ||
|
||
ImportedPublic.privateFunc() // expected-error {{module 'ImportedPublic' has no member named 'privateFunc'}} | ||
ImportedPublic.internalFunc() // expected-error {{module 'ImportedPublic' has no member named 'internalFunc'}} | ||
ImportedPublic.packageFunc() // expected-error {{module 'ImportedPublic' has no member named 'packageFunc'}} | ||
ImportedPublic.publicFunc() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: split-file %s %t | ||
|
||
/// Build libraries | ||
// RUN: %target-swift-frontend -emit-module %t/LibShared.swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -emit-module-path %t/LibShared.swiftmodule | ||
// RUN: %target-swift-frontend -emit-module %t/LibWithPublicFoo.swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -emit-module-path %t/LibWithPublicFoo.swiftmodule -I %t | ||
// RUN: %target-swift-frontend -emit-module %t/LibWithInternalFoo.swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -emit-module-path %t/LibWithInternalFoo.swiftmodule -I %t | ||
|
||
/// Build client | ||
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \ | ||
// RUN: -enable-library-evolution -swift-version 5 | ||
|
||
//--- LibShared.swift | ||
public struct Struct { | ||
public init() {} | ||
} | ||
|
||
//--- LibWithPublicFoo.swift | ||
import LibShared | ||
|
||
extension Struct { | ||
public func foo() {} | ||
} | ||
|
||
//--- LibWithInternalFoo.swift | ||
import LibShared | ||
|
||
extension Struct { | ||
internal func foo() {} | ||
} | ||
|
||
//--- Client.swift | ||
import LibShared | ||
import LibWithPublicFoo | ||
private import LibWithInternalFoo | ||
|
||
var s = Struct() | ||
s.foo() // This is non-ambiguous |