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-1019] Can't use the new #selector syntax for generic types #43631

Open
swift-ci opened this issue Mar 22, 2016 · 3 comments
Open

[SR-1019] Can't use the new #selector syntax for generic types #43631

swift-ci opened this issue Mar 22, 2016 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself good first issue Good for newcomers

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-1019
Radar None
Original Reporter JamieWhite (JIRA User)
Type Bug
Environment

xcode 7.3
Swift 2.2

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: 5685a8e13e6f20612a2c6754c850cfe2

Issue Description:

I have an example here: https://gist.github.com/JamieWhite/72e0f7406a33d8e52657/51032655f639d9f92042ed7c02d0ee6c9e22790f

You'll notice this:

addTarget(trampoline, action: #selector(ActionTrampoline.action(_:)), forControlEvents: events)

ActionTrampoline is generic type. How this should work is doing this:

addTarget(trampoline, action: #selector(ActionTrampoline<Self>.action(_:)), forControlEvents: events)

How I worked around this was typeAliasing ActionTrampoline<self> and using that in the #selector like this:

https://gist.github.com/JamieWhite/72e0f7406a33d8e52657/fb010c8c0403725e431880b9dc6253dafc0c3b35

@swift-ci
Copy link
Contributor Author

swift-ci commented May 1, 2016

Comment by Mark Sands (JIRA)

JamieWhite (JIRA User) You can specify the generic type in your selector. Add <UIControl> in the failing line:

addTarget(trampoline, action: #selector(ActionTrampoline<UIControl>.action(_:)), forControlEvents: events)

@swift-ci
Copy link
Contributor Author

swift-ci commented May 1, 2016

Comment by Mark Sands (JIRA)

I created a radar for Xcode here 26031273, or reach out to me on twitter @marksands if someone from Apple actually wants to provide feedback 😉

FYI, a very simple test case to break Xcode's current behavior is this:

import Foundation

class TestClass<T> {
    let testSelector: Selector = "action" // Xcode should convert to #selector(TestClass<T>.action)
    @objc func action() { }
}

@CodaFi
Copy link
Contributor

CodaFi commented May 31, 2016

I have a patch, but the worrying thing about fixing this is that the fixit is still "wrong" in a lot of cases. Where before (replace without the generic param list) we would complain about not knowing how to, say, instantiate T in TestClass, now we get a fully spelled out type with an undeclared generic type parameter in it. Essentially: In non-generic contexts the fixit is just shuffling one error around for another.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 itself good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants