[Sema] Mark VarDecl in capture lists

Fixes SR-2757.

Variables in capture lists are treated as 'let' constants, which can
result in misleading, incorrect diagnostics. Mark them as such in order
to produce better diagnostics, by adding an extra parameter to the
VarDecl initializer.

Alternatively, these variables could be marked as implicit, but that
results in other diagnostic problems: capture list variables that are
never used produce warnings, but these warnings aren't normally emitted for
implicit variables. Other assertions in the compiler also misfire when
these variables are treated as implicit.

Another alternative would be to walk up the AST and determine whether
the `VarDecl`, but there doesn't appear to be a way to do so.
This commit is contained in:
Brian Gesiak
2016-12-25 12:03:28 -05:00
parent 474096b9cb
commit 4108e1d9af
19 changed files with 152 additions and 117 deletions

View File

@@ -472,9 +472,9 @@ public:
}
VarDecl *VD =
new (Context) VarDecl(false, // static
true, // let
SourceLoc(), Context.getIdentifier(NameBuf),
new (Context) VarDecl(/*IsStatic*/false, /*IsLet*/true,
/*IsCaptureList*/false, SourceLoc(),
Context.getIdentifier(NameBuf),
MaybeLoadInitExpr->getType(), TypeCheckDC);
VD->setImplicit();