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-4014] Can't Call Overloaded Method Within Another Overloaded Method #46599

Open
swift-ci opened this issue Feb 21, 2017 · 5 comments
Open
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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4014
Radar None
Original Reporter Andy (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode Version 8.3 beta 3 (8W132p)
Xcode Version 8.2.1 (8C1002)
macOS Sierra 10.12.3

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

md5: 076e7ba1d75c403b3cc508d17be38368

relates to:

  • SR-2657 error: '(f: () -> ())' is not convertible to '(f: () -> ())'

Issue Description:

It looks like Swift is currently having issues calling overloaded methods within overloaded methods.

Case in point:

I have the following method:

    @available(*, introduced: 1.0) final public func activity(_ name: String, page: Int = 1, completionHandler completion: @escaping Anilist.API.APIArrayResponseHandler<Activity>) {
        log("Getting activity info for \(name), page \(page)")
        let usableUsername = name.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
        let path = "user/\(usableUsername)/activity"
        self.associatedSession?.api.performAPITaskGET(path: path, getParameters: ["page" : "\(page)"], completionHandler: nil, completionHandlerArray: completion)
    }

This method has the signature `activity(_ name: String, page: Int, completionHandler: Anilist.API.APIArrayResponseHandler<Activity>`. We will call this the "String version of Activity".

I have this other method which is simply a convenience method to call the above one with an integer as the "name" parameter.

    @available(*, introduced: 1.0) final public func activity(_ id: Int, page: Int = 0, completionHandler completion: Anilist.API.APIArrayResponseHandler<Activity>) {
        self.activity("\(id)", page: page, completionHandler: completion)
    }

Which like you can see, is just an overload of the method I posted earlier. `activity(id: Int, page: Int, completionHandler: Anilist.API.APIArrayResponseHandler<Activity>`. We will call this "Int version of Activity".

On the line where I try to call the "String version of Activity", Swift complains:

"Cannot convert value of type 'String' to expected argument of type 'Int'"

Basically, this method call wants to call itself recursively and does not see there's a different version in the same scope.

Unfortunately, I have no idea when this broke. I wrote this code in the Xcode 8.0/Swift 3.0 beta days and it used to work fine. If memory serves me right, this error started happening on the final release of Xcode 8.0 and Swift 3.0

I need to note that autocompletion works fine. When typing `self.activity...` within the "Int Version of Activity" autocompletion shows and completes the "String version of Activity" and inserts it there. So this is most likely a compiler bug.

@belkadan
Copy link
Contributor

It's a bad error message, but you forgot to mark your overload's completion handler as @escaping.

@belkadan
Copy link
Contributor

@rudkx, @slavapestov, @milseman, do we have something tracking this already?

@swift-ci
Copy link
Collaborator Author

Comment by Andy Ibanez (JIRA)

Thanks Jordan, you are entirely right.

Somewhere along the migration, Xcode failed to see a few missing @escaping clauses (it did suggest the majority of them though). My code currently has three places where this happens but I will fix them in a flash now.

@milseman
Copy link
Mannequin

milseman mannequin commented Feb 21, 2017

@belkadan is https://bugs.swift.org/browse/SR-2657 the same issue?

@belkadan
Copy link
Contributor

Certainly related, but that just shows there is a good diagnostic and it's not kicking in. I suspect the reasons are different.

@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 diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants