Skip to content

Commit 9e22826

Browse files
committed
[Multi-expression closures] Add support for remaining declarations
1 parent 594b635 commit 9e22826

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

lib/Sema/CSClosure.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ class ClosureConstraintGenerator
4343

4444
private:
4545
void visitDecl(Decl *decl) {
46-
// Just ignore #if; the chosen children should appear in the
47-
// surrounding context. This isn't good for source tools but it
48-
// at least works.
49-
if (isa<IfConfigDecl>(decl))
50-
return;
51-
52-
// Skip #warning/#error; we'll handle them when applying the closure.
53-
if (isa<PoundDiagnosticDecl>(decl))
54-
return;
55-
56-
// Ignore variable declarations, because they're always handled within
57-
// their enclosing pattern bindings.
58-
if (isa<VarDecl>(decl))
59-
return;
60-
6146
// Generate constraints for pattern binding declarations.
6247
if (auto patternBinding = dyn_cast<PatternBindingDecl>(decl)) {
6348
SolutionApplicationTarget target(patternBinding);
@@ -67,7 +52,12 @@ class ClosureConstraintGenerator
6752
return;
6853
}
6954

70-
llvm_unreachable("Unimplemented case for closure body");
55+
// Ignore variable declarations, because they're always handled within
56+
// their enclosing pattern bindings.
57+
if (isa<VarDecl>(decl))
58+
return;
59+
60+
// Other declarations will be handled at application time.
7161
}
7262

7363
void visitBraceStmt(BraceStmt *braceStmt) {
@@ -334,7 +324,14 @@ class ClosureConstraintApplication
334324
return;
335325
}
336326

337-
llvm_unreachable("Declarations not supported");
327+
// Just ignore #if; the chosen children should appear in the
328+
// surrounding context. This isn't good for source tools but it
329+
// at least works.
330+
if (isa<IfConfigDecl>(decl))
331+
return;
332+
333+
// Type check the declaration.
334+
TypeChecker::typeCheckDecl(decl);
338335
}
339336

340337
ASTNode visitBraceStmt(BraceStmt *braceStmt) {

test/expr/closure/multi_statement.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ func mapWithMoreStatements(ints: [Int], state: State) throws {
8080

8181
#assert(true)
8282

83+
// expected-warning@+1{{danger zone}}
84+
#warning("danger zone")
85+
86+
#if false
87+
struct NothingHere { }
88+
#else
89+
struct NestedStruct {
90+
var x: Int
91+
}
92+
#endif
93+
8394
do {
8495
print(try mightThrow())
8596
} catch let e as MyError {

0 commit comments

Comments
 (0)