@@ -4678,6 +4678,7 @@ bool swift::isKeywordPossibleDeclStart(const Token &Tok) {
46784678 case tok::kw_func:
46794679 case tok::kw_import:
46804680 case tok::kw_init:
4681+ case tok::kw_inout:
46814682 case tok::kw_internal:
46824683 case tok::kw_let:
46834684 case tok::kw_operator:
@@ -5067,11 +5068,11 @@ Parser::parseDecl(ParseDeclOptions Flags,
50675068
50685069 bool HandlerAlreadyCalled = false ;
50695070
5070- auto parseLetOrVar = [&](bool HasLetOrVarKeyword ) {
5071+ auto parseBindingIntroducer = [&](bool HasBindingIntroducerKeyword ) {
50715072 // Collect all modifiers into a modifier list.
50725073 llvm::SmallVector<Decl *, 4 > Entries;
50735074 DeclResult = parseDeclVar (Flags, Attributes, Entries, StaticLoc,
5074- StaticSpelling, tryLoc, HasLetOrVarKeyword );
5075+ StaticSpelling, tryLoc, HasBindingIntroducerKeyword );
50755076 StaticLoc = SourceLoc (); // we handled static if present.
50765077 MayNeedOverrideCompletion = true ;
50775078 if ((AttrStatus.hasCodeCompletion () || DeclResult.hasCodeCompletion ())
@@ -5096,9 +5097,10 @@ Parser::parseDecl(ParseDeclOptions Flags,
50965097 case tok::kw_extension:
50975098 DeclResult = parseDeclExtension (Flags, Attributes);
50985099 break ;
5100+ case tok::kw_inout:
50995101 case tok::kw_let:
51005102 case tok::kw_var: {
5101- parseLetOrVar (/* HasLetOrVarKeyword=*/ true );
5103+ parseBindingIntroducer (/* HasLetOrVarKeyword=*/ true );
51025104 break ;
51035105 }
51045106 case tok::kw_typealias:
@@ -5239,7 +5241,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
52395241 diagnose (Tok.getLoc (), diag::expected_keyword_in_decl, " var" ,
52405242 DescriptiveKind)
52415243 .fixItInsert (Tok.getLoc (), " var " );
5242- parseLetOrVar (/* HasLetOrVarKeyword=*/ false );
5244+ parseBindingIntroducer (/* HasLetOrVarKeyword=*/ false );
52435245 break ;
52445246 }
52455247
@@ -7406,15 +7408,15 @@ void Parser::ParsedAccessors::classify(Parser &P, AbstractStorageDecl *storage,
74067408}
74077409
74087410
7409- // / Parse a 'var' or 'let ' declaration, doing no token skipping on error.
7411+ // / Parse a 'var', 'let', or 'inout ' declaration, doing no token skipping on error.
74107412ParserResult<PatternBindingDecl>
74117413Parser::parseDeclVar (ParseDeclOptions Flags,
74127414 DeclAttributes &Attributes,
74137415 SmallVectorImpl<Decl *> &Decls,
74147416 SourceLoc StaticLoc,
74157417 StaticSpellingKind StaticSpelling,
74167418 SourceLoc TryLoc,
7417- bool HasLetOrVarKeyword ) {
7419+ bool HasBindingKeyword ) {
74187420 assert (StaticLoc.isInvalid () || StaticSpelling != StaticSpellingKind::None);
74197421
74207422 if (StaticLoc.isValid ()) {
@@ -7432,11 +7434,13 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
74327434 }
74337435 }
74347436
7435- bool isLet = HasLetOrVarKeyword && Tok.is (tok::kw_let);
7436- assert (!HasLetOrVarKeyword || Tok.getKind () == tok::kw_let ||
7437- Tok.getKind () == tok::kw_var);
7437+ PatternBindingState newBindingContext = PatternBindingState::NotInBinding;
7438+ if (HasBindingKeyword)
7439+ newBindingContext = PatternBindingState (Tok);
7440+ assert (!HasBindingKeyword || Tok.getKind () == tok::kw_let ||
7441+ Tok.getKind () == tok::kw_var || Tok.getKind () == tok::kw_inout);
74387442
7439- SourceLoc VarLoc = HasLetOrVarKeyword ? consumeToken () : Tok.getLoc ();
7443+ SourceLoc VarLoc = newBindingContext. getIntroducer () ? consumeToken () : Tok.getLoc ();
74407444
74417445 // If this is a var in the top-level of script/repl source file, wrap the
74427446 // PatternBindingDecl in a TopLevelCodeDecl, since it represents executable
@@ -7507,7 +7511,7 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
75077511 // In our recursive parse, remember that we're in a var/let pattern.
75087512 llvm::SaveAndRestore<decltype (InBindingPattern)> T (
75097513 InBindingPattern,
7510- isLet ? PatternBindingState::InLet : PatternBindingState::InVar );
7514+ newBindingContext. getPatternBindingStateForIntroducer (VarDecl::Introducer::Var) );
75117515
75127516 // Track whether we are parsing an 'async let' pattern.
75137517 const auto hasAsyncAttr = Attributes.hasAttribute <AsyncAttr>();
0 commit comments