Skip to content

Commit 3c05458

Browse files
authored
Merge pull request #10954 from felipepiovezan/felipe/fix_diagnostic_2
[lldb][swift] ] Fix GetParentIfClosure for didSet/settters/getters
2 parents 762a2bf + f8d883a commit 3c05458

File tree

3 files changed

+130
-5
lines changed

3 files changed

+130
-5
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,9 +1554,10 @@ std::string SwiftLanguageRuntime::GetParentNameIfClosure(Function &func) {
15541554
// entity.
15551555
static const auto closure_kinds = {Kind::ImplicitClosure,
15561556
Kind::ExplicitClosure};
1557-
static const auto function_kinds = {Kind::ImplicitClosure,
1558-
Kind::ExplicitClosure, Kind::Function,
1559-
Kind::Constructor, Kind::Static};
1557+
static const auto function_kinds = {
1558+
Kind::ImplicitClosure, Kind::ExplicitClosure, Kind::Function,
1559+
Kind::Constructor, Kind::Static, Kind::Getter,
1560+
Kind::Setter, Kind::DidSet};
15601561
auto *closure_node = swift_demangle::GetFirstChildOfKind(node, closure_kinds);
15611562
auto *parent_func_node =
15621563
swift_demangle::GetFirstChildOfKind(closure_node, function_kinds);

lldb/test/API/lang/swift/closures_var_not_captured/TestSwiftClosureVarNotCaptured.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,34 @@ def test_ctor_class_closure(self):
135135
)
136136
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me_static")
137137

138+
for kind in ["getter", "setter"]:
139+
lldbutil.continue_to_source_breakpoint(
140+
self,
141+
process,
142+
f"break_class_computed_property_{kind}",
143+
lldb.SBFileSpec("main.swift"),
144+
)
145+
check_not_captured_error(
146+
self,
147+
thread.frames[0],
148+
"find_me",
149+
f"MY_CLASS.class_computed_property.{kind}",
150+
)
151+
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
152+
lldbutil.continue_to_source_breakpoint(
153+
self,
154+
process,
155+
f"break_class_computed_property_didset",
156+
lldb.SBFileSpec("main.swift"),
157+
)
158+
check_not_captured_error(
159+
self,
160+
thread.frames[0],
161+
"find_me",
162+
f"MY_CLASS.class_computed_property_didset.didset",
163+
)
164+
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
165+
138166
@swiftTest
139167
def test_ctor_struct_closure(self):
140168
self.build()
@@ -164,6 +192,34 @@ def test_ctor_struct_closure(self):
164192
)
165193
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me_static")
166194

195+
for kind in ["getter", "setter"]:
196+
lldbutil.continue_to_source_breakpoint(
197+
self,
198+
process,
199+
f"break_struct_computed_property_{kind}",
200+
lldb.SBFileSpec("main.swift"),
201+
)
202+
check_not_captured_error(
203+
self,
204+
thread.frames[0],
205+
"find_me",
206+
f"MY_STRUCT.struct_computed_property.{kind}",
207+
)
208+
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
209+
lldbutil.continue_to_source_breakpoint(
210+
self,
211+
process,
212+
f"break_struct_computed_property_didset",
213+
lldb.SBFileSpec("main.swift"),
214+
)
215+
check_not_captured_error(
216+
self,
217+
thread.frames[0],
218+
"find_me",
219+
f"MY_STRUCT.struct_computed_property_didset.didset",
220+
)
221+
check_no_enhanced_diagnostic(self, thread.frames[0], "dont_find_me")
222+
167223
@swiftTest
168224
def test_ctor_enum_closure(self):
169225
self.build()

lldb/test/API/lang/swift/closures_var_not_captured/main.swift

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,37 @@ class MY_CLASS {
103103
}
104104
let dont_find_me_static = "hello"
105105
}
106+
107+
public var class_computed_property: Int {
108+
get {
109+
let find_me = "hello"
110+
let _ = {
111+
print("break_class_computed_property_getter")
112+
return 10
113+
}()
114+
let dont_find_me = "hello"
115+
return 42
116+
}
117+
set {
118+
let find_me = "hello"
119+
let _ = {
120+
print("break_class_computed_property_setter")
121+
return 10
122+
}()
123+
let dont_find_me = "hello"
124+
}
125+
}
126+
127+
public var class_computed_property_didset: Int = 0 {
128+
didSet {
129+
let find_me = "hello"
130+
let _ = {
131+
print("break_class_computed_property_didset")
132+
return 10
133+
}()
134+
let dont_find_me = "hello"
135+
}
136+
}
106137
}
107138

108139
struct MY_STRUCT {
@@ -123,6 +154,37 @@ struct MY_STRUCT {
123154
}
124155
let dont_find_me_static = "hello"
125156
}
157+
158+
public var struct_computed_property: Int {
159+
get {
160+
let find_me = "hello"
161+
let _ = {
162+
print("break_struct_computed_property_getter")
163+
return 10
164+
}()
165+
let dont_find_me = "hello"
166+
return 42
167+
}
168+
set {
169+
let find_me = "hello"
170+
let _ = {
171+
print("break_struct_computed_property_setter")
172+
return 10
173+
}()
174+
let dont_find_me = "hello"
175+
}
176+
}
177+
178+
public var struct_computed_property_didset: Int = 0 {
179+
didSet {
180+
let find_me = "hello"
181+
let _ = {
182+
print("break_struct_computed_property_didset")
183+
return 10
184+
}()
185+
let dont_find_me = "hello"
186+
}
187+
}
126188
}
127189

128190
enum MY_ENUM {
@@ -153,9 +215,15 @@ enum MY_ENUM {
153215
func_1(arg: 42)
154216
func_2(arg: 42)
155217
await func_3(arg: 42)
156-
let _ = MY_CLASS(input: [1, 2])
218+
var my_class = MY_CLASS(input: [1, 2])
157219
MY_CLASS.static_func(input_static: [42])
158-
let _ = MY_STRUCT(input: [1, 2])
220+
print(my_class.class_computed_property)
221+
my_class.class_computed_property = 10
222+
my_class.class_computed_property_didset = 10;
223+
var my_struct = MY_STRUCT(input: [1, 2])
159224
MY_STRUCT.static_func(input_static: [42])
225+
print(my_struct.struct_computed_property)
226+
my_struct.struct_computed_property = 10
227+
my_struct.struct_computed_property_didset = 10
160228
let _ = MY_ENUM(input: [1,2])
161229
MY_ENUM.static_func(input_static: [42])

0 commit comments

Comments
 (0)