Skip to content

Commit ffe21d4

Browse files
committed
Sema: Diagnose duplicate capture list entires when parser lookup is off
Another spot where we have to check for redeclaration manually now. As before, we can use the existing mechanism though.
1 parent 4f1ab9d commit ffe21d4

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,8 @@ namespace {
34403440

34413441
// Generate constraints for each of the entries in the capture list.
34423442
if (auto captureList = dyn_cast<CaptureListExpr>(expr)) {
3443+
TypeChecker::diagnoseDuplicateCaptureVars(captureList);
3444+
34433445
auto &CS = CG.getConstraintSystem();
34443446
for (const auto &capture : captureList->getCaptureList()) {
34453447
SolutionApplicationTarget target(capture.Init);

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,14 @@ void TypeChecker::diagnoseDuplicateBoundVars(Pattern *pattern) {
13341334
diagnoseDuplicateDecls(boundVars);
13351335
}
13361336

1337+
void TypeChecker::diagnoseDuplicateCaptureVars(CaptureListExpr *expr) {
1338+
SmallVector<VarDecl *, 2> captureListVars;
1339+
for (auto &capture : expr->getCaptureList())
1340+
captureListVars.push_back(capture.Var);
1341+
1342+
diagnoseDuplicateDecls(captureListVars);
1343+
}
1344+
13371345
namespace {
13381346
class DeclChecker : public DeclVisitor<DeclChecker> {
13391347
public:

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ void checkParameterList(ParameterList *params);
502502

503503
void diagnoseDuplicateBoundVars(Pattern *pattern);
504504

505+
void diagnoseDuplicateCaptureVars(CaptureListExpr *expr);
506+
505507
Type checkReferenceOwnershipAttr(VarDecl *D, Type interfaceType,
506508
ReferenceOwnershipAttr *attr);
507509

0 commit comments

Comments
 (0)