Skip to content

[SR-7104] Crash when running getTasksWithCompletionHandler on URLSession, where a new completion is protocol based #49652

@swift-ci

Description

@swift-ci
Previous ID SR-7104
Radar None
Original Reporter breiflabb (JIRA User)
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Environment

Swift: 4.0.3

Target os: tvOS 11.2.6

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

md5: 83c5c391bc74a082aa143aad924d29fe

Issue Description:

Given a protocol 'A' which URLSessionDataTask and URLSessionDownloadTask conforms to.

protocol A {}
extension URLSessionDataTask: A{}
extension URLSessionDownloadTask: A {}

App will crash if one passes results from getTasksWithCompletionHandler (DataTask, UploadTask, DownloadTask) to a completion handler which takes three parameters respectively (A, A, A). Like so:

func handleTasks(data: [A], upload: [A], download: [A]) {

}

URLSession.shared.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in 
    handleTasks(data: dataTasks, upload: uploadTasks, download: downloadTasks)
}

The app will not crash if a single conformance for URLSessionTask is made.

extension URLSessionTask : A {}

Attached 2 playgrounds to demonstrate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions