@@ -6226,7 +6226,7 @@ ParserStatus Parser::parseGetEffectSpecifier(ParsedAccessors &accessors,
62266226
62276227ParserStatus Parser::parseGetSet (ParseDeclOptions Flags,
62286228 GenericParamList *GenericParams,
6229- ParameterList *Indices,
6229+ ParameterList *Indices, TypeRepr *ResultType,
62306230 ParsedAccessors &accessors,
62316231 AbstractStorageDecl *storage,
62326232 SourceLoc StaticLoc) {
@@ -6258,8 +6258,22 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags,
62586258 if (parsingLimitedSyntax)
62596259 return makeParserSuccess ();
62606260
6261- diagnose (accessors.RBLoc , diag::computed_property_no_accessors,
6262- /* subscript*/ Indices != nullptr );
6261+ if (ResultType != nullptr ) {
6262+ // An error type at this point means we couldn't parse
6263+ // the result type for subscript correctly which will be
6264+ // already diagnosed as missing result type in declaration.
6265+ if (ResultType->getKind () == TypeReprKind::Error)
6266+ return makeParserError ();
6267+
6268+ diagnose (accessors.RBLoc , diag::missing_accessor_return_decl,
6269+ /* subscript*/ Indices != nullptr , ResultType);
6270+ } else {
6271+ // This is supposed to be a computed property, but we don't
6272+ // have a result type representation which indicates this is probably not
6273+ // a well-formed computed property. So we can assume that empty braces
6274+ // are unexpected at this position for this declaration.
6275+ diagnose (accessors.LBLoc , diag::unexpected_curly_braces_in_decl);
6276+ }
62636277 return makeParserError ();
62646278 }
62656279
@@ -6488,9 +6502,11 @@ Parser::parseDeclVarGetSet(PatternBindingEntry &entry, ParseDeclOptions Flags,
64886502
64896503 // Parse getter and setter.
64906504 ParsedAccessors accessors;
6505+ auto typedPattern = dyn_cast<TypedPattern>(pattern);
6506+ auto *resultTypeRepr = typedPattern ? typedPattern->getTypeRepr () : nullptr ;
64916507 auto AccessorStatus = parseGetSet (Flags, /* GenericParams=*/ nullptr ,
6492- /* Indices=*/ nullptr , accessors ,
6493- storage, StaticLoc);
6508+ /* Indices=*/ nullptr , resultTypeRepr ,
6509+ accessors, storage, StaticLoc);
64946510 if (AccessorStatus.hasCodeCompletion ())
64956511 return makeParserCodeCompletionStatus ();
64966512 if (AccessorStatus.isErrorOrHasCompletion ())
@@ -6500,7 +6516,7 @@ Parser::parseDeclVarGetSet(PatternBindingEntry &entry, ParseDeclOptions Flags,
65006516 if (!PrimaryVar)
65016517 return nullptr ;
65026518
6503- if (!isa<TypedPattern>(pattern) ) {
6519+ if (!typedPattern ) {
65046520 if (accessors.Get || accessors.Set || accessors.Address ||
65056521 accessors.MutableAddress ) {
65066522 SourceLoc locAfterPattern = pattern->getLoc ().getAdvancedLoc (
@@ -8029,7 +8045,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
80298045 Status.setIsParseError ();
80308046 }
80318047 } else if (!Status.hasCodeCompletion ()) {
8032- Status |= parseGetSet (Flags, GenericParams, Indices.get (),
8048+ Status |= parseGetSet (Flags, GenericParams, Indices.get (), ElementTy. get (),
80338049 accessors, Subscript, StaticLoc);
80348050 }
80358051
0 commit comments