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-5856] Error claims a protocol is a generic type, but no generics are used #48426

Closed
swift-ci opened this issue Sep 7, 2017 · 8 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 7, 2017

Previous ID SR-5856
Radar None
Original Reporter BenLeggiero (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee matt baranowski (JIRA)
Priority Medium

md5: 1eea87b8a1fe05b63eade321219bac87

Issue Description:

I am wishing to implement a pattern similar to Notification.Name where anyone can add one later via an extension, like this:

public protocol Foo {
    var bar: String { get }
}



public struct FooImpl: Foo {
    public let bar: String
}



public extension Foo {
    public static let baz: Foo = FooImpl(bar: "baz")
}

This seems fine to me, but I get a confusing error when compiling:

/path/to/main.swift:24:23: error: static stored properties not supported in generic types
    public static let baz: Foo = FooImpl(bar: "baz")
           ~~~~~~     ^
@belkadan
Copy link
Contributor

belkadan commented Sep 8, 2017

Oops, good catch. Tagging this as a starter bug: there should be a special message for extensions of protocols. This means:

1. Finding out where this message is defined (look in include/swift/AST/DiagnosticsXXXX.def)
2. Adding a new boolean argument to the diagnostic.
3. Changing it to use "%select{generic types|protocol extensions}n" instead of just "generic types", where "n" is the index of the new argument. (See docs/Diagnostics.md.)
4. Updating everywhere in the compiler that references this diagnostic to check specifically for a protocol extension. (DeclContext has the methods you'll need.)
5. Add Ben's test case to the same file where the existing diagnostic is tested, and make sure it gives the new message!

@belkadan
Copy link
Contributor

Ah, I tried to mention that above. You'd get "static stored properties not supported in generic types" in the normal case and "static stored properties not supported in protocol extensions" otherwise.

@swift-ci
Copy link
Collaborator Author

Comment by Oscar Swanros (JIRA)

Yeah, figured it out once I saw the code lol.

I think I'll have a PR soon.

@swift-ci
Copy link
Collaborator Author

Comment by Oscar Swanros (JIRA)

Do you have any idea where the test could be? Been greppin' around but can't find anything.

@swift-ci
Copy link
Collaborator Author

Comment by Oscar Swanros (JIRA)

Found it in test/decl/properties

@swift-ci
Copy link
Collaborator Author

Comment by Matthew Baranowski (JIRA)

swanros (JIRA User) apologies, I assumed the ticket was available and grabbed it after talking to Robin Kunde who also assigned himself within minutes of me. Here is my PR: #11930 This is my first attempt to contribute to swift so my solution may be lacking. I'd appreciate any feedback of course, or to compare notes with your effort.

@swift-ci
Copy link
Collaborator Author

Comment by Oscar Swanros (JIRA)

Uh, bummer. I just submitted mine... #11934 — we actually did the same thing.

/shrug

@belkadan
Copy link
Contributor

Matthew's PR got merged a few weeks ago; marking as Resolved.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants