swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.61k stars 10.37k forks source link

[SR-8059] Migrator adds unnecessary functions when dealing with UIBackgroundTaskIdentifier #50592

Open keith opened 6 years ago

keith commented 6 years ago
Previous ID SR-8059
Radar None
Original Reporter @keith
Type Bug
Status Reopened
Resolution

Attachment: Download

Environment Xcode 10.0 beta 2 (10L177m)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Source Tooling | |Labels | Bug, Migrator | |Assignee | @nkcsgexi | |Priority | Medium | md5: 894c9c2b831afe650601702c7593f5c9

Issue Description:

When you migrate this Swift 4.1 code:

let taskID = UIApplication.shared.beginBackgroundTask {}
UIApplication.shared.endBackgroundTask(taskID)

You end up with this 4.2 code:

let taskID = convertFromUIBackgroundTaskIdentifier(UIApplication.shared.beginBackgroundTask {})
UIApplication.shared.endBackgroundTask(convertToUIBackgroundTaskIdentifier(taskID))

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromUIBackgroundTaskIdentifier(_ input: UIBackgroundTaskIdentifier) -> Int {
    return input.rawValue
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToUIBackgroundTaskIdentifier(_ input: Int) -> UIBackgroundTaskIdentifier {
    return UIBackgroundTaskIdentifier(rawValue: input)
}

The original code compiles correctly with Swift 4.2. Migrate the attached project for an example. This is similar to https://bugs.swift.org/browse/SR-8057

belkadan commented 6 years ago

@nkcsgexi, did you have a bug for this already?

nkcsgexi commented 6 years ago

Unfortunately, migrator currently has no comprehensive static analysis capability to simplify this migration pattern.

nkcsgexi commented 6 years ago

The requested optimization is beyond the current static analysis capability of migrator.

NachoSoto commented 6 years ago

Well, isn't that why a bug was filed?

nkcsgexi commented 6 years ago

this bug is a totally reasonable request. We resolved it because it's hard for migrator to fix it at this point 🙂

tonyarnold commented 6 years ago

But it's not resolved - why not leave the bug open as an indication that it's something the migrator should be able to handle?

nkcsgexi commented 6 years ago

@tonyarnold sounds good! let's re-open it on migrator for future reference.