@@ -172,12 +172,15 @@ bool Parser::startsParameterName(bool isClosure) {
172172 return true ;
173173
174174 // "isolated" can be an argument label, but it's also a contextual keyword,
175- // so look ahead one more token see if we have a ':' that would indicate
176- // that this is an argument label.
177- BacktrackingScope backtrackScope (*this );
178- consumeToken ();
179- consumeToken ();
180- return Tok.is (tok::colon);
175+ // so look ahead one more token (two total) see if we have a ':' that would
176+ // indicate that this is an argument label.
177+ return lookahead<bool >(2 , [&](CancellableBacktrackingScope &) {
178+ if (Tok.is (tok::colon))
179+ return true ; // isolated :
180+
181+ // isolated x :
182+ return Tok.canBeArgumentLabel () && nextTok.is (tok::colon);
183+ });
181184 }
182185
183186 if (isOptionalToken (nextTok)
@@ -260,14 +263,30 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
260263 Tok.isContextualKeyword (" __shared" ) ||
261264 Tok.isContextualKeyword (" __owned" ) ||
262265 Tok.isContextualKeyword (" isolated" )) {
266+
263267 if (Tok.isContextualKeyword (" isolated" )) {
268+ // did we already find an 'isolated' type modifier?
264269 if (param.IsolatedLoc .isValid ()) {
265270 diagnose (Tok, diag::parameter_specifier_repeated)
266- .fixItRemove (Tok.getLoc ());
271+ .fixItRemove (Tok.getLoc ());
267272 consumeToken ();
268- } else {
269- param.IsolatedLoc = consumeToken ();
273+ continue ;
270274 }
275+
276+ // is this 'isolated' token the identifier of an argument label?
277+ bool partOfArgumentLabel = lookahead<bool >(1 , [&](CancellableBacktrackingScope &) {
278+ if (Tok.is (tok::colon))
279+ return true ; // isolated :
280+
281+ // isolated x :
282+ return Tok.canBeArgumentLabel () && peekToken ().is (tok::colon);
283+ });
284+
285+ if (partOfArgumentLabel)
286+ break ;
287+
288+ // consume 'isolated' as type modifier
289+ param.IsolatedLoc = consumeToken ();
271290 continue ;
272291 }
273292
@@ -304,7 +323,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
304323 diagnose (Tok, diag::parameter_let_var_as_attr, Tok.getText ())
305324 .fixItReplace (Tok.getLoc (), " `" + Tok.getText ().str () + " `" );
306325 }
307-
326+
308327 if (startsParameterName (isClosure)) {
309328 // identifier-or-none for the first name
310329 param.FirstNameLoc = consumeArgumentLabel (param.FirstName ,
@@ -433,7 +452,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
433452 status.setIsParseError ();
434453 }
435454 }
436-
455+
437456 // '...'?
438457 if (Tok.isEllipsis ()) {
439458 Tok.setKind (tok::ellipsis);
0 commit comments