Skip to content

[lldb][swift] Fix GetParentIfClosure for Init methods of classes #10903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,8 @@ std::string SwiftLanguageRuntime::GetParentNameIfClosure(StringRef name) {
static const auto closure_kinds = {Kind::ImplicitClosure,
Kind::ExplicitClosure};
static const auto function_kinds = {Kind::ImplicitClosure,
Kind::ExplicitClosure, Kind::Function};
Kind::ExplicitClosure, Kind::Function,
Kind::Constructor};
auto *closure_node = swift_demangle::GetFirstChildOfKind(node, closure_kinds);
auto *parent_func_node =
swift_demangle::GetFirstChildOfKind(closure_node, function_kinds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ def test_async_closure(self):
self, thread.frames[0], "var_in_outer_closure", "closure #1 in func_3(arg:)"
)
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")

@swiftTest
def test_ctor_class_closure(self):
self.build()
(target, process, thread, bkpt) = self.get_to_bkpt("break_ctor_class")
check_not_captured_error(self, thread.frames[0], "input", "MY_STRUCT.init(input:)")
check_not_captured_error(self, thread.frames[0], "find_me", "MY_STRUCT.init(input:)")
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
11 changes: 11 additions & 0 deletions lldb/test/API/lang/swift/closures_var_not_captured/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ func func_3(arg: Int) async {
print(dont_find_me)
}

class MY_STRUCT {
init(input: [Int]) {
let find_me = "hello"
let _ = input.map {
return $0 // break_ctor_class
}
let dont_find_me = "hello"
}
}

func_1(arg: 42)
func_2(arg: 42)
await func_3(arg: 42)
let _ = MY_STRUCT(input: [1, 2])