Skip to content

Commit 5693331

Browse files
authored
Merge pull request #58768 from xedin/redecl-check-in-multi-closures
[CSClosure] Diagnose invalid re-declarations in multi-statement closures
2 parents c7b1505 + 854f64e commit 5693331

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/Sema/CSClosure.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,10 +1189,6 @@ class SyntacticElementSolutionApplication
11891189
if (isa<IfConfigDecl>(decl))
11901190
return;
11911191

1192-
// Variable declaration would be handled by a pattern binding.
1193-
if (isa<VarDecl>(decl))
1194-
return;
1195-
11961192
// Generate constraints for pattern binding declarations.
11971193
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
11981194
SolutionApplicationTarget target(patternBinding);

test/expr/closure/multi_statement.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ func test_local_function_capturing_vars() {
234234
}
235235
}
236236

237+
func test_test_invalid_redeclaration() {
238+
func test(_: () -> Void) {
239+
}
240+
241+
test {
242+
let foo = 0 // expected-note {{'foo' previously declared here}}
243+
let foo = foo // expected-error {{invalid redeclaration of 'foo'}}
244+
}
245+
246+
test {
247+
let (foo, foo) = (5, 6) // expected-error {{invalid redeclaration of 'foo'}} expected-note {{'foo' previously declared here}}
248+
}
249+
}
250+
237251
func test_pattern_ambiguity_doesnot_crash_compiler() {
238252
enum E {
239253
case hello(result: Int) // expected-note 2 {{found this candidate}}

0 commit comments

Comments
 (0)