@@ -296,11 +296,27 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
296
296
SGF.LocalAuxiliaryDecls .clear ();
297
297
}
298
298
299
+ bool didDiagnoseUnreachableElements = false ;
299
300
for (auto &ESD : S->getElements ()) {
300
301
301
- if (auto D = ESD.dyn_cast <Decl*>())
302
+ if (auto D = ESD.dyn_cast <Decl*>()) {
302
303
if (isa<IfConfigDecl>(D))
303
304
continue ;
305
+
306
+ // Hoisted declarations are emitted at the top level by emitSourceFile().
307
+ if (D->isHoisted ())
308
+ continue ;
309
+
310
+ // PatternBindingBecls represent local variable bindings that execute
311
+ // as part of the function's execution.
312
+ if (!isa<PatternBindingDecl>(D)) {
313
+ // Other decls define entities that may be used by the program, such as
314
+ // local function declarations. So handle them here, before checking for
315
+ // reachability, and then continue looping.
316
+ SGF.visit (D);
317
+ continue ;
318
+ }
319
+ }
304
320
305
321
// If we ever reach an unreachable point, stop emitting statements and issue
306
322
// an unreachable code diagnostic.
@@ -350,6 +366,10 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
350
366
continue ;
351
367
}
352
368
369
+ if (didDiagnoseUnreachableElements)
370
+ continue ;
371
+ didDiagnoseUnreachableElements = true ;
372
+
353
373
if (StmtType != UnknownStmtType) {
354
374
diagnose (getASTContext (), ESD.getStartLoc (),
355
375
diag::unreachable_code_after_stmt, StmtType);
@@ -376,7 +396,7 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
376
396
}
377
397
}
378
398
}
379
- return ;
399
+ continue ;
380
400
}
381
401
382
402
// Process children.
@@ -395,11 +415,11 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
395
415
} else {
396
416
auto *D = ESD.get <Decl*>();
397
417
398
- // Hoisted declarations are emitted at the top level by emitSourceFile() .
399
- if (D-> isHoisted ())
400
- continue ;
418
+ // Only PatternBindingDecls should be emitted here .
419
+ // Other decls were handled above.
420
+ auto PBD = cast<PatternBindingDecl>(D) ;
401
421
402
- SGF.visit (D );
422
+ SGF.visit (PBD );
403
423
}
404
424
}
405
425
}
0 commit comments