Skip to content

Commit 54fc26f

Browse files
authored
Merge pull request #34282 from rintaro/parse-opaque-closure
[Parse] Parse opaque result types in closure signature position
2 parents edef3d6 + d996359 commit 54fc26f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/Parse/ParseType.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ Parser::parseTypeSimpleOrComposition(Diag<> MessageID,
841841
// This is only semantically allowed in certain contexts, but we parse it
842842
// generally for diagnostics and recovery.
843843
SourceLoc opaqueLoc;
844-
if (Tok.is(tok::identifier) && Tok.getRawText() == "some") {
844+
if (Tok.isContextualKeyword("some")) {
845845
// Treat some as a keyword.
846846
TokReceiver->registerTokenKindChange(Tok.getLoc(), tok::contextual_keyword);
847847
opaqueLoc = consumeToken();
@@ -905,7 +905,7 @@ Parser::parseTypeSimpleOrComposition(Diag<> MessageID,
905905
}
906906

907907
// Diagnose invalid `some` after an ampersand.
908-
if (Tok.is(tok::identifier) && Tok.getRawText() == "some") {
908+
if (Tok.isContextualKeyword("some")) {
909909
auto badLoc = consumeToken();
910910

911911
diagnose(badLoc, diag::opaque_mid_composition)
@@ -1094,7 +1094,7 @@ ParserResult<TypeRepr> Parser::parseTypeTupleBody() {
10941094
// If the label is "some", this could end up being an opaque type
10951095
// description if there's `some <identifier>` without a following colon,
10961096
// so we may need to backtrack as well.
1097-
if (Tok.getText().equals("some")) {
1097+
if (Tok.isContextualKeyword("some")) {
10981098
Backtracking.emplace(*this);
10991099
}
11001100

@@ -1531,6 +1531,9 @@ bool Parser::canParseType() {
15311531
// Accept 'inout' at for better recovery.
15321532
consumeIf(tok::kw_inout);
15331533

1534+
if (Tok.isContextualKeyword("some"))
1535+
consumeToken();
1536+
15341537
switch (Tok.getKind()) {
15351538
case tok::kw_Self:
15361539
case tok::kw_Any:

test/type/opaque.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct Test {
7373
let inferredOpaqueStructural2 = (bar(), bas()) // expected-error{{inferred type}}
7474
}
7575

76-
//let zingle = {() -> some P in 1 } // FIXME ex/pected-error{{'some' types are only implemented}}
76+
let zingle = {() -> some P in 1 } // expected-error{{'some' types are only implemented}}
7777

7878
// Invalid positions
7979

0 commit comments

Comments
 (0)