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-9479] Subclasses of generic classes don't remember @objc names for optional protocol methods #51941

Open
ahti opened this issue Dec 12, 2018 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@ahti
Copy link
Contributor

ahti commented Dec 12, 2018

Previous ID SR-9479
Radar rdar://problem/30489065
Original Reporter @ahti
Type Bug
Environment

macOS Mojave, both in Swift 4.2 and the 2018-12-09 5.0 snapshot.

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

md5: cbac37027cfe1a9f7b7ec5f6d6688217

is duplicated by:

  • SR-10832 Generic encapsulating type erases optional protocol methods

Issue Description:

I need to manually specify @objc names for optional methods in a protocol implemented by a generic superclass.

Example:

import Foundation

@objc protocol P {
    @objc(doF) optional func f() -> Int
}

class Gen<T>: NSObject, P {}
class NoGen:  NSObject, P {}

class NoGen1: NoGen {
    func f() -> Int {
        return 42
    }
}
(NoGen1() as P).f?() // 42, works

class Gen1: Gen<Any> {
    func f() -> Int {
        return 42
    }
}
(Gen1() as P).f?() // nil <----------

class Gen2: Gen<Any> {
    @objc(doF) func f() -> Int { // explicitly set objc name
        return 42
    }
}
(Gen2() as P).f?() // 42, works again
@belkadan
Copy link
Contributor

I suspect they're not being inferred as @objc at all, but either way it's a problem! Thanks, Lukas.

@belkadan
Copy link
Contributor

@DougGregor, did you have a Radar for this already?

@belkadan
Copy link
Contributor

belkadan commented Jun 5, 2019

Also applies to classes nested in generic contexts, even if they themselves are not generic (see dup).

@belkadan
Copy link
Contributor

belkadan commented Aug 1, 2019

The problem here seems to be in swift::findWitnessedObjCRequirements:

// If we have an optional requirement in an inherited conformance,
// check whether the potential witness matches the requirement.
// FIXME: for now, don't even try this with generics involved. We
// should be tracking how subclasses implement optional requirements,
// in which case the getWitness() check above would suffice.

I don't know what the context is here, though.

@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 in itself
Projects
None yet
Development

No branches or pull requests

2 participants