Skip to content

Commit d88955b

Browse files
authored
Merge pull request #3043 from CodaFi/closing-time
[Swift 5.5] Special-case Pattern Binding Decls Created by LLDB
2 parents 3233b4a + 61fcbe9 commit d88955b

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ swift::Stmt *SwiftASTManipulator::ConvertExpressionToTmpReturnVarAccess(
432432
result_loc_info.tmp_var_decl);
433433

434434
const auto static_spelling_kind = swift::StaticSpellingKind::KeywordStatic;
435-
result_loc_info.binding_decl = swift::PatternBindingDecl::createImplicit(
435+
result_loc_info.binding_decl = swift::PatternBindingDecl::createForDebugger(
436436
ast_context, static_spelling_kind, var_pattern, expr, new_decl_context);
437437
result_loc_info.binding_decl->setStatic(false);
438438

@@ -445,8 +445,12 @@ swift::Stmt *SwiftASTManipulator::ConvertExpressionToTmpReturnVarAccess(
445445
body.push_back(result_loc_info.return_stmt);
446446
}
447447

448+
swift::SourceLoc brace_end = result_loc_info.orig_expr->getEndLoc();
449+
if (brace_end.isInvalid()) {
450+
brace_end = source_loc;
451+
}
448452
auto *body_stmt = swift::BraceStmt::create(
449-
ast_context, source_loc, llvm::ArrayRef<swift::ASTNode>(body), source_loc,
453+
ast_context, source_loc, llvm::ArrayRef<swift::ASTNode>(body), brace_end,
450454
true);
451455

452456
// Default construct a label info that contains nothing for the 'do'

lldb/test/API/lang/swift/expression/scopes/main.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func main () -> Void
131131
var my_b = B()
132132

133133
my_b.method()
134+
135+
let my_c = [1, 2, 3].map { x in x }
136+
print(my_c)
134137
}
135138

136139
main()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test that we can define and use variables in closure scopes in the REPL
2+
// REQUIRES: swift
3+
4+
// RUN: %lldb --repl < %s | FileCheck %s
5+
6+
print([1, 2, 3].map { x in x + 1 })
7+
// CHECK: [2, 3, 4]
8+
9+
var numbers = [20, 17, 2, 7]
10+
print(numbers.map({ (number: Int) -> Int in return 3 * number }))
11+
// CHECK: numbers: [Int] = 4 values {
12+
// CHECK: [0] = 20
13+
// CHECK: [1] = 17
14+
// CHECK: [2] = 2
15+
// CHECK: [3] = 7
16+
// CHECK: }
17+
// CHECK: [60, 51, 6, 21]
18+

0 commit comments

Comments
 (0)