Skip to content

Commit 854f64e

Browse files
committed
[CSClosure] Diagnose invalid re-declarations in multi-statement closures
Calling `typeCheckDecl` on `VarDecl` is what triggers re-declaration checking and that was skipped by the solution application logic.
1 parent f1d5751 commit 854f64e

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
@@ -1188,10 +1188,6 @@ class SyntacticElementSolutionApplication
11881188
if (isa<IfConfigDecl>(decl))
11891189
return;
11901190

1191-
// Variable declaration would be handled by a pattern binding.
1192-
if (isa<VarDecl>(decl))
1193-
return;
1194-
11951191
// Generate constraints for pattern binding declarations.
11961192
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
11971193
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)