@@ -2135,14 +2135,29 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2135
2135
AppendingExpr));
2136
2136
}
2137
2137
2138
+ // / Equivalent to \c Tok.is(tok::colon), but pretends that \c tok::colon_colon
2139
+ // / doesn't exist if \c EnableExperimentalModuleSelector is disabled.
2140
+ static bool isColon (Parser &P, Token Tok, tok altColon = tok::NUM_TOKENS) {
2141
+ // FIXME: Introducing tok::colon_colon broke diag::empty_arg_label_underscore.
2142
+ // We only care about tok::colon_colon when module selectors are turned on, so
2143
+ // when they are turned off, this function works around the bug by treating
2144
+ // tok::colon_colon as a synonym for tok::colon. However, the bug still exists
2145
+ // when Feature::ModuleSelector is enabled. We will need to address this
2146
+ // before the feature can be released.
2147
+
2148
+ if (P.Context .LangOpts .hasFeature (Feature::ModuleSelector))
2149
+ return Tok.isAny (tok::colon, altColon);
2150
+
2151
+ return Tok.isAny (tok::colon, tok::colon_colon, altColon);
2152
+ }
2153
+
2138
2154
void Parser::parseOptionalArgumentLabel (Identifier &name, SourceLoc &loc,
2139
2155
bool isAttr) {
2140
2156
// / A token that has the same meaning as colon, but is deprecated, if one exists for this call.
2141
2157
auto altColon = isAttr ? tok::equal : tok::NUM_TOKENS;
2142
2158
2143
2159
// Check to see if there is an argument label.
2144
- if (Tok.canBeArgumentLabel () && peekToken ().isAny (tok::colon, altColon)) {
2145
- // Label found, including colon.
2160
+ if (Tok.canBeArgumentLabel () && isColon (*this , peekToken (), altColon)) {
2146
2161
auto text = Tok.getText ();
2147
2162
2148
2163
// If this was an escaped identifier that need not have been escaped, say
@@ -2161,7 +2176,7 @@ void Parser::parseOptionalArgumentLabel(Identifier &name, SourceLoc &loc,
2161
2176
}
2162
2177
2163
2178
loc = consumeArgumentLabel (name, /* diagnoseDollarPrefix=*/ false );
2164
- } else if (Tok. isAny (tok::colon , altColon)) {
2179
+ } else if (isColon (* this , Tok , altColon)) {
2165
2180
// Found only the colon.
2166
2181
diagnose (Tok, diag::expected_label_before_colon)
2167
2182
.fixItInsert (Tok.getLoc (), " <#label#>" );
@@ -2171,7 +2186,12 @@ void Parser::parseOptionalArgumentLabel(Identifier &name, SourceLoc &loc,
2171
2186
}
2172
2187
2173
2188
// If we get here, we ought to be on the colon.
2174
- assert (Tok.isAny (tok::colon, altColon));
2189
+ ASSERT (Tok.isAny (tok::colon, tok::colon_colon, altColon));
2190
+
2191
+ if (Tok.is (tok::colon_colon)) {
2192
+ consumeIfColonSplittingDoubles ();
2193
+ return ;
2194
+ }
2175
2195
2176
2196
if (Tok.is (altColon))
2177
2197
diagnose (Tok, diag::replace_equal_with_colon_for_value)
@@ -2201,7 +2221,7 @@ static bool tryParseArgLabelList(Parser &P, Parser::DeclNameOptions flags,
2201
2221
flags.contains (Parser::DeclNameFlag::AllowZeroArgCompoundNames) &&
2202
2222
next.is (tok::r_paren);
2203
2223
// An argument label.
2204
- bool nextIsArgLabel = next.canBeArgumentLabel () || next. is (tok::colon );
2224
+ bool nextIsArgLabel = next.canBeArgumentLabel () || isColon (P, next );
2205
2225
// An editor placeholder.
2206
2226
bool nextIsPlaceholder = Identifier::isEditorPlaceholder (next.getText ());
2207
2227
@@ -2214,11 +2234,11 @@ static bool tryParseArgLabelList(Parser &P, Parser::DeclNameOptions flags,
2214
2234
lparenLoc = P.consumeToken (tok::l_paren);
2215
2235
while (P.Tok .isNot (tok::r_paren)) {
2216
2236
// If we see a ':', the user forgot the '_';
2217
- if (P.Tok . is (tok::colon )) {
2218
- P.diagnose (P.Tok , diag::empty_arg_label_underscore)
2219
- .fixItInsert (P.Tok . getLoc () , " _" );
2237
+ if (P.consumeIfColonSplittingDoubles ( )) {
2238
+ P.diagnose (P.PreviousLoc , diag::empty_arg_label_underscore)
2239
+ .fixItInsert (P.PreviousLoc , " _" );
2220
2240
argumentLabels.push_back (Identifier ());
2221
- argumentLabelLocs.push_back (P.consumeToken (tok::colon) );
2241
+ argumentLabelLocs.push_back (P.PreviousLoc );
2222
2242
}
2223
2243
2224
2244
Identifier argName;
0 commit comments