@@ -234,16 +234,16 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(Diag<> MessageID) {
234
234
235
235
if (!Tok.isAtStartOfLine ()) {
236
236
if (isOptionalToken (Tok)) {
237
- ty = parseTypeOptional (ty. get () );
237
+ ty = parseTypeOptional (ty);
238
238
continue ;
239
239
}
240
240
if (isImplicitlyUnwrappedOptionalToken (Tok)) {
241
- ty = parseTypeImplicitlyUnwrappedOptional (ty. get () );
241
+ ty = parseTypeImplicitlyUnwrappedOptional (ty);
242
242
continue ;
243
243
}
244
244
// Parse legacy array types for migration.
245
245
if (Tok.is (tok::l_square)) {
246
- ty = parseTypeArray (ty. get () );
246
+ ty = parseTypeArray (ty);
247
247
continue ;
248
248
}
249
249
}
@@ -1183,12 +1183,11 @@ ParserResult<TypeRepr> Parser::parseTypeTupleBody() {
1183
1183
// / type-array '[' ']'
1184
1184
// / type-array '[' expr ']'
1185
1185
// /
1186
- ParserResult<TypeRepr> Parser::parseTypeArray (TypeRepr * Base) {
1186
+ ParserResult<TypeRepr> Parser::parseTypeArray (ParserResult< TypeRepr> Base) {
1187
1187
assert (Tok.isFollowingLSquare ());
1188
1188
Parser::StructureMarkerRAII ParsingArrayBound (*this , Tok);
1189
1189
SourceLoc lsquareLoc = consumeToken ();
1190
- ArrayTypeRepr *ATR = nullptr ;
1191
-
1190
+
1192
1191
// Handle a postfix [] production, a common typo for a C-like array.
1193
1192
1194
1193
// If we have something that might be an array size expression, parse it as
@@ -1201,19 +1200,23 @@ ParserResult<TypeRepr> Parser::parseTypeArray(TypeRepr *Base) {
1201
1200
1202
1201
SourceLoc rsquareLoc;
1203
1202
if (parseMatchingToken (tok::r_square, rsquareLoc,
1204
- diag::expected_rbracket_array_type, lsquareLoc))
1205
- return makeParserErrorResult (Base);
1203
+ diag::expected_rbracket_array_type, lsquareLoc)) {
1204
+ Base.setIsParseError ();
1205
+ return Base;
1206
+ }
1207
+
1208
+ auto baseTyR = Base.get ();
1206
1209
1207
1210
// If we parsed something valid, diagnose it with a fixit to rewrite it to
1208
1211
// Swift syntax.
1209
1212
diagnose (lsquareLoc, diag::new_array_syntax)
1210
- .fixItInsert (Base ->getStartLoc (), " [" )
1213
+ .fixItInsert (baseTyR ->getStartLoc (), " [" )
1211
1214
.fixItRemove (lsquareLoc);
1212
1215
1213
1216
// Build a normal array slice type for recovery.
1214
- ATR = new (Context) ArrayTypeRepr (Base,
1215
- SourceRange (Base ->getStartLoc (), rsquareLoc));
1216
- return makeParserResult (ATR);
1217
+ ArrayTypeRepr * ATR = new (Context) ArrayTypeRepr (
1218
+ baseTyR, SourceRange (baseTyR ->getStartLoc (), rsquareLoc));
1219
+ return makeParserResult (ParserStatus (Base), ATR);
1217
1220
}
1218
1221
1219
1222
ParserResult<TypeRepr> Parser::parseTypeCollection () {
@@ -1318,22 +1321,22 @@ SourceLoc Parser::consumeImplicitlyUnwrappedOptionalToken() {
1318
1321
// / Parse a single optional suffix, given that we are looking at the
1319
1322
// / question mark.
1320
1323
ParserResult<TypeRepr>
1321
- Parser::parseTypeOptional (TypeRepr * base) {
1324
+ Parser::parseTypeOptional (ParserResult< TypeRepr> base) {
1322
1325
SourceLoc questionLoc = consumeOptionalToken ();
1323
- auto TyR = new (Context) OptionalTypeRepr (base, questionLoc);
1326
+ auto TyR = new (Context) OptionalTypeRepr (base. get () , questionLoc);
1324
1327
SyntaxContext->createNodeInPlace (SyntaxKind::OptionalType);
1325
- return makeParserResult (TyR);
1328
+ return makeParserResult (ParserStatus (base), TyR);
1326
1329
}
1327
1330
1328
1331
// / Parse a single implicitly unwrapped optional suffix, given that we
1329
1332
// / are looking at the exclamation mark.
1330
1333
ParserResult<TypeRepr>
1331
- Parser::parseTypeImplicitlyUnwrappedOptional (TypeRepr * base) {
1334
+ Parser::parseTypeImplicitlyUnwrappedOptional (ParserResult< TypeRepr> base) {
1332
1335
SourceLoc exclamationLoc = consumeImplicitlyUnwrappedOptionalToken ();
1333
1336
auto TyR =
1334
- new (Context) ImplicitlyUnwrappedOptionalTypeRepr (base, exclamationLoc);
1337
+ new (Context) ImplicitlyUnwrappedOptionalTypeRepr (base. get () , exclamationLoc);
1335
1338
SyntaxContext->createNodeInPlace (SyntaxKind::ImplicitlyUnwrappedOptionalType);
1336
- return makeParserResult (TyR);
1339
+ return makeParserResult (ParserStatus (base), TyR);
1337
1340
}
1338
1341
1339
1342
// ===----------------------------------------------------------------------===//
0 commit comments