Skip to content

[Parse] Set missing contextual keyword token kind for async #58912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Parse/ParsePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ ParserStatus Parser::parseEffectsSpecifiers(SourceLoc existingArrowLoc,
.fixItInsert(throwsLoc, isReasync ? "reasync " : "async ");
}
if (asyncLoc.isInvalid()) {
Tok.setKind(tok::contextual_keyword);
if (reasync)
*reasync = isReasync;
asyncLoc = Tok.getLoc();
Expand Down
2 changes: 2 additions & 0 deletions test/IDE/coloring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ protocol Prot {
var protocolProperty1: Int { get }
// CHECK: <kw>var</kw> protocolProperty2: <type>Int</type> { <kw>get</kw> <kw>set</kw> }
var protocolProperty2: Int { get set }
// CHECK: <kw>var</kw> protoAsyncProp: <type>Int</type> { <kw>get</kw> <kw>async</kw> }
var protoAsyncProp: Int { get async }
}

// CHECK: <attr-builtin>infix</attr-builtin> <kw>operator</kw> *-* : FunnyPrecedence{{$}}
Expand Down
4 changes: 4 additions & 0 deletions test/SourceKit/SyntaxMapData/Inputs/syntaxmap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ enum A {
case namedArguments(param1: String, param2: Int)
case mutedArguments(String, Int)
}

protocol AsyncPropTest {
var protoAsyncProp: Int { get async }
}
37 changes: 36 additions & 1 deletion test/SourceKit/SyntaxMapData/syntaxmap.swift.response
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
key.offset: 0,
key.length: 1325,
key.length: 1393,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.syntaxmap: [
{
Expand Down Expand Up @@ -707,6 +707,41 @@
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 1318,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 1326,
key.length: 8
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 1335,
key.length: 13
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 1353,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 1357,
key.length: 14
},
{
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 1373,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 1379,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 1383,
key.length: 5
}
]
}
2 changes: 1 addition & 1 deletion unittests/Syntax/TypeSyntaxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ TEST(TypeSyntaxTests, FunctionTypeMakeAPIs) {
auto RightParen = Factory.makeRightParenToken("", " ");
auto Int = Factory.makeTypeIdentifier("Int", "", "");
auto IntArg = Factory.makeBlankTupleTypeElement().withType(Int);
auto Async = Factory.makeIdentifier("async", "", " ");
auto Async = Factory.makeContextualKeyword("async", "", " ");
auto Throws = Factory.makeThrowsKeyword("", " ");
auto Rethrows = Factory.makeRethrowsKeyword("", " ");
auto Arrow = Factory.makeArrowToken("", " ");
Expand Down
6 changes: 2 additions & 4 deletions utils/gyb_syntax_support/DeclNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
Node('FunctionSignature', kind='Syntax',
children=[
Child('Input', kind='ParameterClause'),
Child('AsyncOrReasyncKeyword', kind='IdentifierToken',
classification='Keyword',
Child('AsyncOrReasyncKeyword', kind='ContextualKeywordToken',
text_choices=['async', 'reasync'], is_optional=True),
Child('ThrowsOrRethrowsKeyword', kind='Token',
is_optional=True,
Expand Down Expand Up @@ -538,8 +537,7 @@
'_read', '_modify'
]),
Child('Parameter', kind='AccessorParameter', is_optional=True),
Child('AsyncKeyword', kind='IdentifierToken',
classification='Keyword',
Child('AsyncKeyword', kind='ContextualKeywordToken',
text_choices=['async'], is_optional=True),
Child('ThrowsKeyword', kind='Token',
is_optional=True,
Expand Down
6 changes: 2 additions & 4 deletions utils/gyb_syntax_support/ExprNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@
# NOTE: This appears only in SequenceExpr.
Node('ArrowExpr', kind='Expr',
children=[
Child('AsyncKeyword', kind='IdentifierToken',
classification='Keyword',
Child('AsyncKeyword', kind='ContextualKeywordToken',
text_choices=['async'], is_optional=True),
Child('ThrowsToken', kind='ThrowsToken',
is_optional=True),
Expand Down Expand Up @@ -394,8 +393,7 @@
Child('SimpleInput', kind='ClosureParamList'),
Child('Input', kind='ParameterClause'),
]),
Child('AsyncKeyword', kind='IdentifierToken',
classification='Keyword',
Child('AsyncKeyword', kind='ContextualKeywordToken',
text_choices=['async'], is_optional=True),
Child('ThrowsTok', kind='ThrowsToken', is_optional=True),
Child('Output', kind='ReturnClause', is_optional=True),
Expand Down
3 changes: 1 addition & 2 deletions utils/gyb_syntax_support/TypeNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@
Child('Arguments', kind='TupleTypeElementList',
collection_element_name='Argument'),
Child('RightParen', kind='RightParenToken'),
Child('AsyncKeyword', kind='IdentifierToken',
classification='Keyword',
Child('AsyncKeyword', kind='ContextualKeyworkToken',
text_choices=['async'], is_optional=True),
Child('ThrowsOrRethrowsKeyword', kind='Token',
is_optional=True,
Expand Down