Skip to content

Commit eca732f

Browse files
committed
[lldb] Allow "var" expr variables to be modified (#5651)
Unconditionally call `SwiftExpressionVariable::SetIsModifiable`, for both `let` and `var` variables. Previously `SetIsModifiable(false)` was called for `let` variables - now `var` variables will result in `SetIsModifiable(true)`. This fixes the following bug: (lldb) expr var $count = 123 (lldb) expr $count = 456 error: expression failed to parse: error: <EXPR>:3:1: error: cannot assign to value: '$count' is immutable $count = 456 ^~ rdar://102675900 (cherry picked from commit 6089eda)
1 parent 6a58b89 commit eca732f

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,14 +1811,10 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
18111811

18121812
swift::VarDecl *decl = variable_info.GetDecl();
18131813
if (decl) {
1814-
if (decl->isLet()) {
1815-
llvm::cast<SwiftExpressionVariable>(persistent_variable.get())
1816-
->SetIsModifiable(false);
1817-
}
1818-
if (!decl->hasStorage()) {
1819-
llvm::cast<SwiftExpressionVariable>(persistent_variable.get())
1820-
->SetIsComputed(true);
1821-
}
1814+
auto swift_var =
1815+
llvm::cast<SwiftExpressionVariable>(persistent_variable.get());
1816+
swift_var->SetIsModifiable(!decl->isLet());
1817+
swift_var->SetIsComputed(!decl->hasStorage());
18221818
}
18231819

18241820
variable_info.m_metadata.reset(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestCase(TestBase):
8+
@swiftTest
9+
def test(self):
10+
"""Test that persistent variables are mutable."""
11+
self.build()
12+
lldbutil.run_to_name_breakpoint(self, "main")
13+
self.expect("expr var $count = 30")
14+
self.expect("expr $count = 41")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// does nothing

0 commit comments

Comments
 (0)