Skip to content

InternalImportsByDefault issue on Swift 6.0 Toolchain #81248

Closed
@Kyle-Ye

Description

@Kyle-Ye

InternalImportsByDefault is a feature flag which can be opt-in since Swift 5.9.

And I just noticed it has some strange bug behavior occurring on Swift 6.0 toolchain.

Description

If you enable InternalImportsByDefault as a upcoming feature, you will be able to use other package's package API even you are not in the same package.

Example 1:
We have Demo and DemoKit package, and Demo has a dependency on DemoKit.

Both Demo and DemoKit is build by Swift 6.0 compiler with Swift 5/6 mode does not matter.

It will be buildable that Demo use DemoKit's package API if we are using Xcode 16.0 with Swift 6.0 compiler.

Example 2:

The same thing applies for the system framework.

SwiftUI.framework & SwiftUICore.framework has some @inlinable package API in its public interface.

We can also call it directly on Demo package if we enable InternalImportsByDefault and compile it under Xcode 16.0 with Swift 6.0 compiiler.

// SwiftUICore.swiftmodule
extension CoreFoundation.CGSize {
  @available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
  @inlinable package var hasZero: Swift.Bool {
    get { width == 0.0 || height == 0.0 }
  }
}
import SwiftUI
let size = CGSize()
print(size.hasZero)

Image

Reproduction

Demo.zip

See Demo package in the attachment.

Expected behavior

Not able to call package API in other package and fail to compile.

Environment

swiftc -version
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Additional information

The bug seem to be fixed on Swift 6.1 / Xcode 16.3.

But I did not find any existing issue or test case covering it in the Swift repo.

cc @xymus

Metadata

Metadata

Assignees

No one assigned

    Labels

    access controlFeature → modifiers: Access control and access levelsbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions