From 2e6fe33af30f94f91ae21d9844f9ab7e1c427c70 Mon Sep 17 00:00:00 2001 From: ElevenDuan Date: Sat, 9 Dec 2023 10:37:25 +0800 Subject: [PATCH] type inference test case change Signed-off-by: ElevenDuan --- ets2panda/checker/ETSAnalyzer.cpp | 26 +- .../expressions/arrowFunctionExpression.cpp | 5 +- ...bda_cast_infer_type_narrowing-expected.txt | 208 +++++- .../lambda_cast_infer_type_narrowing.ets | 1 + .../lambda_cast_infer_type_void-expected.txt | 130 +++- .../lambda_cast_infer_type_void.ets | 1 + ...mbda_cast_infer_type_widening-expected.txt | 208 +++++- .../lambda_cast_infer_type_widening.ets | 1 + .../lambda_cast_type_has_pramas-expected.txt | 200 +++++- .../lambda_cast_type_has_pramas.ets | 1 + .../lambda_infer_type-expected.txt | 124 +++- .../lambda_infer_type/lambda_infer_type.ets | 1 + ...a_infer_type_arrow_expression-expected.txt | 142 +++- .../lambda_infer_type_arrow_expression.ets | 1 + ...type_arrow_expression_literal-expected.txt | 132 +++- ...da_infer_type_arrow_expression_literal.ets | 1 + .../lambda_infer_type_has_return-expected.txt | 146 +++- .../lambda_infer_type_has_return.ets | 3 +- ...lambda_infer_type_retrun_enum-expected.txt | 124 +++- .../lambda_infer_type_retrun_enum.ets | 1 + ...ambda_infer_type_return_array-expected.txt | 137 +++- .../lambda_infer_type_return_array.ets | 1 + ...mbda_infer_type_return_lambda-expected.txt | 146 +++- .../lambda_infer_type_return_lambda.ets | 3 +- ...bda_infer_type_return_lambda1-expected.txt | 138 +++- .../lambda_infer_type_return_lambda1.ets | 1 + ...type_return_lambda_expression-expected.txt | 226 ++++++- ...da_infer_type_return_lambda_expression.ets | 3 +- ...bda_infer_type_return_literal-expected.txt | 124 +++- .../lambda_infer_type_return_literal.ets | 1 + ...ambda_infer_type_return_union-expected.txt | 180 ++++- .../lambda_infer_type_return_union.ets | 1 + .../lambda_infer_type_scope-expected.txt | 623 ++++++++++++++++++ .../lambda_infer_type_scope.ets | 20 + 34 files changed, 2902 insertions(+), 158 deletions(-) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_infer_type_narrowing-expected.txt (77%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_infer_type_narrowing.ets (94%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_infer_type_void-expected.txt (71%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_infer_type_void.ets (95%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt (77%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets (94%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_type_has_pramas-expected.txt (71%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_cast_type_has_pramas.ets (94%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type-expected.txt (66%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type.ets (95%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_arrow_expression-expected.txt (75%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_arrow_expression.ets (95%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal-expected.txt (74%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_arrow_expression_literal.ets (94%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_has_return-expected.txt (80%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_has_return.ets (92%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_retrun_enum-expected.txt (80%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_retrun_enum.ets (95%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_array-expected.txt (76%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_array.ets (94%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_lambda-expected.txt (76%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_lambda.ets (93%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_lambda1-expected.txt (69%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_lambda1.ets (94%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression-expected.txt (61%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_lambda_expression.ets (91%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_literal-expected.txt (69%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_literal.ets (95%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_union-expected.txt (72%) rename ets2panda/test/{parser => compiler}/ets/lambda_infer_type/lambda_infer_type_return_union.ets (94%) create mode 100644 ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope-expected.txt create mode 100644 ets2panda/test/compiler/ets/lambda_infer_type/lambda_infer_type_scope.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 4f35405def..89f0892fe1 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 249aa83775..83a1873dbe 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 5c23000dde..4006b73d23 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 3deadfbc31..d30c882985 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 1ca55a254b..66623064bb 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 cfdec9acf1..40ba385a39 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 46895a7994..545b1715cf 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 3c904151bc..cb90f223b6 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 f5d8820869..0d17b84dd6 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 54b4f3e7e1..5654723617 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 18135a31d1..1fa2395cb8 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 2b174aac2a..c3e1e23546 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 5805f98ba6..1037cfbeb4 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 f7f3f8866d..8b0adf2839 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 707d202c3f..654f361bbd 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 f25216490d..d635026902 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 b307e9a56a..13636ecffc 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 357e2c31bf..4cb018cc8d 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 001c891667..ae8e7882a3 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 b2b1bf9c55..8ed8c6e8c7 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 b4aa958eaf..a333dff5f0 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 4c471e8e9d..c2a299ba25 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 f5e21f45ae..4db8770ef4 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 52a1a7cb13..159e563745 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 487934f8aa..9aef2f59fa 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 0d36b599b4..f0cb1b26b5 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 47d0a02942..2237eae3ae 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 4c20b1a836..8bcea1baa2 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 0b1093dd09..84d4b48482 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 368e82afbf..05e3bf890c 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 bdbe6148f5..191ba526c8 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 3cd66a19d9..6196e74e32 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 0000000000..1034ff0fdf --- /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 0000000000..dcc3b38705 --- /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 +} -- Gitee