Skip to content
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
2 changes: 1 addition & 1 deletion lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
SourceLoc awaitLoc = consumeToken(tok::kw___await);
ParserResult<Expr> sub = parseExprUnary(message, isExprBasic);
if (!sub.hasCodeCompletion() && !sub.isNull()) {
ElementContext.setCreateSyntax(SyntaxKind::TryExpr);
ElementContext.setCreateSyntax(SyntaxKind::AwaitExpr);
sub = makeParserResult(new (Context) AwaitExpr(awaitLoc, sub.get()));
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,10 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID,
ParsedFunctionTypeSyntaxBuilder Builder(*SyntaxContext);
Builder.useReturnType(std::move(*SyntaxContext->popIf<ParsedTypeSyntax>()));
Builder.useArrow(SyntaxContext->popToken());
if (asyncLoc.isValid())
Builder.useAsyncKeyword(SyntaxContext->popToken());
if (throwsLoc.isValid())
Builder.useThrowsOrRethrowsKeyword(SyntaxContext->popToken());
if (asyncLoc.isValid())
Builder.useAsyncKeyword(SyntaxContext->popToken());

auto InputNode(std::move(*SyntaxContext->popIf<ParsedTypeSyntax>()));
if (auto TupleTypeNode = InputNode.getAs<ParsedTupleTypeSyntax>()) {
Expand Down
16 changes: 16 additions & 0 deletions test/Parse/async-syntax.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -verify-syntax-tree

func asyncGlobal1() async { }
func asyncGlobal2() async throws { }

typealias AsyncFunc1 = () async -> ()
typealias AsyncFunc2 = () async throws -> ()

func testTypeExprs() {
let _ = [() async -> ()]()
let _ = [() async throws -> ()]()
}

func testAwaitOperator() async {
let _ = __await asyncGlobal1()
}
1 change: 1 addition & 0 deletions test/Serialization/Inputs/def_async.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public func doSomethingBig() async -> Int { return 0 }
11 changes: 11 additions & 0 deletions test/Serialization/async.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t-scratch)
// RUN: %target-swift-frontend -emit-module -o %t-scratch/def_async~partial.swiftmodule -primary-file %S/Inputs/def_async.swift -module-name def_async -enable-experimental-concurrency
// RUN: %target-swift-frontend -merge-modules -emit-module -parse-as-library -enable-testing %t-scratch/def_async~partial.swiftmodule -module-name def_async -o %t/def_async.swiftmodule -enable-experimental-concurrency
// RUN: %target-swift-frontend -typecheck -I%t -verify %s -verify-ignore-unknown -enable-experimental-concurrency

import def_async

func testDoSomethingBig() {
let _: () -> Int = doSomethingBig // expected-error{{cannot convert value of type '() async -> Int' to specified type '() -> Int'}}
}
2 changes: 1 addition & 1 deletion unittests/Syntax/TypeSyntaxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ TEST(TypeSyntaxTests, FunctionTypeMakeAPIs) {
auto Int = SyntaxFactory::makeTypeIdentifier("Int", {}, {});
auto IntArg = SyntaxFactory::makeBlankTupleTypeElement()
.withType(Int);
auto Async = SyntaxFactory::makeContextualKeyword(
auto Async = SyntaxFactory::makeIdentifier(
"async", { }, { Trivia::spaces(1) });
auto Throws = SyntaxFactory::makeThrowsKeyword({}, { Trivia::spaces(1) });
auto Rethrows = SyntaxFactory::makeRethrowsKeyword({},
Expand Down
3 changes: 2 additions & 1 deletion utils/gyb_syntax_support/DeclNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
Node('FunctionSignature', kind='Syntax',
children=[
Child('Input', kind='ParameterClause'),
Child('AsyncKeyword', kind='ContextualKeywordToken',
Child('AsyncKeyword', kind='IdentifierToken',
classification='Keyword',
text_choices=['async'], is_optional=True),
Child('ThrowsOrRethrowsKeyword', kind='Token',
is_optional=True,
Expand Down
3 changes: 2 additions & 1 deletion utils/gyb_syntax_support/ExprNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@
# NOTE: This appears only in SequenceExpr.
Node('ArrowExpr', kind='Expr',
children=[
Child('AsyncKeyword', kind='ContextualKeywordToken',
Child('AsyncKeyword', kind='IdentifierToken',
classification='Keyword',
text_choices=['async'], is_optional=True),
Child('ThrowsToken', kind='ThrowsToken',
is_optional=True),
Expand Down
5 changes: 3 additions & 2 deletions utils/gyb_syntax_support/TypeNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@
Child('Arguments', kind='TupleTypeElementList',
collection_element_name='Argument'),
Child('RightParen', kind='RightParenToken'),
Child('AsyncKeyword', kind='Token', text_choices=['async'],
is_optional=True),
Child('AsyncKeyword', kind='IdentifierToken',
classification='Keyword',
text_choices=['async'], is_optional=True),
Child('ThrowsOrRethrowsKeyword', kind='Token',
is_optional=True,
token_choices=[
Expand Down