Navigation Menu

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

[SR-15691] Invalid warning: 'self' refers to the method 'Foo.self' #57970

Closed
keith opened this issue Jan 5, 2022 · 2 comments · Fixed by #41520
Closed

[SR-15691] Invalid warning: 'self' refers to the method 'Foo.self' #57970

keith opened this issue Jan 5, 2022 · 2 comments · Fixed by #41520
Labels
backticked identifiers Feature → identifiers: Backticked identifiers. Allows using reserved words as identifiers bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself enum cases Feature → enums: Enum cases enum Feature → type declarations: Swift enumeration declarations expressions Feature: expressions identifiers Feature: Identifiers self Feature → expressions: The 'self' expression swift 5.6 type checker Area → compiler: Semantic analysis unexpected warning Bug: Unexpected warning

Comments

@keith
Copy link
Collaborator

keith commented Jan 5, 2022

Previous ID SR-15691
Radar None
Original Reporter @keith
Type Bug
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 92266992a8216159c3017c1eaba44660

Issue Description:

With this code and Swift 5.5, it compiled fine:

enum Foo {
    case `self`

    init() {
        self = .self
    }
}

With the 2021-12-23 main snapshot (org.swift.50202112231a) compiling gives an seemingly impossible to silence warning, here are the variations I tried:

enum Foo {
    case `self`

    init() {
        // This option produces:
        // /tmp/qux.swift:5:17: warning: 'self' refers to the method 'Foo.self', which may be unexpected
        //         self = .self
        //                 ^
        // /tmp/qux.swift:5:17: note: use 'Foo.self' to silence this warning
        //         self = .self
        //                 ^
        //                 Foo.
        self = .self

        // This option fails to compile
        // /tmp/qux.swift:15:16: error: cannot assign value of type 'Foo.Type' to type 'Foo'
        //         self = Foo.self
        //                ^~~~~~~~
        // self = Foo.self

        // This option produces:
        // /tmp/qux.swift:22:20: warning: 'self' refers to the method 'Foo.self', which may be unexpected
        //         self = Foo.`self`
        //                    ^
        // /tmp/qux.swift:22:20: note: use 'Foo.self' to silence this warning
        //         self = Foo.`self`
        //                    ^
        //                    Foo.
        self = Foo.`self`
    }
}

I believe this might have been introduced as the fix for #47136 here 7e0a7f3

cc jackmarch (JIRA User)

@keith
Copy link
Collaborator Author

keith commented Feb 23, 2022

I've submitted #41520 which I hope is a reasonable fix for this

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@keith keith closed this as completed Apr 29, 2023
@keith
Copy link
Collaborator Author

keith commented Apr 29, 2023

Fixed in Swift 5.6

@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler in itself label May 2, 2023
@AnthonyLatsis AnthonyLatsis added type checker Area → compiler: Semantic analysis expressions Feature: expressions unexpected warning Bug: Unexpected warning swift 5.6 backticked identifiers Feature → identifiers: Backticked identifiers. Allows using reserved words as identifiers enum Feature → type declarations: Swift enumeration declarations enum cases Feature → enums: Enum cases identifiers Feature: Identifiers self Feature → expressions: The 'self' expression labels May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backticked identifiers Feature → identifiers: Backticked identifiers. Allows using reserved words as identifiers bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself enum cases Feature → enums: Enum cases enum Feature → type declarations: Swift enumeration declarations expressions Feature: expressions identifiers Feature: Identifiers self Feature → expressions: The 'self' expression swift 5.6 type checker Area → compiler: Semantic analysis unexpected warning Bug: Unexpected warning
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants