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-8697] Xcode 10 missing type specifier when converting Swift to objc #51210

Closed
swift-ci opened this issue Sep 5, 2018 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PrintAsClang Area → compiler: The PrintAsClang library

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 5, 2018

Previous ID SR-8697
Radar rdar://problem/43347303
Original Reporter kerrmarin (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10 beta 6, using Swift 4

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

md5: 0da0e6bcb053aec2d0b1777c1971af56

Issue Description:

Apologies in advance if this doesn't belong here, but I wanted to create the issue just in case. I also added the 'Tooling' flag to this but i presume that's wrong.

When creating a Swift class with a function annotated with @objc, and that function receives as a parameter a generic associated type that will translate into an objc primitive, the conversion in the *-Swift.h file has nullability specifiers that prevent it from compiling.

Steps to Reproduce:

Given the following setup:

public struct Identifier<T, RawIdentifier> : Hashable, RawRepresentable, Codable where RawIdentifier : Decodable, RawIdentifier : Encodable, RawIdentifier : Hashable {
    /// Identifier's raw value.
    public let rawValue: RawIdentifier 
    /// Creates a new `Identifier`.
    public init(rawValue: RawIdentifier) {
        self.rawValue = rawValue
    }
}

public protocol Identifiable {
    associatedtype RawIdentifier: Hashable & Codable = UInt64
    var id: Identifier<Self, RawIdentifier> { get }
}

public struct Member: Identifiable {
    public var id: Identifier<Member, UInt64>
}

public typealias MemberID = Identifier<Member, UInt64>

When we create a class that exposes an @objc convenience initializer like:

class Tab {}

extension Tab {
    /// Convenience ObjC initializer.
    @objc public convenience init(memberID: MemberID.RawValue, title: String) {
        // Implementation of this method
    }
}

The generated *-Swift.h file contains the following method signature:

- (nonnull instancetype)initWithMemberID:( _Nonnull)memberID title:(NSString * _Nonnull)title;

Which obviously doesn't compile because it's missing the type specifier:

warning: type specifier missing, defaults to 'int'

and that won't compile either because you can't apply _Nonnull to a primitive type.

Expected Results: The method will be translated to objc successfully (in this case it would be something like:

- (nonnull instancetype)initWithMemberID:(int64_t)memberID title:(NSString * _Nonnull)title;

Actual Results:

The generated *-Swift.h file contains the following method signature:

- (nonnull instancetype)initWithMemberID:( _Nonnull)memberID title:(NSString * _Nonnull)title; 
@belkadan
Copy link
Contributor

belkadan commented Sep 5, 2018

Fixed in master in #18941 (but not going to make 4.2, sorry)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Sep 5, 2018

Comment by Kerr Marin Miller (JIRA)

Thanks for the quick response Jordan. Shame it won't be in 4.2 🙁!

@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 PrintAsClang Area → compiler: The PrintAsClang library
Projects
None yet
Development

No branches or pull requests

2 participants