diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 95113ed59c675d244b23db736b586f42413d9e07..6e522646948b5f8f8393d0571cf9e253f2c61c5a 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 5e15bcbf7dada134279d2b9f12f5c685e0b3a4ab..def4f2d689ce6aa180d16054b16b39c7daa4f263 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 4e77ac3504eb0fe575b83ec5f4ee7de37a694224..d98c5292efca91f780f9aaa3326aa7c36f809670 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 d1988ddb9f2ac4cd5d902736652aaf88d22f56ca..afc73414c536da4c6c90b55f564fbeea447d5753 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 19b5147c4de18673c8d759894dbfbfc38afa47a0..8ba4500cc5a2a161b8c743a4dda6ed0e4d2c1249 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 9ae6ae1cfbe9ba1e3f22a745204faa0639addde7..94b2beadf8a2fd5ad8bece72ca5ffdab8e009e22 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 000e77b934f199bacb265755eb2694e3a28058ed..9ae4b2079a63e5daae5ce6da594a7762fb1a5f42 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 1a81850799003b49deca4d9d8cb1896b03660969..e4a365838e1af2e78c7c72e3d27c588af4b7f6a6 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 6efaf5c538513acaa001743b1d3cca5ae83c7d96..f946480fbd295c6b0c44c3633461cc6611f02c05 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 eb68f44567d8663e460289c84e7a21bb9d6a4a78..6ce72538e5bb25672268ac3c964e4a7af743b4ba 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 b90d64d9bf08b21113de6749c5bc702d53e6f0e0..613a23cf436a58b7739afcf4d60c0937038fdcfd 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 82ca7f094e7480cd781a36de5e86cdc8517815e9..64b9dd5e7c144e43d5678b116ce5b4185b4be52c 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 74b905de900fa5922ce76d1960eb8fdfef3630b8..11635623e66f1fcc5a516d19ba2a72ced5f7e222 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 ec2ef0638505652d957ef4fefe53924441a571e3..baa2e5238688683bbea33c674a2f783b9585cf00 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 8cd629b6defb2048ec40db3c0f24446986ec090f..c0b8408ce9970c676bd5d195aa146cd9e0bad774 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 e737ad019059bbd56053cd0746ff4adbb980fb6c..305b49ad3883b17dcea15fed2f1253907d741b07 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 a1aac4e6dcb82168a47271d9302c309043ab3236..646bf9c9d6e8620384e60bbd24b821167c78b4cf 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 db334bdb7de84883fc7a34a271fac46fcbd6b263..d50d3a1d85338f7cb7fff8c167ecc13681dfa954 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 87d4a1059a8681779d30f0f52678b2148cb01e5a..0c891bed8225fb77534ea2d46244652fa5f1bd17 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 f50ea6320030f987bf2ba8843acf6a1f174389c1..9dee0907c278fbb87ff07a1d3df7fbcff5c0a66b 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 0b99a3f81ddc515ee86cfd07fa205a1bbdf9ab9d..05ccecd717564d7c725db89ffb69f8a366d530e4 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 fd075cefcb81189d642e79a514959530769d48c4..7e7ec2f8aa135e9cd633109ce58dfdf4db764df5 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 470b08284945dd780b51241548ee7e0b5ec95f57..778e7b29ab306aa8259aba1f8a286d01da285901 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 d8a218abd8e4a3bbd9309833641ffa73829e0771..f86300905f70f93b57ff14fc888cb0dcfdd3d638 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."