Skip to content
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

Error should be raised for public typealias with internal generic parameter #73317

Open
CrazyFanFan opened this issue Apr 28, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@CrazyFanFan
Copy link
Contributor

CrazyFanFan commented Apr 28, 2024

Description

When using the following Swift code:

protocol Foo {
    var foo: Int { get }
}

public typealias Alias<T: Foo> = (T) -> Void

A warning is issued:

Type alias should not be declared public because its generic parameter uses an internal type.

However, I believe this should be an error instead of a warning.

Upon examining the source code, I discovered a FIXME comment indicating that there are plans to promote this warning to an error in a future -swift-version break:

// swift/lib/Sema/TypeCheckAccess.cpp:line:491
// FIXME: Promote these to an error in the next -swift-version break.
if (isa<SubscriptDecl>(ownerDecl) || isa<TypeAliasDecl>(ownerDecl))
    downgradeToWarning = DowngradeToWarning::Yes;

Furthermore, when BUILD_LIBRARY_FOR_DISTRIBUTION is set to YES, this issue leads to module verifier failures. The inconsistent behavior between the two scenarios adds to the problem.

Reproduction

protocol Foo {
    var foo: Int { get }
}

public typealias Alias<T: Foo> = (T) -> Void

Expected behavior

The warning should be upgraded to an error for the public typealias with an internal generic parameter. This change would ensure consistency and prevent module verifier failures when building libraries for distribution.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0a

Additional information

No response

@CrazyFanFan CrazyFanFan added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant