From c81ebd08d31ef199284671bed42e503beb132251 Mon Sep 17 00:00:00 2001 From: daizihan Date: Sat, 2 Aug 2025 19:48:24 +0800 Subject: [PATCH] Add cte for await in non-async function Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICQO6M?from=project-issue Signed-off-by: daizihan --- ets2panda/checker/ETSAnalyzer.cpp | 18 + .../ast/compiler/ets/unexpected_param_01.ets | 3 +- .../test/ast/parser/ets/await_priority.ets | 3 +- .../parser/ets/dynmicImportUnimplemented.ets | 2 +- .../ast/parser/ets/unexpected_token_22.ets | 1 + .../asyncfunc_lambda_main-expected.txt | 263 ++++++- .../import_tests/asyncfunc_lambda_main.ets | 6 +- .../ets/await_complex_promise-expected.txt | 730 +++++++++++++----- .../test/parser/ets/await_complex_promise.ets | 10 +- .../parser/ets/await_keyword-expected.txt | 235 +++++- ets2panda/test/parser/ets/await_keyword.ets | 4 +- .../test/runtime/ets/ThisInAsyncMethod.ets | 7 +- .../async-func-overload-and-type-infer.ets | 6 +- ...c_and_instance_method_with_same_name01.ets | 6 +- ...c_and_instance_method_with_same_name02.ets | 6 +- .../test/runtime/ets/async_lambda_box.ets | 2 +- .../ets/async_method_with_same_name01.ets | 6 +- .../ets/async_method_with_same_name02.ets | 6 +- ets2panda/test/runtime/ets/async_optional.ets | 6 +- ets2panda/test/runtime/ets/async_overload.ets | 6 +- .../async-func-overload-and-type-infer.ets | 6 +- .../async_method_with_same_name02.ets | 10 +- .../ast_verifier_variable_has_scope_test.cpp | 6 +- ets2panda/util/diagnostic/syntax.yaml | 4 + 24 files changed, 1085 insertions(+), 267 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 95113ed59c..6e52264694 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -1324,6 +1324,20 @@ static bool IsPromiseType(checker::Type *type, ETSChecker *checker) type->AsETSObjectType()->GetOriginalBaseType() == checker->GlobalBuiltinPromiseType(); } +static bool CheckAwaitExpressionInAsyncFunc(ir::AwaitExpression *expr) +{ + ir::AstNode *node = expr; + while (node != nullptr) { + if (node->IsScriptFunction() && + (node->AsScriptFunction()->IsAsyncFunc() || node->AsScriptFunction()->IsAsyncImplFunc())) { + return true; + } else { + node = node->Parent(); + } + } + return false; +} + checker::Type *ETSAnalyzer::Check(ir::AwaitExpression *expr) const { ETSChecker *checker = GetETSChecker(); @@ -1331,6 +1345,10 @@ checker::Type *ETSAnalyzer::Check(ir::AwaitExpression *expr) const return expr->TsType(); } + if (!CheckAwaitExpressionInAsyncFunc(expr)) { + return checker->TypeError(expr, diagnostic::AWAIT_MUST_IN_ASYNC_FUNCTION, expr->Argument()->Start()); + } + checker::Type *argType = checker->GetApparentType(expr->argument_->Check(checker)); ArenaVector awaitedTypes(checker->ProgramAllocator()->Adapter()); diff --git a/ets2panda/test/ast/compiler/ets/unexpected_param_01.ets b/ets2panda/test/ast/compiler/ets/unexpected_param_01.ets index 5e15bcbf7d..def4f2d689 100644 --- a/ets2panda/test/ast/compiler/ets/unexpected_param_01.ets +++ b/ets2panda/test/ast/compiler/ets/unexpected_param_01.ets @@ -29,4 +29,5 @@ await byteP; /* @@? 17:50 Error SyntaxError: Unexpected token 'Object'. */ /* @@? 17:50 Error TypeError: The type of parameter 'Object' cannot be inferred */ /* @@? 18:12 Error TypeError: Unresolved reference value */ -/* @@? 20:2 Error SyntaxError: Unexpected token ')'. */ \ No newline at end of file +/* @@? 20:2 Error SyntaxError: Unexpected token ')'. */ +/* @@? 21:7 Error SyntaxError: Using await outside of async function is forbidden. */ diff --git a/ets2panda/test/ast/parser/ets/await_priority.ets b/ets2panda/test/ast/parser/ets/await_priority.ets index 4e77ac3504..d98c5292ef 100644 --- a/ets2panda/test/ast/parser/ets/await_priority.ets +++ b/ets2panda/test/ast/parser/ets/await_priority.ets @@ -14,8 +14,7 @@ */ function main(){ - await test(); - + test(); } async function test() { diff --git a/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets b/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets index d1988ddb9f..afc73414c5 100644 --- a/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets +++ b/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets @@ -28,4 +28,4 @@ function main() { } /* @@? 18:15 Error SyntaxError: Unexpected token 'import'. */ -/* @@? 18:15 Error TypeError: 'await' expressions require Promise object as argument. */ +/* @@? 18:15 Error SyntaxError: Using await outside of async function is forbidden. */ diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_22.ets b/ets2panda/test/ast/parser/ets/unexpected_token_22.ets index 19b5147c4d..8ba4500cc5 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_22.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_22.ets @@ -40,3 +40,4 @@ function main(): void { /* @@? 25:43 Error TypeError: Type '(_: Promise) => Promise' cannot be assigned to type '() => Promise' */ /* @@? 25:44 Error SyntaxError: Unexpected token, expected an identifier. */ /* @@? 25:60 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 31:11 Error SyntaxError: Using await outside of async function is forbidden. */ diff --git a/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main-expected.txt b/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main-expected.txt index 9ae6ae1cfb..94b2beadf8 100644 --- a/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main-expected.txt +++ b/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main-expected.txt @@ -462,17 +462,17 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "main", + "name": "asyncFoo", "decorators": [], "loc": { "start": { "line": 22, - "column": 10, + "column": 16, "program": "asyncfunc_lambda_main.ets" }, "end": { "line": 22, - "column": 14, + "column": 24, "program": "asyncfunc_lambda_main.ets" } } @@ -488,36 +488,100 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "main", + "name": "asyncFoo", "decorators": [], "loc": { "start": { "line": 22, - "column": 10, + "column": 16, "program": "asyncfunc_lambda_main.ets" }, "end": { "line": 22, - "column": 14, + "column": 24, "program": "asyncfunc_lambda_main.ets" } } }, "generator": false, - "async": false, + "async": true, "expression": false, "params": [], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 28, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 22, + "column": 35, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 36, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 22, + "column": 40, + "program": "asyncfunc_lambda_main.ets" + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 35, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 22, + "column": 41, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 28, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 22, + "column": 41, + "program": "asyncfunc_lambda_main.ets" + } + } + }, "loc": { "start": { "line": 22, - "column": 18, + "column": 28, "program": "asyncfunc_lambda_main.ets" }, "end": { "line": 22, - "column": 22, + "column": 41, "program": "asyncfunc_lambda_main.ets" } } @@ -1583,7 +1647,7 @@ "loc": { "start": { "line": 22, - "column": 23, + "column": 42, "program": "asyncfunc_lambda_main.ets" }, "end": { @@ -1596,7 +1660,7 @@ "loc": { "start": { "line": 22, - "column": 10, + "column": 16, "program": "asyncfunc_lambda_main.ets" }, "end": { @@ -1609,7 +1673,7 @@ "loc": { "start": { "line": 22, - "column": 10, + "column": 16, "program": "asyncfunc_lambda_main.ets" }, "end": { @@ -1633,6 +1697,177 @@ "program": "asyncfunc_lambda_main.ets" } } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 10, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 36, + "column": 14, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 10, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 36, + "column": 14, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 36, + "column": 18, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 36, + "column": 22, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "asyncFoo", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 5, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 37, + "column": 13, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 5, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 37, + "column": 15, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 5, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 37, + "column": 15, + "program": "asyncfunc_lambda_main.ets" + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 23, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 38, + "column": 2, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 10, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 38, + "column": 2, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 10, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 38, + "column": 2, + "program": "asyncfunc_lambda_main.ets" + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 1, + "program": "asyncfunc_lambda_main.ets" + }, + "end": { + "line": 38, + "column": 2, + "program": "asyncfunc_lambda_main.ets" + } + } } ], "loc": { @@ -1669,7 +1904,7 @@ "program": "asyncfunc_lambda_main.ets" }, "end": { - "line": 35, + "line": 39, "column": 1, "program": "asyncfunc_lambda_main.ets" } diff --git a/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main.ets b/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main.ets index 000e77b934..9ae4b2079a 100644 --- a/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main.ets +++ b/ets2panda/test/compiler/ets/import_tests/asyncfunc_lambda_main.ets @@ -19,7 +19,7 @@ import { CC } from "./asyncfun_lambda_lib" import { DC } from "./asyncfun_lambda_lib" -function main(): void { +async function asyncFoo(): Promise { let aClass: AC = new AC(); await aClass.foo(); @@ -32,3 +32,7 @@ function main(): void { let dClass: DC = new DC(); dClass.foz(); } + +function main(): void { + asyncFoo() +} diff --git a/ets2panda/test/parser/ets/await_complex_promise-expected.txt b/ets2panda/test/parser/ets/await_complex_promise-expected.txt index 1a81850799..e4a365838e 100644 --- a/ets2panda/test/parser/ets/await_complex_promise-expected.txt +++ b/ets2panda/test/parser/ets/await_complex_promise-expected.txt @@ -452,12 +452,12 @@ "loc": { "start": { "line": 16, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } @@ -478,18 +478,18 @@ "loc": { "start": { "line": 16, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } }, "generator": false, - "async": false, + "async": true, "expression": false, "params": [ { @@ -508,12 +508,12 @@ "loc": { "start": { "line": 16, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" } } @@ -532,12 +532,12 @@ "loc": { "start": { "line": 16, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 33, + "column": 39, "program": "await_complex_promise.ets" } } @@ -556,12 +556,12 @@ "loc": { "start": { "line": 16, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -569,12 +569,12 @@ "loc": { "start": { "line": 16, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -582,12 +582,12 @@ "loc": { "start": { "line": 16, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -596,12 +596,12 @@ "loc": { "start": { "line": 16, - "column": 33, + "column": 39, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } @@ -609,12 +609,12 @@ "loc": { "start": { "line": 16, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } @@ -622,12 +622,12 @@ "loc": { "start": { "line": 16, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } @@ -636,12 +636,12 @@ "loc": { "start": { "line": 16, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } @@ -649,12 +649,12 @@ "loc": { "start": { "line": 16, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } @@ -662,12 +662,12 @@ "loc": { "start": { "line": 16, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } @@ -676,12 +676,12 @@ "loc": { "start": { "line": 16, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } @@ -689,28 +689,92 @@ "loc": { "start": { "line": 16, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" } } } ], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 51, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 16, + "column": 58, + "program": "await_complex_promise.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 59, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 16, + "column": 63, + "program": "await_complex_promise.ets" + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 58, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 16, + "column": 64, + "program": "await_complex_promise.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 51, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 16, + "column": 64, + "program": "await_complex_promise.ets" + } + } + }, "loc": { "start": { "line": 16, - "column": 45, + "column": 51, "program": "await_complex_promise.ets" }, "end": { "line": 16, - "column": 49, + "column": 64, "program": "await_complex_promise.ets" } } @@ -851,7 +915,7 @@ "loc": { "start": { "line": 16, - "column": 50, + "column": 65, "program": "await_complex_promise.ets" }, "end": { @@ -864,7 +928,7 @@ "loc": { "start": { "line": 16, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -877,7 +941,7 @@ "loc": { "start": { "line": 16, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -911,12 +975,12 @@ "loc": { "start": { "line": 20, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } @@ -937,18 +1001,18 @@ "loc": { "start": { "line": 20, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } }, "generator": false, - "async": false, + "async": true, "expression": false, "params": [ { @@ -967,12 +1031,12 @@ "loc": { "start": { "line": 20, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" } } @@ -994,12 +1058,12 @@ "loc": { "start": { "line": 20, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 33, + "column": 39, "program": "await_complex_promise.ets" } } @@ -1018,12 +1082,12 @@ "loc": { "start": { "line": 20, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -1031,12 +1095,12 @@ "loc": { "start": { "line": 20, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -1044,12 +1108,12 @@ "loc": { "start": { "line": 20, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -1058,12 +1122,12 @@ "loc": { "start": { "line": 20, - "column": 33, + "column": 39, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 41, + "column": 47, "program": "await_complex_promise.ets" } } @@ -1071,12 +1135,12 @@ "loc": { "start": { "line": 20, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 41, + "column": 47, "program": "await_complex_promise.ets" } } @@ -1084,12 +1148,12 @@ "loc": { "start": { "line": 20, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 41, + "column": 47, "program": "await_complex_promise.ets" } } @@ -1105,12 +1169,12 @@ "loc": { "start": { "line": 20, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 48, + "column": 54, "program": "await_complex_promise.ets" } } @@ -1118,12 +1182,12 @@ "loc": { "start": { "line": 20, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 48, + "column": 54, "program": "await_complex_promise.ets" } } @@ -1131,12 +1195,12 @@ "loc": { "start": { "line": 20, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 48, + "column": 54, "program": "await_complex_promise.ets" } } @@ -1145,12 +1209,12 @@ "loc": { "start": { "line": 20, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 48, + "column": 54, "program": "await_complex_promise.ets" } } @@ -1159,12 +1223,12 @@ "loc": { "start": { "line": 20, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 49, + "column": 55, "program": "await_complex_promise.ets" } } @@ -1172,12 +1236,12 @@ "loc": { "start": { "line": 20, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 49, + "column": 55, "program": "await_complex_promise.ets" } } @@ -1185,12 +1249,12 @@ "loc": { "start": { "line": 20, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 49, + "column": 55, "program": "await_complex_promise.ets" } } @@ -1199,12 +1263,12 @@ "loc": { "start": { "line": 20, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 49, + "column": 55, "program": "await_complex_promise.ets" } } @@ -1212,28 +1276,92 @@ "loc": { "start": { "line": 20, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 49, + "column": 55, "program": "await_complex_promise.ets" } } } ], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 58, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 20, + "column": 65, + "program": "await_complex_promise.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 20, + "column": 66, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 20, + "column": 70, + "program": "await_complex_promise.ets" + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 65, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 20, + "column": 71, + "program": "await_complex_promise.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 58, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 20, + "column": 71, + "program": "await_complex_promise.ets" + } + } + }, "loc": { "start": { "line": 20, - "column": 52, + "column": 58, "program": "await_complex_promise.ets" }, "end": { "line": 20, - "column": 56, + "column": 71, "program": "await_complex_promise.ets" } } @@ -1438,7 +1566,7 @@ "loc": { "start": { "line": 20, - "column": 57, + "column": 72, "program": "await_complex_promise.ets" }, "end": { @@ -1451,7 +1579,7 @@ "loc": { "start": { "line": 20, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -1464,7 +1592,7 @@ "loc": { "start": { "line": 20, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -1498,12 +1626,12 @@ "loc": { "start": { "line": 24, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } @@ -1524,18 +1652,18 @@ "loc": { "start": { "line": 24, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } }, "generator": false, - "async": false, + "async": true, "expression": false, "params": [ { @@ -1554,12 +1682,12 @@ "loc": { "start": { "line": 24, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" } } @@ -1581,12 +1709,12 @@ "loc": { "start": { "line": 24, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 33, + "column": 39, "program": "await_complex_promise.ets" } } @@ -1605,12 +1733,12 @@ "loc": { "start": { "line": 24, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -1618,12 +1746,12 @@ "loc": { "start": { "line": 24, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -1631,12 +1759,12 @@ "loc": { "start": { "line": 24, - "column": 34, + "column": 40, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 40, + "column": 46, "program": "await_complex_promise.ets" } } @@ -1645,12 +1773,12 @@ "loc": { "start": { "line": 24, - "column": 33, + "column": 39, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 41, + "column": 47, "program": "await_complex_promise.ets" } } @@ -1658,12 +1786,12 @@ "loc": { "start": { "line": 24, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 41, + "column": 47, "program": "await_complex_promise.ets" } } @@ -1671,12 +1799,12 @@ "loc": { "start": { "line": 24, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 41, + "column": 47, "program": "await_complex_promise.ets" } } @@ -1692,12 +1820,12 @@ "loc": { "start": { "line": 24, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 49, + "column": 55, "program": "await_complex_promise.ets" } } @@ -1716,12 +1844,12 @@ "loc": { "start": { "line": 24, - "column": 50, + "column": 56, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 56, + "column": 62, "program": "await_complex_promise.ets" } } @@ -1729,12 +1857,12 @@ "loc": { "start": { "line": 24, - "column": 50, + "column": 56, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 56, + "column": 62, "program": "await_complex_promise.ets" } } @@ -1742,12 +1870,12 @@ "loc": { "start": { "line": 24, - "column": 50, + "column": 56, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 56, + "column": 62, "program": "await_complex_promise.ets" } } @@ -1756,12 +1884,12 @@ "loc": { "start": { "line": 24, - "column": 49, + "column": 55, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1769,12 +1897,12 @@ "loc": { "start": { "line": 24, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1782,12 +1910,12 @@ "loc": { "start": { "line": 24, - "column": 42, + "column": 48, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1796,12 +1924,12 @@ "loc": { "start": { "line": 24, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1810,12 +1938,12 @@ "loc": { "start": { "line": 24, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1823,12 +1951,12 @@ "loc": { "start": { "line": 24, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1836,12 +1964,12 @@ "loc": { "start": { "line": 24, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1850,12 +1978,12 @@ "loc": { "start": { "line": 24, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } @@ -1863,28 +1991,92 @@ "loc": { "start": { "line": 24, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 58, + "column": 64, "program": "await_complex_promise.ets" } } } ], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 67, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 24, + "column": 74, + "program": "await_complex_promise.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 24, + "column": 75, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 24, + "column": 79, + "program": "await_complex_promise.ets" + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 74, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 24, + "column": 80, + "program": "await_complex_promise.ets" + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 67, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 24, + "column": 80, + "program": "await_complex_promise.ets" + } + } + }, "loc": { "start": { "line": 24, - "column": 61, + "column": 67, "program": "await_complex_promise.ets" }, "end": { "line": 24, - "column": 65, + "column": 80, "program": "await_complex_promise.ets" } } @@ -2089,7 +2281,7 @@ "loc": { "start": { "line": 24, - "column": 66, + "column": 81, "program": "await_complex_promise.ets" }, "end": { @@ -2102,7 +2294,7 @@ "loc": { "start": { "line": 24, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -2115,7 +2307,7 @@ "loc": { "start": { "line": 24, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -2149,12 +2341,12 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } @@ -2175,18 +2367,18 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } }, "generator": false, - "async": false, + "async": true, "expression": false, "params": [ { @@ -2205,12 +2397,12 @@ "loc": { "start": { "line": 28, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" } } @@ -2226,12 +2418,12 @@ "loc": { "start": { "line": 28, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 30, + "column": 36, "program": "await_complex_promise.ets" } } @@ -2247,12 +2439,12 @@ "loc": { "start": { "line": 28, - "column": 31, + "column": 37, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 38, + "column": 44, "program": "await_complex_promise.ets" } } @@ -2271,12 +2463,12 @@ "loc": { "start": { "line": 28, - "column": 39, + "column": 45, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 45, + "column": 51, "program": "await_complex_promise.ets" } } @@ -2284,12 +2476,12 @@ "loc": { "start": { "line": 28, - "column": 39, + "column": 45, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 45, + "column": 51, "program": "await_complex_promise.ets" } } @@ -2297,12 +2489,12 @@ "loc": { "start": { "line": 28, - "column": 39, + "column": 45, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 45, + "column": 51, "program": "await_complex_promise.ets" } } @@ -2311,12 +2503,12 @@ "loc": { "start": { "line": 28, - "column": 38, + "column": 44, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2324,12 +2516,12 @@ "loc": { "start": { "line": 28, - "column": 31, + "column": 37, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2337,12 +2529,12 @@ "loc": { "start": { "line": 28, - "column": 31, + "column": 37, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2351,12 +2543,12 @@ "loc": { "start": { "line": 28, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2365,12 +2557,12 @@ "loc": { "start": { "line": 28, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2378,12 +2570,12 @@ "loc": { "start": { "line": 28, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2391,12 +2583,12 @@ "loc": { "start": { "line": 28, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2405,12 +2597,12 @@ "loc": { "start": { "line": 28, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } @@ -2418,28 +2610,92 @@ "loc": { "start": { "line": 28, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 47, + "column": 53, "program": "await_complex_promise.ets" } } } ], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 56, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 28, + "column": 63, + "program": "await_complex_promise.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 28, + "column": 64, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 28, + "column": 68, + "program": "await_complex_promise.ets" + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 63, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 28, + "column": 69, + "program": "await_complex_promise.ets" + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 56, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 28, + "column": 69, + "program": "await_complex_promise.ets" + } + } + }, "loc": { "start": { "line": 28, - "column": 50, + "column": 56, "program": "await_complex_promise.ets" }, "end": { "line": 28, - "column": 54, + "column": 69, "program": "await_complex_promise.ets" } } @@ -2612,7 +2868,7 @@ "loc": { "start": { "line": 28, - "column": 55, + "column": 70, "program": "await_complex_promise.ets" }, "end": { @@ -2625,7 +2881,7 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -2638,7 +2894,7 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -2672,12 +2928,12 @@ "loc": { "start": { "line": 33, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } @@ -2698,18 +2954,18 @@ "loc": { "start": { "line": 33, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 14, + "column": 20, "program": "await_complex_promise.ets" } } }, "generator": false, - "async": false, + "async": true, "expression": false, "params": [ { @@ -2728,12 +2984,12 @@ "loc": { "start": { "line": 33, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" } } @@ -2752,12 +3008,12 @@ "loc": { "start": { "line": 33, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 31, + "column": 37, "program": "await_complex_promise.ets" } } @@ -2765,12 +3021,12 @@ "loc": { "start": { "line": 33, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 31, + "column": 37, "program": "await_complex_promise.ets" } } @@ -2778,12 +3034,12 @@ "loc": { "start": { "line": 33, - "column": 26, + "column": 32, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 31, + "column": 37, "program": "await_complex_promise.ets" } } @@ -2792,12 +3048,12 @@ "loc": { "start": { "line": 33, - "column": 25, + "column": 31, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 32, + "column": 38, "program": "await_complex_promise.ets" } } @@ -2805,12 +3061,12 @@ "loc": { "start": { "line": 33, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 32, + "column": 38, "program": "await_complex_promise.ets" } } @@ -2818,12 +3074,12 @@ "loc": { "start": { "line": 33, - "column": 18, + "column": 24, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 32, + "column": 38, "program": "await_complex_promise.ets" } } @@ -2832,12 +3088,12 @@ "loc": { "start": { "line": 33, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 32, + "column": 38, "program": "await_complex_promise.ets" } } @@ -2845,28 +3101,92 @@ "loc": { "start": { "line": 33, - "column": 15, + "column": 21, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 32, + "column": 38, "program": "await_complex_promise.ets" } } } ], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 41, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 33, + "column": 48, + "program": "await_complex_promise.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 49, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 33, + "column": 53, + "program": "await_complex_promise.ets" + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 48, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 33, + "column": 54, + "program": "await_complex_promise.ets" + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 41, + "program": "await_complex_promise.ets" + }, + "end": { + "line": 33, + "column": 54, + "program": "await_complex_promise.ets" + } + } + }, "loc": { "start": { "line": 33, - "column": 35, + "column": 41, "program": "await_complex_promise.ets" }, "end": { "line": 33, - "column": 39, + "column": 54, "program": "await_complex_promise.ets" } } @@ -3071,7 +3391,7 @@ "loc": { "start": { "line": 33, - "column": 40, + "column": 55, "program": "await_complex_promise.ets" }, "end": { @@ -3084,7 +3404,7 @@ "loc": { "start": { "line": 33, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { @@ -3097,7 +3417,7 @@ "loc": { "start": { "line": 33, - "column": 10, + "column": 16, "program": "await_complex_promise.ets" }, "end": { diff --git a/ets2panda/test/parser/ets/await_complex_promise.ets b/ets2panda/test/parser/ets/await_complex_promise.ets index 6efaf5c538..f946480fbd 100644 --- a/ets2panda/test/parser/ets/await_complex_promise.ets +++ b/ets2panda/test/parser/ets/await_complex_promise.ets @@ -13,23 +13,23 @@ * limitations under the License. */ -function foo1(p: Promise>): void { +async function foo1(p: Promise>): Promise { let result: string = await p; } -function foo2(p: Promise|number>): void { +async function foo2(p: Promise|number>): Promise { let result: string|number = await p; } -function foo3(p: Promise|Promise>): void { +async function foo3(p: Promise|Promise>): Promise { let result: string|number = await p; } -function foo4(p: Promise>): void { +async function foo4(p: Promise>): Promise { let result: null|string = await p; } type Alias = Promise|number; -function foo5(p: Promise): void { +async function foo5(p: Promise): Promise { let result: string|number = await p; } diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index eb68f44567..6ce72538e5 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -1161,20 +1161,84 @@ "type": "ScriptFunction", "id": null, "generator": false, - "async": false, + "async": true, "expression": false, "params": [], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 45, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 52, + "program": "await_keyword.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 53, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 57, + "program": "await_keyword.ets" + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 52, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 58, + "program": "await_keyword.ets" + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 45, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 58, + "program": "await_keyword.ets" + } + } + }, "loc": { "start": { "line": 33, - "column": 30, + "column": 45, "program": "await_keyword.ets" }, "end": { "line": 33, - "column": 34, + "column": 58, "program": "await_keyword.ets" } } @@ -1862,7 +1926,7 @@ "loc": { "start": { "line": 33, - "column": 38, + "column": 62, "program": "await_keyword.ets" }, "end": { @@ -1875,7 +1939,7 @@ "loc": { "start": { "line": 33, - "column": 26, + "column": 41, "program": "await_keyword.ets" }, "end": { @@ -1888,7 +1952,7 @@ "loc": { "start": { "line": 33, - "column": 26, + "column": 41, "program": "await_keyword.ets" }, "end": { @@ -3304,12 +3368,12 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_keyword.ets" }, "end": { "line": 28, - "column": 13, + "column": 19, "program": "await_keyword.ets" } } @@ -3330,31 +3394,95 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_keyword.ets" }, "end": { "line": 28, - "column": 13, + "column": 19, "program": "await_keyword.ets" } } }, "generator": false, - "async": false, + "async": true, "expression": false, "params": [], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 23, + "program": "await_keyword.ets" + }, + "end": { + "line": 28, + "column": 30, + "program": "await_keyword.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 28, + "column": 31, + "program": "await_keyword.ets" + }, + "end": { + "line": 28, + "column": 35, + "program": "await_keyword.ets" + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 30, + "program": "await_keyword.ets" + }, + "end": { + "line": 28, + "column": 36, + "program": "await_keyword.ets" + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 23, + "program": "await_keyword.ets" + }, + "end": { + "line": 28, + "column": 36, + "program": "await_keyword.ets" + } + } + }, "loc": { "start": { "line": 28, - "column": 17, + "column": 23, "program": "await_keyword.ets" }, "end": { "line": 28, - "column": 21, + "column": 36, "program": "await_keyword.ets" } } @@ -4042,7 +4170,7 @@ "loc": { "start": { "line": 28, - "column": 22, + "column": 37, "program": "await_keyword.ets" }, "end": { @@ -4055,7 +4183,7 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_keyword.ets" }, "end": { @@ -4068,7 +4196,7 @@ "loc": { "start": { "line": 28, - "column": 10, + "column": 16, "program": "await_keyword.ets" }, "end": { @@ -4122,7 +4250,71 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 19, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 26, + "program": "await_keyword.ets" + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 27, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 31, + "program": "await_keyword.ets" + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 26, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 32, + "program": "await_keyword.ets" + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 19, + "program": "await_keyword.ets" + }, + "end": { + "line": 33, + "column": 32, + "program": "await_keyword.ets" + } + } + }, "loc": { "start": { "line": 33, @@ -4131,7 +4323,7 @@ }, "end": { "line": 33, - "column": 23, + "column": 32, "program": "await_keyword.ets" } } @@ -4144,7 +4336,7 @@ }, "end": { "line": 33, - "column": 23, + "column": 32, "program": "await_keyword.ets" } } @@ -4539,3 +4731,4 @@ } } } +SyntaxError: Using await outside of async function is forbidden. [await_keyword.ets:39:32] diff --git a/ets2panda/test/parser/ets/await_keyword.ets b/ets2panda/test/parser/ets/await_keyword.ets index b90d64d9bf..613a23cf43 100644 --- a/ets2panda/test/parser/ets/await_keyword.ets +++ b/ets2panda/test/parser/ets/await_keyword.ets @@ -25,12 +25,12 @@ let asyncLambda: () => Promise = async (): Promise return promise; } -function foo(): void { +async function foo(): Promise { let promise: Promise | null = (): Promise | null => { return null; }(); let obj: Object | null = await promise!; } -let lambda: () => void = (): void => { +let lambda: () => Promise = async (): Promise => { let promise: Promise | null = (): Promise | null => { return null; }(); let obj: Object | null = await promise!; } diff --git a/ets2panda/test/runtime/ets/ThisInAsyncMethod.ets b/ets2panda/test/runtime/ets/ThisInAsyncMethod.ets index 82ca7f094e..64b9dd5e7c 100644 --- a/ets2panda/test/runtime/ets/ThisInAsyncMethod.ets +++ b/ets2panda/test/runtime/ets/ThisInAsyncMethod.ets @@ -17,8 +17,11 @@ class X { async m(): Promise /* #19874 */ { return this } } -function main() { +async function asyncFoo(): Promise { let f = (): object | null | undefined => await new X().m() - arktest.assertTrue(f() instanceof X) } + +function main() { + asyncFoo() +} diff --git a/ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets b/ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets index 74b905de90..11635623e6 100644 --- a/ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets +++ b/ets2panda/test/runtime/ets/async-func-overload-and-type-infer.ets @@ -30,10 +30,14 @@ async function multipleReturns(flag: boolean): Promise { return "string2" } -function main() { +async function asyncFoo(): Promise { let a: int|string = await multipleReturns(true, 42); let b: int|string = await multipleReturns(false); arktest.assertEQ(a, 42) arktest.assertEQ(b, "string2") } + +function main() { + asyncFoo() +} diff --git a/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name01.ets b/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name01.ets index ec2ef06385..baa2e52386 100644 --- a/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name01.ets +++ b/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name01.ets @@ -22,9 +22,13 @@ class A{ } } -function main(){ +async function asyncFoo(): Promise { let res1:string = await new A().getData() let res2:string = A.getData("I'm a static method with name 'getData'") arktest.assertEQ(res1, "I'm a instance method with name 'getData'") arktest.assertEQ(res2, "I'm a static method with name 'getData'") } + +function main(){ + asyncFoo() +} diff --git a/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name02.ets b/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name02.ets index 8cd629b6de..c0b8408ce9 100644 --- a/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name02.ets +++ b/ets2panda/test/runtime/ets/async_and_instance_method_with_same_name02.ets @@ -22,9 +22,13 @@ class A{ } } -function main(){ +async function asyncFoo(): Promise { let res1:string = new A().getData() let res2:string = await A.getData("I'm a static method with name 'getData'") arktest.assertEQ(res1, "I'm a instance method with name 'getData'") arktest.assertEQ(res2, "I'm a static method with name 'getData'") } + +function main(){ + asyncFoo() +} diff --git a/ets2panda/test/runtime/ets/async_lambda_box.ets b/ets2panda/test/runtime/ets/async_lambda_box.ets index e737ad0190..305b49ad38 100644 --- a/ets2panda/test/runtime/ets/async_lambda_box.ets +++ b/ets2panda/test/runtime/ets/async_lambda_box.ets @@ -19,7 +19,7 @@ async function asyncFunc(): Promise { return true; } -function callAsyncLambda(): void { +async function callAsyncLambda(): Promise { let is_call_async_lambda: boolean = false; let async_lambda: asyncLambda = async (): Promise => { diff --git a/ets2panda/test/runtime/ets/async_method_with_same_name01.ets b/ets2panda/test/runtime/ets/async_method_with_same_name01.ets index a1aac4e6dc..646bf9c9d6 100644 --- a/ets2panda/test/runtime/ets/async_method_with_same_name01.ets +++ b/ets2panda/test/runtime/ets/async_method_with_same_name01.ets @@ -22,9 +22,13 @@ class A{ } } -function main(){ +async function asyncFoo(): Promise { let res1:string = await new A().getData() let res2:string = await A.getData("I'm a static method with name 'getData'") arktest.assertEQ(res1, "I'm a instance method with name 'getData'") arktest.assertEQ(res2, "I'm a static method with name 'getData'") } + +function main(){ + asyncFoo() +} diff --git a/ets2panda/test/runtime/ets/async_method_with_same_name02.ets b/ets2panda/test/runtime/ets/async_method_with_same_name02.ets index db334bdb7d..d50d3a1d85 100644 --- a/ets2panda/test/runtime/ets/async_method_with_same_name02.ets +++ b/ets2panda/test/runtime/ets/async_method_with_same_name02.ets @@ -22,10 +22,14 @@ class A{ } } -function main(){ +async function asyncFoo(): Promise { let res1:string = await A.getData() let res2:string = await A.getData("I'm a static method2 with name 'getData'") arktest.assertEQ(res1, "I'm a static method1 with name 'getData'") arktest.assertEQ(res2, "I'm a static method2 with name 'getData'") } +function main(){ + asyncFoo() +} + diff --git a/ets2panda/test/runtime/ets/async_optional.ets b/ets2panda/test/runtime/ets/async_optional.ets index 87d4a1059a..0c891bed82 100644 --- a/ets2panda/test/runtime/ets/async_optional.ets +++ b/ets2panda/test/runtime/ets/async_optional.ets @@ -22,9 +22,13 @@ class A { } } -function main() { +async function asyncFoo(): Promise { let t : InputT = {name: "zztest"}; let a : A = new A(); let b = await a.update(t); arktest.assertEQ(b, "zztest") +} + +function main() { + asyncFoo() } \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/async_overload.ets b/ets2panda/test/runtime/ets/async_overload.ets index f50ea63200..9dee0907c2 100644 --- a/ets2panda/test/runtime/ets/async_overload.ets +++ b/ets2panda/test/runtime/ets/async_overload.ets @@ -25,8 +25,12 @@ async function foo(a: int) { return 3 } -function main() { +async function asyncMain() { arktest.assertEQ(foo("test"), 1); arktest.assertEQ(await foo(), 2); arktest.assertEQ(await foo(1), 3); } + +function main() { + asyncMain(); +} diff --git a/ets2panda/test/runtime/ets/overload_declaration/async-func-overload-and-type-infer.ets b/ets2panda/test/runtime/ets/overload_declaration/async-func-overload-and-type-infer.ets index 0b99a3f81d..05ccecd717 100644 --- a/ets2panda/test/runtime/ets/overload_declaration/async-func-overload-and-type-infer.ets +++ b/ets2panda/test/runtime/ets/overload_declaration/async-func-overload-and-type-infer.ets @@ -32,10 +32,14 @@ async function multipleReturns1(flag: boolean): Promise { async overload multipleReturns{ multipleReturns1, multipleReturns2 } -function main() { +async function asyncTest() { let a: int | string = await multipleReturns(true, 42); let b: int | string = await multipleReturns(false); arktest.assertEQ(a, 42) arktest.assertEQ(b, "string2") } + +function main() { + asyncTest() +} diff --git a/ets2panda/test/runtime/ets/overload_declaration/async_method_with_same_name02.ets b/ets2panda/test/runtime/ets/overload_declaration/async_method_with_same_name02.ets index fd075cefcb..7e7ec2f8aa 100644 --- a/ets2panda/test/runtime/ets/overload_declaration/async_method_with_same_name02.ets +++ b/ets2panda/test/runtime/ets/overload_declaration/async_method_with_same_name02.ets @@ -23,9 +23,13 @@ class A { static async overload getData{ getData1, getData2 } } -function main() { - let res1: string = await A.getData() - let res2: string = await A.getData("I'm a static method2 with name 'getData'") +async function asyncFoo(): Promise { + let res1:string = await A.getData() + let res2:string = await A.getData("I'm a static method2 with name 'getData'") arktest.assertEQ(res1, "I'm a static method1 with name 'getData'") arktest.assertEQ(res2, "I'm a static method2 with name 'getData'") } + +function main(){ + asyncFoo() +} diff --git a/ets2panda/test/unit/public/ast_verifier_variable_has_scope_test.cpp b/ets2panda/test/unit/public/ast_verifier_variable_has_scope_test.cpp index 470b082849..778e7b29ab 100644 --- a/ets2panda/test/unit/public/ast_verifier_variable_has_scope_test.cpp +++ b/ets2panda/test/unit/public/ast_verifier_variable_has_scope_test.cpp @@ -95,7 +95,7 @@ TEST_F(ASTVerifierTest, AsyncLambda1) return fs[i] } - function main() { + async function asyncFoo() { fs = [ (p: int): int => p + 1, ] @@ -106,6 +106,10 @@ TEST_F(ASTVerifierTest, AsyncLambda1) let cnt = 0 cnt += (await (ps as Promise<(p: int) => int>))(0) } + + function main() { + asyncFoo() + } )"; CONTEXT(ES2PANDA_STATE_CHECKED, text) diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index d8a218abd8..f86300905f 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -93,6 +93,10 @@ syntax: id: 46 message: "await is not allowed in arrow function parameters." +- name: AWAIT_MUST_IN_ASYNC_FUNCTION + id: 78376 + message: "Using await outside of async function is forbidden." + - name: AWAIT_RESERVED_IDENTIFIER_IN_MODULE id: 213 message: "'await' is a reserved identifier in module code." -- Gitee