@@ -796,6 +796,7 @@ Parser::parseTypeIdentifier(bool isParsingQualifiedDeclBaseType) {
796
796
// /
797
797
// / type-composition:
798
798
// / 'some'? type-simple
799
+ // / 'any'? type-simple
799
800
// / type-composition '&' type-simple
800
801
ParserResult<TypeRepr>
801
802
Parser::parseTypeSimpleOrComposition (Diag<> MessageID, ParseTypeReason reason) {
@@ -818,8 +819,9 @@ Parser::parseTypeSimpleOrComposition(Diag<> MessageID, ParseTypeReason reason) {
818
819
SomeTypeContext.setTransparent ();
819
820
}
820
821
821
- auto applyOpaque = [&](TypeRepr *type) -> TypeRepr* {
822
- if (opaqueLoc.isValid ()) {
822
+ auto applyOpaque = [&](TypeRepr *type) -> TypeRepr * {
823
+ if (opaqueLoc.isValid () &&
824
+ (anyLoc.isInvalid () || SourceMgr.isBeforeInBuffer (opaqueLoc, anyLoc))) {
823
825
type = new (Context) OpaqueReturnTypeRepr (opaqueLoc, type);
824
826
} else if (anyLoc.isValid ()) {
825
827
type = new (Context) ExistentialTypeRepr (anyLoc, type);
@@ -879,14 +881,18 @@ Parser::parseTypeSimpleOrComposition(Diag<> MessageID, ParseTypeReason reason) {
879
881
auto keyword = Tok.getText ();
880
882
auto badLoc = consumeToken ();
881
883
884
+ const bool isAnyKeyword = keyword.equals (" any" );
885
+
882
886
diagnose (badLoc, diag::opaque_mid_composition, keyword)
883
887
.fixItRemove (badLoc)
884
888
.fixItInsert (FirstTypeLoc, keyword.str () + " " );
885
889
886
- if (opaqueLoc.isInvalid ()) {
890
+ if (isAnyKeyword) {
891
+ if (anyLoc.isInvalid ()) {
892
+ anyLoc = badLoc;
893
+ }
894
+ } else if (opaqueLoc.isInvalid ()) {
887
895
opaqueLoc = badLoc;
888
- } else if (anyLoc.isInvalid ()) {
889
- anyLoc = badLoc;
890
896
}
891
897
}
892
898
0 commit comments