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-5959] Compilation issue after migrating from Xcode 8.3 to Xcode 9 #48518

Closed
swift-ci opened this issue Sep 21, 2017 · 4 comments
Closed

[SR-5959] Compilation issue after migrating from Xcode 8.3 to Xcode 9 #48518

swift-ci opened this issue Sep 21, 2017 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.0 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5959
Radar rdar://problem/34596043
Original Reporter alexmx (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 9.0 (9A235)

macOS Sierra 10.12.6

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.0Regression, ClangImporter, TypeChecker
Assignee @belkadan
Priority Medium

md5: 6ae8222c8069cd64edfa5fa1d163e628

Issue Description:

Xcode 9 fails to compile the code which was compiling just fine in Xcode 8.3

Attached a reduced use case.

There is an Objective-C category which implements a protocol. The protocol defines two methods, one class method and one instance method with the same signature.

Example:

@protocol SomeProtocol <NSObject>

+ (void)amx_doSomething;
- (void)amx_doSomething;

@end

@interface UILabel (Utils) <SomeProtocol>
@end 

This category is used in a Swift class:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        UILabel.amx_doSomething()
    }
}

Xcode 9 shows a compilation issue:

16:17: error: instance member 'amx_doSomething' cannot be used on type 'UILabel'; did you mean to use a value of this type instead?
        UILabel.amx_doSomething()
        ~~~~~~~ ^

The simple workaround is to change the order in which the methods are declared in the protocol, from this:

@protocol SomeProtocol <NSObject>

+ (void)amx_doSomething;
- (void)amx_doSomething;

@end

To this:

@protocol SomeProtocol <NSObject>

- (void)amx_doSomething;
+ (void)amx_doSomething;

@end

After this change the code compiles just fine.

@belkadan
Copy link
Contributor

Possibly type checker, possibly importer. @swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Alex Maimescu (JIRA)

The mentioned in description workaround just fixes the static method invocation, but breaks it for instances:

error: static member 'amx_doSomething' cannot be used on instance of type 'UILabel'
        labelSample.amx_doSomething()

@belkadan
Copy link
Contributor

#13100

@belkadan
Copy link
Contributor

Merged in f5989d2, will make it into Swift 4.1.

@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 regression swift 4.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants