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