Compare a deinit the way other Swift methods are compared.

A deinit has a body, and a function nested inside it was being reported
on its own. The deinit is now the candidate, and the nested function
stays inside it. Actor methods are documented with the other type methods.

Proved by test_a_deinit_is_compared_and_keeps_its_nested_function.

Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
Cursor Agent
2026-11-25 23:51:01 +00:00
co-authored by Robert C. Martin
parent 105ff6f50c
commit 2862b8428e
4 changed files with 39 additions and 6 deletions
+30
View File
@@ -372,6 +372,36 @@ def test_a_swift_package_skips_its_tests(tmp_path):
assert relative == ["Sources/App.swift"]
def test_a_deinit_is_compared_and_keeps_its_nested_function(tmp_path):
source = """\
class Panel {
deinit {
func hidden() -> Int {
return cache()
}
close(handle)
}
func stop() {
close(handle)
}
}
"""
entries, warning = entries_in_source("swift", source, "Panel.swift", "Panel.swift")
assert warning is None
assert [(entry.start_line, entry.end_line) for entry in entries] == [(2, 7), (9, 11)]
assert _scored(
tmp_path,
"class A {\n deinit {\n close(handle)\n release(buffer)\n }\n}\n",
"class B {\n deinit {\n close(other)\n release(kept)\n }\n}\n",
) == 1.0
assert _scored(
tmp_path,
"class A {\n deinit {\n close(handle)\n }\n}\n",
"class B {\n deinit {\n shutdown(other)\n }\n}\n",
) < 1.0
def test_a_top_level_swift_closure_matches_its_renamed_copy(tmp_path):
left = """\
let alpha = { (xs: [Int]) -> [Int] in