swiftlang / swift

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

[SR-14244] Tuple containing one or more closures is expanded incorrectly in source editor #60693

Open swift-ci opened 3 years ago

swift-ci commented 3 years ago
Previous ID SR-14244
Radar rdar://problem/74617017
Original Reporter orchetect (JIRA User)
Type Bug

Attachment: Download

Environment Xcode 12.5 beta (12E5220o), Swift 5.3/5.4
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | CodeCompletion, SourceKit-LSP | |Labels | Bug, Parser, TypeChecker | |Assignee | None | |Priority | Medium | md5: 7b3e32b05c391b343b357d6ddce792e5

Issue Description:

Observed Behavior: When a function parameter is a tuple containing one or more closure signatures, pressing Return while its placeholder is highlighted in Xcode's source editor produces incorrect code template expansion. All other parameters in the tuple are ignored. If the closure signatures have an empty (()) input pattern, then only the first closure found is expanded. If the the closures expect an input value, then those input values are erroneously aggregated and applied to a single expanded closure.

Expected behavior: The expansion should expand the tuple's signature completely, and for any closures it encounters it should produce fully labelled and parameterized closure structures.

Example 1:

func someMethod(closures: (closure1: () -> Void,
                           closure2: () -> Void)) { }

incorrectly expands as:

someMethod {
    <#code#>
}

but should expand as:

someMethod(closures: (closure1: {
    <#code#>
}, closure2: {
    <#code#>
}))

Example 2:

func someMethod(closures: (int: Int,
                           closure1: (Double) -> Data,
                           closure2: (String, Int) -> Float32)) { }

incorrectly expands as:

someMethod { (<#Double#>, <#String#>, <#Int#>) -> Float32 in
    <#code#>
}

but should expand as:

someMethod(closures: (int: <#Int#>, closure1: { (<#Double#>) -> Data in
    <#code#>
}, closure2: { (<#String#>, <#Int#>) -> Float32 in
    <#code#>
}))
typesanitizer commented 3 years ago

@swift-ci create