Skip to content

[SR-3111] Private top-level extensions cannot contain fileprivate members #45699

@karwa

Description

@karwa
Previous ID SR-3111
Radar None
Original Reporter @karwa
Type Bug
Environment

Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 9cf9a32b39718d5dd45d91c24a104529

Issue Description:

As I understand it, private at top-level is synonymous with fileprivate; so the following code should be fine. In practice the compiler won't have it.

struct MyStruct {
    init() { doSomething() }
}

private extension MyStruct {
    fileprivate func doSomething() { print("doing something...") }
}
test.swift:22:5: warning: declaring a fileprivate instance method in a private extension
    fileprivate func doSomething() { print("doing something...") }
    ^~~~~~~~~~~
    private
test.swift:18:14: error: 'doSomething' is inaccessible due to 'private' protection level
    init() { doSomething() }
             ^
test.swift:22:22: note: 'doSomething()' declared here
    fileprivate func doSomething() { print("doing something...") }
                     ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions