diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 1009646c1c40e..d7f77869d6723 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -397,7 +397,7 @@ ParserResult Parser::parseExprSequenceElement(Diag<> message, SourceLoc awaitLoc = consumeToken(tok::kw___await); ParserResult 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())); } diff --git a/lib/Parse/ParseType.cpp b/lib/Parse/ParseType.cpp index 443f572c04acb..aefea2401c15a 100644 --- a/lib/Parse/ParseType.cpp +++ b/lib/Parse/ParseType.cpp @@ -465,10 +465,10 @@ ParserResult Parser::parseType(Diag<> MessageID, ParsedFunctionTypeSyntaxBuilder Builder(*SyntaxContext); Builder.useReturnType(std::move(*SyntaxContext->popIf())); 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())); if (auto TupleTypeNode = InputNode.getAs()) { diff --git a/test/Parse/async-syntax.swift b/test/Parse/async-syntax.swift new file mode 100644 index 0000000000000..54c1bac839969 --- /dev/null +++ b/test/Parse/async-syntax.swift @@ -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() +} diff --git a/test/Serialization/Inputs/def_async.swift b/test/Serialization/Inputs/def_async.swift new file mode 100644 index 0000000000000..e74faed0ab5b7 --- /dev/null +++ b/test/Serialization/Inputs/def_async.swift @@ -0,0 +1 @@ +public func doSomethingBig() async -> Int { return 0 } diff --git a/test/Serialization/async.swift b/test/Serialization/async.swift new file mode 100644 index 0000000000000..cbf1019a3cdc8 --- /dev/null +++ b/test/Serialization/async.swift @@ -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'}} +} diff --git a/unittests/Syntax/TypeSyntaxTests.cpp b/unittests/Syntax/TypeSyntaxTests.cpp index 22711ccc0d92f..267d8787335cb 100644 --- a/unittests/Syntax/TypeSyntaxTests.cpp +++ b/unittests/Syntax/TypeSyntaxTests.cpp @@ -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({}, diff --git a/utils/gyb_syntax_support/DeclNodes.py b/utils/gyb_syntax_support/DeclNodes.py index a6455574654ce..515ea4fe02723 100644 --- a/utils/gyb_syntax_support/DeclNodes.py +++ b/utils/gyb_syntax_support/DeclNodes.py @@ -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, diff --git a/utils/gyb_syntax_support/ExprNodes.py b/utils/gyb_syntax_support/ExprNodes.py index 730c9bf0d92cb..8b442d8c307a1 100644 --- a/utils/gyb_syntax_support/ExprNodes.py +++ b/utils/gyb_syntax_support/ExprNodes.py @@ -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), diff --git a/utils/gyb_syntax_support/TypeNodes.py b/utils/gyb_syntax_support/TypeNodes.py index 87dbed52dfd16..527dc4d3ccd40 100644 --- a/utils/gyb_syntax_support/TypeNodes.py +++ b/utils/gyb_syntax_support/TypeNodes.py @@ -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=[