Keep the label on a Swift trailing closure.

The grammar puts that label on the call as an identifier, so label:
and action: scored 1.0. The spelling now stays, as a parenthesized
argument label does. A closure body still drops its locals.

Proved by test_a_trailing_closure_label_is_part_of_the_call.

Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
Cursor Agent
2026-11-25 23:49:45 +00:00
co-authored by Robert C. Martin
parent 121fb2f4ba
commit 105ff6f50c
3 changed files with 48 additions and 3 deletions
+37
View File
@@ -131,6 +131,43 @@ def test_a_swift_argument_label_is_part_of_the_call(tmp_path):
) < 1.0
def test_a_trailing_closure_label_is_part_of_the_call(tmp_path):
labeled = """\
func alpha() -> Int {
return Button {
save()
} label: {
Text(title)
}
}
"""
renamed = """\
func beta() -> Int {
return Button {
save()
} label: {
Text(heading)
}
}
"""
relabeled = """\
func beta() -> Int {
return Button {
save()
} action: {
Text(title)
}
}
"""
assert _scored(tmp_path, labeled, renamed) == 1.0
assert _scored(tmp_path, labeled, relabeled) < 1.0
assert _scored(
tmp_path,
"func alpha(xs: [Int]) -> [Int] {\n return xs.filter { item in\n odd(item)\n }\n}\n",
"func beta(items: [Int]) -> [Int] {\n return items.filter { value in\n odd(value)\n }\n}\n",
) == 1.0
def test_swift_literals_normalize_and_interpolation_does_not(tmp_path):
assert _scored(
tmp_path,