Keep Swift call names so a different callee scores lower.

Renamed locals already matched, and so did filter versus select,
because a Swift call keeps its name in a call_suffix and the name
is a simple_identifier. Both were treated as ordinary words, so the
callee disappeared and the score stayed 1.0.

simple_identifier is a name, and call_suffix is the argument list, the
same two decisions the other languages already make.

Proved: test_a_different_swift_callee_is_not_the_same_structure failed
on a score of 1.0, then passed with the pair below 1.0. The renamed-local
pair still scores 1.0. The full suite passed, 82 tests.

Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
Cursor Agent
2026-11-25 23:28:45 +00:00
co-authored by Robert C. Martin
parent a37f7d1827
commit 16b5db55b2
2 changed files with 22 additions and 1 deletions
+2 -1
View File
@@ -28,6 +28,7 @@ _IDENTIFIERS = {
"shorthand_property_identifier", "shorthand_property_identifier",
"shorthand_property_identifier_pattern", "shorthand_property_identifier_pattern",
"package_identifier", "package_identifier",
"simple_identifier",
} }
_LITERALS = { _LITERALS = {
@@ -134,7 +135,7 @@ _SCOPED = {
"scoped_type_identifier", "scoped_type_identifier",
} }
_ARG_LISTS = {"argument_list", "arguments"} _ARG_LISTS = {"argument_list", "arguments", "call_suffix"}
_TYPE_ARGS = {"type_arguments", "type_parameters"} _TYPE_ARGS = {"type_arguments", "type_parameters"}
_DATA: bytes = b"" _DATA: bytes = b""
+20
View File
@@ -38,3 +38,23 @@ def test_renamed_locals_in_swift_functions_match(tmp_path):
assert [(item.language, item.left.file, item.right.file, item.score) for item in found] == [ assert [(item.language, item.left.file, item.right.file, item.score) for item in found] == [
("swift", "left.swift", "right.swift", 1.0) ("swift", "left.swift", "right.swift", 1.0)
] ]
def test_a_different_swift_callee_is_not_the_same_structure(tmp_path):
write_source(tmp_path, "left.swift", SWIFT_LEFT)
write_source(
tmp_path,
"right.swift",
"""\
func beta(items: [Int]) -> [Int] {
let kept = select(items, even)
return collect(kept, dec)
}
""",
)
files = sorted(tmp_path.glob("*.swift"))
entries, warnings = scan_files(files, tmp_path, min_lines=1, min_nodes=1)
assert warnings == []
found = find_duplicates(entries, threshold=0.0)
assert len(found) == 1
assert found[0].score < 1.0