@@ -804,10 +804,15 @@ Parser::parseTypeSimpleOrComposition(Diag<> MessageID, ParseTypeReason reason) {
804
804
// This is only semantically allowed in certain contexts, but we parse it
805
805
// generally for diagnostics and recovery.
806
806
SourceLoc opaqueLoc;
807
+ SourceLoc anyLoc;
807
808
if (Tok.isContextualKeyword (" some" )) {
808
809
// Treat some as a keyword.
809
810
TokReceiver->registerTokenKindChange (Tok.getLoc (), tok::contextual_keyword);
810
811
opaqueLoc = consumeToken ();
812
+ } else if (Tok.isContextualKeyword (" any" )) {
813
+ // Treat any as a keyword.
814
+ TokReceiver->registerTokenKindChange (Tok.getLoc (), tok::contextual_keyword);
815
+ anyLoc = consumeToken ();
811
816
} else {
812
817
// This isn't a some type.
813
818
SomeTypeContext.setTransparent ();
@@ -816,6 +821,8 @@ Parser::parseTypeSimpleOrComposition(Diag<> MessageID, ParseTypeReason reason) {
816
821
auto applyOpaque = [&](TypeRepr *type) -> TypeRepr* {
817
822
if (opaqueLoc.isValid ()) {
818
823
type = new (Context) OpaqueReturnTypeRepr (opaqueLoc, type);
824
+ } else if (anyLoc.isValid ()) {
825
+ type = new (Context) ExistentialTypeRepr (anyLoc, type);
819
826
}
820
827
return type;
821
828
};
@@ -866,16 +873,21 @@ Parser::parseTypeSimpleOrComposition(Diag<> MessageID, ParseTypeReason reason) {
866
873
consumeToken (); // consume '&'
867
874
}
868
875
869
- // Diagnose invalid `some` after an ampersand.
870
- if (Tok.isContextualKeyword (" some" )) {
876
+ // Diagnose invalid `some` or `any` after an ampersand.
877
+ if (Tok.isContextualKeyword (" some" ) ||
878
+ Tok.isContextualKeyword (" any" )) {
879
+ auto keyword = Tok.getText ();
871
880
auto badLoc = consumeToken ();
872
881
873
- diagnose (badLoc, diag::opaque_mid_composition)
882
+ diagnose (badLoc, diag::opaque_mid_composition, keyword )
874
883
.fixItRemove (badLoc)
875
- .fixItInsert (FirstTypeLoc, " some " );
884
+ .fixItInsert (FirstTypeLoc, keyword. str () + " " );
876
885
877
- if (opaqueLoc.isInvalid ())
886
+ if (opaqueLoc.isInvalid ()) {
878
887
opaqueLoc = badLoc;
888
+ } else if (anyLoc.isInvalid ()) {
889
+ anyLoc = badLoc;
890
+ }
879
891
}
880
892
881
893
// Parse next type.
@@ -1441,8 +1453,11 @@ bool Parser::canParseType() {
1441
1453
// Accept 'inout' at for better recovery.
1442
1454
consumeIf (tok::kw_inout);
1443
1455
1444
- if (Tok.isContextualKeyword (" some" ))
1456
+ if (Tok.isContextualKeyword (" some" )) {
1445
1457
consumeToken ();
1458
+ } else if (Tok.isContextualKeyword (" any" )) {
1459
+ consumeToken ();
1460
+ }
1446
1461
1447
1462
switch (Tok.getKind ()) {
1448
1463
case tok::kw_Self:
0 commit comments