mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -2648,7 +2648,8 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto var = createDecl<VarDecl>(isStatic, isLet, SourceLoc(),
|
||||
auto var = createDecl<VarDecl>(/*IsStatic*/isStatic, /*IsLet*/isLet,
|
||||
/*IsCaptureList*/false, SourceLoc(),
|
||||
getIdentifier(nameID), Type(), DC);
|
||||
var->setHasNonPatternBindingInit(hasNonPatternBindingInit);
|
||||
declOrOffset = var;
|
||||
|
||||
Reference in New Issue
Block a user