From 5fb35b20b598096c2a679ea11d6ddccec2af053f Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Tue, 18 Nov 2025 16:45:07 -0800 Subject: [PATCH] [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 --- .../Swift/SwiftExpressionSourceCode.cpp | 3 --- .../API/lang/swift/expression/actor/Makefile | 3 +++ .../actor/TestSwiftExpressionActor.py | 25 +++++++++++++++++++ .../lang/swift/expression/actor/main.swift | 14 +++++++++++ .../TestSwiftExpressionsInClassFunctions.py | 2 ++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/lang/swift/expression/actor/Makefile create mode 100644 lldb/test/API/lang/swift/expression/actor/TestSwiftExpressionActor.py create mode 100644 lldb/test/API/lang/swift/expression/actor/main.swift diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp index 952d8ee005f77..80f342d80e9b2 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.cpp @@ -430,9 +430,6 @@ do { if (needs_object_ptr || static_method) { const char *func_decorator = ""; if (static_method) { - if (is_class) - func_decorator = "final class"; - else func_decorator = "static"; } else if (is_class && !weak_self) { func_decorator = "final"; diff --git a/lldb/test/API/lang/swift/expression/actor/Makefile b/lldb/test/API/lang/swift/expression/actor/Makefile new file mode 100644 index 0000000000000..2a69023633b34 --- /dev/null +++ b/lldb/test/API/lang/swift/expression/actor/Makefile @@ -0,0 +1,3 @@ +SWIFT_SOURCES := main.swift + +include Makefile.rules diff --git a/lldb/test/API/lang/swift/expression/actor/TestSwiftExpressionActor.py b/lldb/test/API/lang/swift/expression/actor/TestSwiftExpressionActor.py new file mode 100644 index 0000000000000..658e4d0f4e5eb --- /dev/null +++ b/lldb/test/API/lang/swift/expression/actor/TestSwiftExpressionActor.py @@ -0,0 +1,25 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil +import os + + +class TestSwiftExpressionActor(TestBase): + @swiftTest + def test_static_func(self): + self.build() + lldbutil.run_to_source_breakpoint( + self, "break here for static", lldb.SBFileSpec("main.swift") + ) + + self.expect("expr self", substrs=["A.Type"]) + + @swiftTest + def test_func(self): + self.build() + lldbutil.run_to_source_breakpoint( + self, "break here for func", lldb.SBFileSpec("main.swift") + ) + + self.expect("expr self", substrs=["(a.A)", "i = 42", 's = "Hello"']) diff --git a/lldb/test/API/lang/swift/expression/actor/main.swift b/lldb/test/API/lang/swift/expression/actor/main.swift new file mode 100644 index 0000000000000..b7d7b85b34621 --- /dev/null +++ b/lldb/test/API/lang/swift/expression/actor/main.swift @@ -0,0 +1,14 @@ +actor A { + let i = 42 + let s = "Hello" + static func foo() { + print("break here for static") + } + + func bar() { + print("break here for func") + } +} + +A.foo() +await A().bar() diff --git a/lldb/test/API/lang/swift/expression/static/TestSwiftExpressionsInClassFunctions.py b/lldb/test/API/lang/swift/expression/static/TestSwiftExpressionsInClassFunctions.py index f79eb58e9b156..ad8dca90fd413 100644 --- a/lldb/test/API/lang/swift/expression/static/TestSwiftExpressionsInClassFunctions.py +++ b/lldb/test/API/lang/swift/expression/static/TestSwiftExpressionsInClassFunctions.py @@ -49,6 +49,8 @@ def test_expressions_in_class_functions(self): self.assertTrue(len(threads) == 1) lldbutil.check_expression(self, self.frame(), "i", str(i), False) + if i == 4: + self.expect('e self', substrs=['F.Type']) if i == 6: lldbutil.check_expression(self, self.frame(), "self", "a.H") frame = threads[0].GetFrameAtIndex(0)