diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 4f35405def8737d07d309baeb3c00308f1f749d6..89f0892fe1569e47f90feef81ac47325bb6cb6a3 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -779,31 +779,7 @@ checker::Type *ETSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const checker->AddStatus(checker::CheckerStatus::IN_LAMBDA); checker->Context().SetContainingSignature(func_type->CallSignatures()[0]); - auto *body_type = expr->Function()->Body()->Check(checker); - if (expr->Function()->Body()->IsExpression()) { - /* - when function body is ArrowFunctionExpression, need infer type for this function body - example code: - ``` - let x = () => () => {} - ``` - */ - if (expr->Function()->ReturnTypeAnnotation() == nullptr) { - if (expr->Function()->Body()->IsArrowFunctionExpression()) { - auto *arrow_func = expr->Function()->Body()->AsArrowFunctionExpression(); - auto *type_annotation = arrow_func->CreateTypeAnnotation(checker); - func_type->CallSignatures()[0]->SetReturnType(type_annotation->GetType(checker)); - } else { - func_type->CallSignatures()[0]->SetReturnType(body_type); - } - } - - checker::AssignmentContext( - checker->Relation(), expr->Function()->Body()->AsExpression(), body_type, - func_type->CallSignatures()[0]->ReturnType(), expr->Function()->Start(), - {"Return statements return type is not compatible with the containing functions return type"}, - checker::TypeRelationFlag::DIRECT_RETURN); - } + expr->Function()->Body()->Check(checker); checker->Context().SetContainingSignature(nullptr); checker->CheckCapturedVariables(); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 249aa83775ca2fd280db3a579968c7057328e502..83a1873dbef125ea7fc20754766401cc102322c1 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -133,11 +133,10 @@ ir::TypeNode *ArrowFunctionExpression::CreateTypeAnnotation(checker::ETSChecker return_node = Function()->ReturnTypeAnnotation(); } - auto *param_scope = checker->Scope()->AsFunctionScope()->ParamScope(); - auto signature = ir::FunctionSignature(nullptr, std::move(Function()->Params()), return_node); + auto orig_params = Function()->Params(); + auto signature = ir::FunctionSignature(nullptr, std::move(orig_params), return_node); auto *func_type = checker->Allocator()->New(std::move(signature), ir::ScriptFunctionFlags::NONE); - func_type->SetScope(param_scope); return_node->SetParent(func_type); return func_type; } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_narrowing-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_narrowing-expected.txt similarity index 77% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_narrowing-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_narrowing-expected.txt index 5c23000dde2ceae8d7fde089a980a768b0825d36..4006b73d23c2fc962c6168d122041cf8d1d1ee86 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_narrowing-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_narrowing-expected.txt @@ -512,7 +512,7 @@ }, "end": { "line": 23, - "column": 6 + "column": 12 } } }, @@ -523,7 +523,7 @@ }, "end": { "line": 23, - "column": 6 + "column": 12 } } }, @@ -534,7 +534,7 @@ }, "end": { "line": 23, - "column": 6 + "column": 12 } } }, @@ -572,6 +572,190 @@ "column": 39 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 24 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 21 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 39 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 40 + } + } } ], "loc": { @@ -580,7 +764,7 @@ "column": 13 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -591,7 +775,7 @@ "column": 10 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -602,7 +786,7 @@ "column": 10 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -615,7 +799,7 @@ "column": 5 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -704,11 +888,11 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 2 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -720,7 +904,7 @@ "column": 19 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -731,7 +915,7 @@ "column": 1 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -881,7 +1065,7 @@ "column": 1 }, "end": { - "line": 25, + "line": 26, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_narrowing.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_narrowing.ets similarity index 94% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_narrowing.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_narrowing.ets index 3deadfbc310ed24c5dde93267f95cf8f9992af61..d30c88298520a3a48e70f32e73b8d41a8dcd105a 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_narrowing.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_narrowing.ets @@ -20,5 +20,6 @@ class A { class B extends A { main () { let a = (a : A) => { return a} as (a : B) => B + let expected : (a : B) => B = a } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt similarity index 71% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt index 1ca55a254bbfd9f015ecc400bebfde75a6a84c53..66623064bb646deeb7db12e1adc3ededdeeb58e6 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt @@ -260,7 +260,7 @@ }, "end": { "line": 18, - "column": 2 + "column": 8 } } }, @@ -271,7 +271,7 @@ }, "end": { "line": 18, - "column": 2 + "column": 8 } } }, @@ -282,7 +282,7 @@ }, "end": { "line": 18, - "column": 2 + "column": 8 } } }, @@ -320,6 +320,120 @@ "column": 21 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 34 + } + } } ], "loc": { @@ -328,7 +442,7 @@ "column": 18 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -339,7 +453,7 @@ "column": 15 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -350,7 +464,7 @@ "column": 15 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -363,7 +477,7 @@ "column": 1 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -398,7 +512,7 @@ "column": 1 }, "end": { - "line": 19, + "line": 20, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_void.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void.ets similarity index 95% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_void.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void.ets index cfdec9acf17678d9e1d3f4608f89bff636f6fc1c..40ba385a39ecb2d1f029d4576be571f6df0de1ca 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_void.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_void.ets @@ -15,4 +15,5 @@ function main () { let x = () => {} as ()=> void + let expected : () => void = x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt similarity index 77% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt index 46895a7994e966a0169e6bdc10e746f8b932cc35..545b1715cf2905525d1f37c516f466f808038e42 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt @@ -512,7 +512,7 @@ }, "end": { "line": 23, - "column": 6 + "column": 12 } } }, @@ -523,7 +523,7 @@ }, "end": { "line": 23, - "column": 6 + "column": 12 } } }, @@ -534,7 +534,7 @@ }, "end": { "line": 23, - "column": 6 + "column": 12 } } }, @@ -572,6 +572,190 @@ "column": 39 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 29 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 24 + }, + "end": { + "line": 23, + "column": 38 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 21 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 39 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 40 + } + } } ], "loc": { @@ -580,7 +764,7 @@ "column": 13 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -591,7 +775,7 @@ "column": 10 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -602,7 +786,7 @@ "column": 10 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -615,7 +799,7 @@ "column": 5 }, "end": { - "line": 23, + "line": 24, "column": 6 } } @@ -704,11 +888,11 @@ "decorators": [], "loc": { "start": { - "line": 24, + "line": 25, "column": 2 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -720,7 +904,7 @@ "column": 19 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -731,7 +915,7 @@ "column": 1 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -881,7 +1065,7 @@ "column": 1 }, "end": { - "line": 25, + "line": 26, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets similarity index 94% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets index 3c904151bc307517f7d1af8d55a59f66dde54abf..cb90f223b65492d77d5f230dba1fa2e5a2097eaf 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets @@ -20,5 +20,6 @@ class A { class B extends A { main () { let a = (a : B) => { return a} as (a : A) => A + let expected : (a : A) => A = a } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt similarity index 71% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt index f5d88208698db187d7e9f45b434bfc2e27464dcb..0d17b84dd6da9b8564c36814a05327b557e43f34 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt @@ -428,7 +428,7 @@ }, "end": { "line": 18, - "column": 2 + "column": 8 } } }, @@ -439,7 +439,7 @@ }, "end": { "line": 18, - "column": 2 + "column": 8 } } }, @@ -450,7 +450,7 @@ }, "end": { "line": 18, - "column": 2 + "column": 8 } } }, @@ -488,6 +488,190 @@ "column": 38 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 40 + } + } } ], "loc": { @@ -496,7 +680,7 @@ "column": 18 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -507,7 +691,7 @@ "column": 15 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -518,7 +702,7 @@ "column": 15 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -531,7 +715,7 @@ "column": 1 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -566,7 +750,7 @@ "column": 1 }, "end": { - "line": 19, + "line": 20, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_type_has_pramas.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas.ets similarity index 94% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_type_has_pramas.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas.ets index 54b4f3e7e11f1fce4ebfd32a96efb28b4d778b70..5654723617c63afb50451604bd9bf5acd239181c 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_cast_type_has_pramas.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_type_has_pramas.ets @@ -15,4 +15,5 @@ function main () { let x = (a : Int) => { return 1 } as (a : Int) => Int + let expected : (a : Int) => Int = x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type-expected.txt similarity index 66% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type-expected.txt index 18135a31d1318771cb7df9285c4f649ae3258fe8..1fa2395cb8c0a1432a31b81fdcd6115be6fe23d1 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type-expected.txt @@ -252,6 +252,120 @@ "column": 21 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 34 + } + } } ], "loc": { @@ -260,7 +374,7 @@ "column": 17 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -271,7 +385,7 @@ "column": 14 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -282,7 +396,7 @@ "column": 14 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -295,7 +409,7 @@ "column": 1 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -330,7 +444,7 @@ "column": 1 }, "end": { - "line": 19, + "line": 20, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type.ets similarity index 95% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type.ets index 2b174aac2adc1adb0a2f61194067991694f422a6..c3e1e2354607a6d556914fe00b1bd99c7f06a529 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type.ets @@ -15,4 +15,5 @@ function main() { let x = () => {} + let expected : () => void = x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression-expected.txt similarity index 75% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression-expected.txt index 5805f98ba6bb070ddcba6641bae8bec7dda14e03..1037cfbeb4b47a22c97effb363054b702da265c6 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression-expected.txt @@ -155,7 +155,7 @@ }, "end": { "line": 19, - "column": 6 + "column": 12 } } }, @@ -189,7 +189,7 @@ }, "end": { "line": 19, - "column": 6 + "column": 12 } } }, @@ -200,7 +200,7 @@ }, "end": { "line": 19, - "column": 6 + "column": 12 } } }, @@ -211,7 +211,7 @@ }, "end": { "line": 19, - "column": 6 + "column": 12 } } } @@ -224,7 +224,121 @@ }, "end": { "line": 19, - "column": 6 + "column": 12 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 35 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 35 } } } @@ -235,7 +349,7 @@ "column": 14 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -246,7 +360,7 @@ "column": 11 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -257,7 +371,7 @@ "column": 11 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -270,7 +384,7 @@ "column": 5 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -359,11 +473,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 2 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -375,7 +489,7 @@ "column": 9 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -386,7 +500,7 @@ "column": 1 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -536,7 +650,7 @@ "column": 1 }, "end": { - "line": 21, + "line": 22, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression.ets similarity index 95% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression.ets index f7f3f8866d33b8364e1f156775175755526aa20e..8b0adf283912e0d4d3f114f8d0e16b76c6d00a7e 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression.ets @@ -16,5 +16,6 @@ class A { main1 () { let x = () => new A() + let expected : () => A = x } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal-expected.txt similarity index 74% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal-expected.txt index 707d202c3f17c1a42513086f8df8a7ebcf03f119..654f361bbd2f21d360154d92daed04a95e5bb794 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal-expected.txt @@ -186,6 +186,120 @@ "column": 24 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 37 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 37 + } + } } ], "loc": { @@ -194,7 +308,7 @@ "column": 14 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -205,7 +319,7 @@ "column": 11 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -216,7 +330,7 @@ "column": 11 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -229,7 +343,7 @@ "column": 5 }, "end": { - "line": 19, + "line": 20, "column": 6 } } @@ -318,11 +432,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 21, "column": 2 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -334,7 +448,7 @@ "column": 9 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -345,7 +459,7 @@ "column": 1 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -495,7 +609,7 @@ "column": 1 }, "end": { - "line": 21, + "line": 22, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal.ets similarity index 94% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal.ets index f25216490d7c354985c00e157dc6fa503af74b0f..d6350269022ffca570a8a2addd12198989fd9c6b 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal.ets @@ -16,5 +16,6 @@ class A { main1 () { let x = () => 1 + let expected : () => Int = x } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_has_return-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_has_return-expected.txt similarity index 80% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_has_return-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_has_return-expected.txt index b307e9a56ae544c67daa71437bf56791514c51be..13636ecffccfc2d8fc319a7a24c9509ee6cf3ff6 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_has_return-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_has_return-expected.txt @@ -82,11 +82,11 @@ "loc": { "start": { "line": 18, - "column": 9 + "column": 13 }, "end": { "line": 18, - "column": 10 + "column": 14 } } }, @@ -274,7 +274,7 @@ "loc": { "start": { "line": 18, - "column": 17 + "column": 21 }, "end": { "line": 21, @@ -285,7 +285,7 @@ "loc": { "start": { "line": 18, - "column": 13 + "column": 17 }, "end": { "line": 21, @@ -296,7 +296,7 @@ "loc": { "start": { "line": 18, - "column": 13 + "column": 17 }, "end": { "line": 21, @@ -307,7 +307,7 @@ "loc": { "start": { "line": 18, - "column": 9 + "column": 13 }, "end": { "line": 21, @@ -320,13 +320,127 @@ "loc": { "start": { "line": 18, - "column": 5 + "column": 9 }, "end": { "line": 21, "column": 10 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 30 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 22, + "column": 35 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 35 + } + } } ], "loc": { @@ -335,7 +449,7 @@ "column": 13 }, "end": { - "line": 22, + "line": 23, "column": 6 } } @@ -346,7 +460,7 @@ "column": 10 }, "end": { - "line": 22, + "line": 23, "column": 6 } } @@ -357,7 +471,7 @@ "column": 10 }, "end": { - "line": 22, + "line": 23, "column": 6 } } @@ -370,7 +484,7 @@ "column": 5 }, "end": { - "line": 22, + "line": 23, "column": 6 } } @@ -459,11 +573,11 @@ "decorators": [], "loc": { "start": { - "line": 23, + "line": 24, "column": 2 }, "end": { - "line": 23, + "line": 24, "column": 2 } } @@ -475,7 +589,7 @@ "column": 9 }, "end": { - "line": 23, + "line": 24, "column": 2 } } @@ -486,7 +600,7 @@ "column": 1 }, "end": { - "line": 23, + "line": 24, "column": 2 } } @@ -636,7 +750,7 @@ "column": 1 }, "end": { - "line": 24, + "line": 25, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_has_return.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_has_return.ets similarity index 92% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_has_return.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_has_return.ets index 357e2c31bf9213f59096826caa7d60d629228c3c..4cb018cc8d81d8d63357c51871df0e1192edefe3 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_has_return.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_has_return.ets @@ -15,9 +15,10 @@ class A { main () { - let x = ()=>{ + let x = ()=>{ let a : A = new A() return a } + let expected : () => A = x } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt similarity index 80% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt index 001c89166709ca0199a6987815ccd3745fe118c4..ae8e7882a3ae83b53ad296853d9f6675ff890a4c 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt @@ -526,6 +526,120 @@ "column": 6 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 20 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 34 + }, + "end": { + "line": 22, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 35 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 35 + } + } } ], "loc": { @@ -534,7 +648,7 @@ "column": 18 }, "end": { - "line": 22, + "line": 23, "column": 2 } } @@ -545,7 +659,7 @@ "column": 15 }, "end": { - "line": 22, + "line": 23, "column": 2 } } @@ -556,7 +670,7 @@ "column": 15 }, "end": { - "line": 22, + "line": 23, "column": 2 } } @@ -569,7 +683,7 @@ "column": 1 }, "end": { - "line": 22, + "line": 23, "column": 2 } } @@ -604,7 +718,7 @@ "column": 1 }, "end": { - "line": 23, + "line": 24, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_retrun_enum.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum.ets similarity index 95% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_retrun_enum.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum.ets index b2b1bf9c55ce7fbb8e8a5842171f1bc807008dd2..8ed8c6e8c7e743272353ebc53e5a1e6151609903 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_retrun_enum.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_retrun_enum.ets @@ -19,4 +19,5 @@ function main () { let y : Color = Color.Red return y } + let expected : () => Color = x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt similarity index 76% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt index b4aa958eaf6f46a7d182c517de45a97863b94c6f..a333dff5f00ce6439187d32ea22f7ab848617bc8 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt @@ -436,6 +436,133 @@ "column": 19 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 34 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 35 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 36 + } + } } ], "loc": { @@ -444,7 +571,7 @@ "column": 18 }, "end": { - "line": 19, + "line": 20, "column": 2 } } @@ -455,7 +582,7 @@ "column": 15 }, "end": { - "line": 19, + "line": 20, "column": 2 } } @@ -466,7 +593,7 @@ "column": 15 }, "end": { - "line": 19, + "line": 20, "column": 2 } } @@ -479,7 +606,7 @@ "column": 1 }, "end": { - "line": 19, + "line": 20, "column": 2 } } @@ -514,7 +641,7 @@ "column": 1 }, "end": { - "line": 20, + "line": 21, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_array.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array.ets similarity index 94% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_array.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array.ets index 4c471e8e9d26cb2ac28b6f72ee0a941d7154b4b2..c2a299ba2562d6ee296e6c57f12bfb5987586e4b 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_array.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_array.ets @@ -16,4 +16,5 @@ function main () { let y : number[] = [ 1 ,2 ,3 ] let x = () => y + let expected : () => number[] = x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda-expected.txt similarity index 76% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda-expected.txt index f5e21f45ae662950345eb05247d21bdd38cdd142..4db8770ef4c58cb0aabb76003649bec672727976 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda-expected.txt @@ -399,6 +399,134 @@ } } }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 23, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 23, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 23, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 37 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 38 + }, + "end": { + "line": 23, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 39 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 39 + } + } + }, { "type": "ReturnStatement", "argument": { @@ -407,22 +535,22 @@ "decorators": [], "loc": { "start": { - "line": 23, + "line": 24, "column": 12 }, "end": { - "line": 23, + "line": 24, "column": 13 } } }, "loc": { "start": { - "line": 23, + "line": 24, "column": 5 }, "end": { - "line": 23, + "line": 24, "column": 13 } } @@ -434,7 +562,7 @@ "column": 17 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -445,7 +573,7 @@ "column": 14 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -456,7 +584,7 @@ "column": 14 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -469,7 +597,7 @@ "column": 1 }, "end": { - "line": 24, + "line": 25, "column": 2 } } @@ -504,7 +632,7 @@ "column": 1 }, "end": { - "line": 25, + "line": 26, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda.ets similarity index 93% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda.ets index 52a1a7cb138cbec6a2af1b815220662a7e785506..159e563745aa49ab594cac473cee4ffbd606792e 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda.ets @@ -20,5 +20,6 @@ function main() { } return y } - return x + let expected : () => () => Int = x + return x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda1-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda1-expected.txt similarity index 69% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda1-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda1-expected.txt index 487934f8aa2dfa4db059c89ccf76929dfaf820ee..9aef2f59fa456abcb376b8db9e612d4823ab7fd5 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda1-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda1-expected.txt @@ -311,6 +311,134 @@ "column": 27 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 26 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 40 + } + } } ], "loc": { @@ -319,7 +447,7 @@ "column": 17 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -330,7 +458,7 @@ "column": 14 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -341,7 +469,7 @@ "column": 14 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -354,7 +482,7 @@ "column": 1 }, "end": { - "line": 18, + "line": 19, "column": 2 } } @@ -389,7 +517,7 @@ "column": 1 }, "end": { - "line": 19, + "line": 20, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda1.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda1.ets similarity index 94% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda1.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda1.ets index 0d36b599b47b3a722009da17386cb82ee12966e1..f0cb1b26b567a2ad2f588e6bc4c7c12734acc92c 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda1.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda1.ets @@ -15,4 +15,5 @@ function main() { let x = () => () => {} + let expected : () => () => void = x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt similarity index 61% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt index 47d0a0294250d1ddf3f6929bd9f433d7e3b8c63e..2237eae3ae1026548f75c9359fbb11ddc2c4cabc 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt @@ -69,7 +69,80 @@ "params": [], "body": { "type": "BlockStatement", - "statements": [], + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "expected", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "main1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 43 + } + } + } + ], "loc": { "start": { "line": 1, @@ -120,7 +193,7 @@ "type": "MethodDefinition", "key": { "type": "Identifier", - "name": "main", + "name": "main1", "decorators": [], "loc": { "start": { @@ -129,7 +202,7 @@ }, "end": { "line": 16, - "column": 14 + "column": 15 } } }, @@ -144,7 +217,7 @@ "type": "ScriptFunction", "id": { "type": "Identifier", - "name": "main", + "name": "main1", "decorators": [], "loc": { "start": { @@ -153,7 +226,7 @@ }, "end": { "line": 16, - "column": 14 + "column": 15 } } }, @@ -285,7 +358,7 @@ "loc": { "start": { "line": 16, - "column": 18 + "column": 19 }, "end": { "line": 22, @@ -296,7 +369,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 16 }, "end": { "line": 22, @@ -307,7 +380,7 @@ "loc": { "start": { "line": 16, - "column": 15 + "column": 16 }, "end": { "line": 22, @@ -327,6 +400,141 @@ "column": 2 } } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "expected", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "value": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "main1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 22 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 43 + } + } } ], "loc": { @@ -358,7 +566,7 @@ "column": 1 }, "end": { - "line": 23, + "line": 24, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression.ets similarity index 91% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression.ets index 4c20b1a836ffc6cbae374b263b4a6fb16be560a6..8bcea1baa23d63e200a8909cd3704af851a7fd74 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression.ets @@ -13,10 +13,11 @@ * limitations under the License. */ -function main () { +function main1 () { return () => { return () => { } } } +let expected : () => () => void = main1 () diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt similarity index 69% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt index 0b1093dd094ea7cc22f19390c761814bd6b09152..84d4b4848292a682b19f803ab7071a66ab5ed25e 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt @@ -280,6 +280,120 @@ "column": 6 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 33 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 33 + } + } } ], "loc": { @@ -288,7 +402,7 @@ "column": 18 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -299,7 +413,7 @@ "column": 15 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -310,7 +424,7 @@ "column": 15 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -323,7 +437,7 @@ "column": 1 }, "end": { - "line": 20, + "line": 21, "column": 2 } } @@ -358,7 +472,7 @@ "column": 1 }, "end": { - "line": 21, + "line": 22, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_literal.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal.ets similarity index 95% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_literal.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal.ets index 368e82afbf677a85cb5a92c1f021921600d477b0..05e3bf890ca1c172bb2935e14f26573053ff3f9c 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_literal.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_literal.ets @@ -17,4 +17,5 @@ function main () { let x = () => { return 1 } + let expected : () => Int = x } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt similarity index 72% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt index bdbe6148f561ee33fe07e2f9928a5fce7d1d5a71..191ba526c8b13f49e8da175acde31cee783aa65d 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt @@ -436,6 +436,176 @@ "column": 4 } } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "expected", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 38 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 15 + } + } + }, + "init": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 39 + }, + "end": { + "line": 21, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 40 + } + } } ], "loc": { @@ -444,7 +614,7 @@ "column": 18 }, "end": { - "line": 21, + "line": 22, "column": 2 } } @@ -455,7 +625,7 @@ "column": 15 }, "end": { - "line": 21, + "line": 22, "column": 2 } } @@ -466,7 +636,7 @@ "column": 15 }, "end": { - "line": 21, + "line": 22, "column": 2 } } @@ -479,7 +649,7 @@ "column": 1 }, "end": { - "line": 21, + "line": 22, "column": 2 } } @@ -514,7 +684,7 @@ "column": 1 }, "end": { - "line": 22, + "line": 23, "column": 1 } } diff --git a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_union.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union.ets similarity index 94% rename from ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_union.ets rename to ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union.ets index 3cd66a19d9b1f3fc8f94638e296768c460c2b910..6196e74e327774df0fd11bf4fdbcddf51f5600d1 100644 --- a/ets2panda/test/parser/ets/lambda_infer_type/lambda_infer_type_return_union.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_return_union.ets @@ -18,4 +18,5 @@ function main () { let y : Int | Double = 2.0 return y } + let expected : () => Int | Double = x } diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1034ff0fdf3ac0adaf2f09094330126ec92db18d --- /dev/null +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt @@ -0,0 +1,623 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 6 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 6 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "value": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": true, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 19 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "right": { + "type": "Identifier", + "name": "p", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "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": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "AssertStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 42, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 16 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 43, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope.ets new file mode 100644 index 0000000000000000000000000000000000000000..dcc3b38705e5211d04d2f48e9edd9dc3a030ab51 --- /dev/null +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let b = 1; +let f = (p: double) => b + p; +function main () { + assert f(42) == 43 +}