-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swift 6 mode converts decl_from_hidden_module diagnostics to errors, from warnings #78297
Comments
Yes, it's intentional that these are errors in Swift 6. Access level on imports is a feature available in the Swift 6 compiler, even though |
Should those still be errors then if the code isn't being built with |
Yes, in general we don't want library evolution to create a language dialect, and the error really makes sense semantically regardless of library evolution mode. |
Can I turn this around and ask why it being an error a problem? It should be very simple to resolve (just add the missing import), and new language modes are often leveraged as the opportunity to fix existing gaps in type checking. |
It's not that I disagree with the error or what it's going for (and I agree that we don't want library evolution to be a dialect). I was just surprised because it was a source-breaking error specifically when enabling Swift 6 language mode that didn't appear to be tied to and staged in via an upcoming feature flag, and I couldn't recall it being broadcast as one of the breaking changes for users to expect. That's the main reason I was wondering if it was intentional, especially since some of the other import visibility changes were pulled back from being enforced in Swift 6. |
I noticed there's some inconsistency with this diagnostic when using a typealias in the "middle" module, // helpers.swift
public typealias ExportType = ExportedP
public typealias CompoundType = ExportedP & Hashable
struct Foo: ExportedP, Hashable {}
public func makeProtocol() -> ExportType { Foo() }
public func makeProtocol2() -> any CompoundType { Foo() } // api.swift
import helpers
public struct API {
public let p = makeProtocol()
public let c = makeProtocol2()
} The diagnostic flags the first property, The diagnostic doesn't flag anything on the second property, |
Description
Prior to Swift 6, there has been a warning on public declarations that use a type that is not imported in the current file. This warning is the diagnostic decl_from_hidden_module. I believe this diagnostic is notifying the user about possibly exposing types from a Swift module that doesn't directly import the exposed type.
This became more tightly enforced as an error with Swift 6 mode. Because this is an error, additional imports are required in the source file(s) to satisfy this diagnostic. That is possibly a source breaking change. Is the change in severity intended?
Reproduction
This issue can be reproduced with 3 Swift modules.
decls
.decls
; call ithelpers
.decls
; call itapi
.Compile the modules in order:
decls
,helpers
, thenapi
:Expected behavior
I believe this should generate a warning in
api.swift
:Instead the diagnostic is raised as an error when using
-swift-version 6
. Without swift-version 6, the diagnostic is a warning.Environment
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: