Skip to content

Commit 5fb35b2

Browse files
committed
[lldb] Fix expression evaluation in static functions in actors
Instead of trying to discern if lldb is stopped in a static or class function, always generate the function as static in either of those cases, since static works for classes/actors/structs/enums and for expression evaluation purposes a static or class function will work exactly the same. rdar://152446035
1 parent 18ffb87 commit 5fb35b2

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,6 @@ do {
430430
if (needs_object_ptr || static_method) {
431431
const char *func_decorator = "";
432432
if (static_method) {
433-
if (is_class)
434-
func_decorator = "final class";
435-
else
436433
func_decorator = "static";
437434
} else if (is_class && !weak_self) {
438435
func_decorator = "final";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import os
6+
7+
8+
class TestSwiftExpressionActor(TestBase):
9+
@swiftTest
10+
def test_static_func(self):
11+
self.build()
12+
lldbutil.run_to_source_breakpoint(
13+
self, "break here for static", lldb.SBFileSpec("main.swift")
14+
)
15+
16+
self.expect("expr self", substrs=["A.Type"])
17+
18+
@swiftTest
19+
def test_func(self):
20+
self.build()
21+
lldbutil.run_to_source_breakpoint(
22+
self, "break here for func", lldb.SBFileSpec("main.swift")
23+
)
24+
25+
self.expect("expr self", substrs=["(a.A)", "i = 42", 's = "Hello"'])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
actor A {
2+
let i = 42
3+
let s = "Hello"
4+
static func foo() {
5+
print("break here for static")
6+
}
7+
8+
func bar() {
9+
print("break here for func")
10+
}
11+
}
12+
13+
A.foo()
14+
await A().bar()

lldb/test/API/lang/swift/expression/static/TestSwiftExpressionsInClassFunctions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def test_expressions_in_class_functions(self):
4949

5050
self.assertTrue(len(threads) == 1)
5151
lldbutil.check_expression(self, self.frame(), "i", str(i), False)
52+
if i == 4:
53+
self.expect('e self', substrs=['F<Int>.Type'])
5254
if i == 6:
5355
lldbutil.check_expression(self, self.frame(), "self", "a.H<Int>")
5456
frame = threads[0].GetFrameAtIndex(0)

0 commit comments

Comments
 (0)