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 type access level not enforced for property getters #79992

Open
lawrence-forooghian opened this issue Mar 13, 2025 · 0 comments
Open

Error type access level not enforced for property getters #79992

lawrence-forooghian opened this issue Mar 13, 2025 · 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

@lawrence-forooghian
Copy link

Description

Given a protocol that has a property getter which throws a typed error, the compiler does not check whether the access level of the error type is compatible with that of the protocol.

Reproduction

internal enum MyError: Error {}

public protocol MyProtocol {
    var foo: String { get throws(MyError) }
}

Expected behavior

I expected a compiler error telling me that the property cannot be declared public because its thrown error uses an internal type. However, instead the code compiles without error.

If I switch the property to a function, then I get the expected error:

internal enum MyError: Error {}

public protocol MyProtocol {
    func bar() throws(MyError) -> String
}

gives "method cannot be declared public because its thrown error uses an internal type".

Environment

Tried with the following:

Xcode 16.1:

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

Xcode 16.3 Beta 2:

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.109.103 clang-1700.0.13.2)
Target: arm64-apple-macosx15.0

Additional information

No response

@lawrence-forooghian lawrence-forooghian added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 13, 2025
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