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

**URL:** <https://forums.swift.org/t/sr-14244-tuple-containing-one-or-more-closures-is-expanded-incorrectly-in-source-editor/44889>\
**Category:** SourceKit-LSP\
**Tags:** xcode, sourcekit, tuple, closure\
**Created:** [February 18, 2021, 9:07pm UTC](https://forums.swift.org/t/sr-14244-tuple-containing-one-or-more-closures-is-expanded-incorrectly-in-source-editor/44889 "2021-02-18T21:07:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![orchetect](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/orchetect/32/5098_2.png) [@orchetect](https://forums.swift.org/u/orchetect)\
**Post date:** [February 18, 2021, 9:07pm UTC](https://forums.swift.org/t/sr-14244-tuple-containing-one-or-more-closures-is-expanded-incorrectly-in-source-editor/44889/1 "2021-02-18T21:07:32Z")

</div>

I stumbled on a source parsing bug affecting Xcode's parameter expansion, and from my vetting of JIRA and the forums I don't think it's been reported yet, so I [dropped a bug report into JIRA](https://bugs.swift.org/browse/SR-14244) outlining this behavior.

## 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

 ![simple](https://global.discourse-cdn.com/swift/original/2X/7/7934391b22348dd35cc3907ebe8bb114a80f54f4.png)

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

```

_incorrectly_ expands as:

```
someMethod {
    <#code#>
}

```

but _should_ expand as:

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

```

## Example 2

 ![complex](https://global.discourse-cdn.com/swift/original/2X/d/d7c6a402d8901864466386bd61d1f7d82e52afbe.png)

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

```

_incorrectly_ expands as:

(notice the first `int: Int` parameter disappears and the closures become erroneously merged, with the return type taken from the 2nd closure)

```
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#>
}))

```
