diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index f91ee6ca74baf1c27f552ac3a85e504a908deba4..aac274175865e83f79f2a1ccd55144748e2cf420 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -345,11 +345,12 @@ checker::Type *ETSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const 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); + auto *const return_type = func_type->CallSignatures()[0]->ReturnType(); + checker::AssignmentContext(checker->Relation(), expr->Function()->Body()->AsExpression(), body_type, + return_type, expr->Function()->Start(), + {"Return statement's return type '", body_type, + "' is not compatible with the arrow function's return type '", return_type, "'."}, + checker::TypeRelationFlag::DIRECT_RETURN); } checker->Context().SetContainingSignature(nullptr); @@ -716,10 +717,11 @@ void CheckReturnType(ETSChecker *checker, checker::Type *func_return_type, check st_argument->Start()); } } else { - checker::AssignmentContext(checker->Relation(), st_argument, argument_type, func_return_type, - st_argument->Start(), - {"Return statement type is not compatible with the enclosing method's return type."}, - checker::TypeRelationFlag::DIRECT_RETURN); + checker::AssignmentContext( + checker->Relation(), st_argument, argument_type, func_return_type, st_argument->Start(), + {"Return statement's type '", argument_type, + "' is not compatible with the enclosing method's return type '", func_return_type, "'."}, + checker::TypeRelationFlag::DIRECT_RETURN); } } @@ -827,8 +829,9 @@ void ProcessReturnStatements(ETSChecker *checker, ir::ScriptFunction *containing containing_func->Signature()->AddSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE); } else if (!relation->IsAssignableTo(argument_type, func_return_type)) { checker->ThrowTypeError( - "Return statement type is not compatible with previous method's return statement " - "type(s).", + {"Return statement's type '", argument_type, + "' is not compatible with the enclosing method's previous return statement type(s) '", + func_return_type, "'."}, st_argument->Start()); } } else { diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 7e6538ad779804810f7a49a78c87889141bdb4fe..83c28c9a0cb6007ac9657a69ae320956478e1e5b 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -126,8 +126,10 @@ void ETSChecker::EnhanceSubstitutionForType(const ArenaVector &type_para // NOLINTBEGIN(modernize-avoid-c-arrays) static constexpr char const INVALID_CALL_ARGUMENT_1[] = "Call argument at index "; -static constexpr char const INVALID_CALL_ARGUMENT_2[] = " is not compatible with the signature's type at that index."; -static constexpr char const INVALID_CALL_ARGUMENT_3[] = " is not compatible with the signature's rest parameter type."; +static constexpr char const INVALID_CALL_ARGUMENT_2[] = " with type '"; +static constexpr char const INVALID_CALL_ARGUMENT_3[] = "' is not compatible with the signature's type '"; +static constexpr char const INVALID_CALL_ARGUMENT_4[] = " is not compatible with the signature's rest parameter type '"; +static constexpr char const INVALID_CALL_ARGUMENT_5[] = "' at that index"; // NOLINTEND(modernize-avoid-c-arrays) Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *type_arguments, @@ -202,7 +204,9 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP if (auto const invocation_ctx = checker::InvocationContext( Relation(), argument, argument_type, substituted_sig->Params()[index]->TsType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_2}, flags); + {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_2, argument_type, INVALID_CALL_ARGUMENT_3, + substituted_sig->Params()[index]->TsType(), INVALID_CALL_ARGUMENT_5}, + flags); !invocation_ctx.IsInvocable()) { return nullptr; } @@ -238,7 +242,10 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP if (auto const invocation_ctx = checker::InvocationContext( Relation(), argument, argument_type, substituted_sig->RestVar()->TsType()->AsETSArrayType()->ElementType(), argument->Start(), - {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_3}, flags); + {INVALID_CALL_ARGUMENT_1, index, INVALID_CALL_ARGUMENT_2, argument_type, + INVALID_CALL_ARGUMENT_4, substituted_sig->RestVar()->TsType()->AsETSArrayType()->ElementType(), + INVALID_CALL_ARGUMENT_5}, + flags); !invocation_ctx.IsInvocable()) { return nullptr; } diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index b1f99ba5be31df8752d5e681279a7fc6a67bfa98..65c984c005ba7000a5715ec7d39822290a056ddc 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -903,7 +903,8 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T if (annotation_type != nullptr) { AssignmentContext(Relation(), init, init_type, annotation_type, init->Start(), - {"Initializers type is not assignable to the target type"}); + {"Type '", init_type, "' is not assignable to type '", annotation_type, "'."}); + if (is_const && init_type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && annotation_type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { binding_var->SetTsType(init->TsType()); @@ -2178,9 +2179,12 @@ bool ETSChecker::TypeInference(Signature *signature, const ArenaVectorAsETSFunctionType()); Type *const arg_type = arrow_func_expr->Check(this); - checker::InvocationContext invokation_ctx( - Relation(), arguments[index], arg_type, signature->Params()[index]->TsType(), arrow_func_expr->Start(), - {"Call argument at index ", index, " is not compatible with the signature's type at that index"}, flags); + checker::InvocationContext invokation_ctx(Relation(), arguments[index], arg_type, + signature->Params()[index]->TsType(), arrow_func_expr->Start(), + {"Call argument at index ", index, " with type '", arg_type, + "' is not compatible with the signature's type '", + signature->Params()[index]->TsType(), "' at that index"}, + flags); invocable &= invokation_ctx.IsInvocable(); } diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index ee23d08854063b5e52316957947e01388f42bee9..49b6b286b4d11ffb2b9b90fb88e6faf02e7afa0f 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -28,10 +28,11 @@ void AssignmentContext::ValidateArrayTypeInitializerByElement(TypeRelation *rela { for (uint32_t index = 0; index < node->Elements().size(); index++) { ir::Expression *current_array_elem = node->Elements()[index]; - AssignmentContext(relation, current_array_elem, - current_array_elem->Check(relation->GetChecker()->AsETSChecker()), target->ElementType(), + auto *const current_array_element_type = current_array_elem->Check(relation->GetChecker()->AsETSChecker()); + AssignmentContext(relation, current_array_elem, current_array_element_type, target->ElementType(), current_array_elem->Start(), - {"Array element at index ", index, " is not compatible with the target array element type."}); + {"Array element at index ", index, " with type '", current_array_element_type, + "' is not compatible with the target array element type '", target->ElementType(), "'."}); } } diff --git a/ets2panda/checker/types/ets/etsArrayType.cpp b/ets2panda/checker/types/ets/etsArrayType.cpp index 5c2bdbac39322b6294c27f5508b67211f922c134..0413b69808352ceb7caf8c23b142042772e1cc27 100644 --- a/ets2panda/checker/types/ets/etsArrayType.cpp +++ b/ets2panda/checker/types/ets/etsArrayType.cpp @@ -25,6 +25,11 @@ void ETSArrayType::ToString(std::stringstream &ss) const { element_->ToString(ss); ss << "[]"; + + if (IsNullish()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); + } } void ETSArrayType::ToAssemblerType(std::stringstream &ss) const diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 7d060c93c57c08edf186bd7416ed5a972c78443b..1b2ba7988fbdfa2132b121fe31fcc0290dc6ec46 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -284,26 +284,41 @@ std::unordered_map ETSObject void ETSObjectType::ToString(std::stringstream &ss) const { - ss << name_; + if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && + !name_.Empty()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); + } + GetFunctionalInterfaceInvokeType()->ToString(ss); + } else { + ss << name_; + } if (IsGeneric()) { - auto const type_arguments_size = type_arguments_.size(); ss << compiler::Signatures::GENERIC_BEGIN; - type_arguments_[0]->ToString(ss); - for (std::size_t i = 1U; i < type_arguments_size; ++i) { - ss << ','; - type_arguments_[i]->ToString(ss); + + for (auto arg = type_arguments_.cbegin(); arg != type_arguments_.cend(); ++arg) { + (*arg)->ToString(ss); + + if (next(arg) != type_arguments_.cend()) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_COMMA); + } } ss << compiler::Signatures::GENERIC_END; } if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && !name_.Empty()) { + if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); + } if (ContainsNull()) { - ss << "|null"; + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); } if (ContainsUndefined()) { - ss << "|undefined"; + ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) + << lexer::TokenToString(lexer::TokenType::KEYW_UNDEFINED); } } } diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index a083979f86ffc07384e9df0e89b9a2a70409e337..cb9fa1e52df6c160181a380a295a90f91dd45afe 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -389,7 +389,7 @@ public: return (flags_ & flag) != 0; } - ETSFunctionType *GetFunctionalInterfaceInvokeType() + ETSFunctionType *GetFunctionalInterfaceInvokeType() const { ASSERT(HasObjectFlag(ETSObjectFlags::FUNCTIONAL)); auto *invoke = GetOwnProperty("invoke"); diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index a6ba7d6ee0528ee4b948d9be668fe3a275f21027..7f048d0a70b9b68cda1901ff3be40d0d48169c2a 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -300,7 +300,7 @@ checker::Type *AssignmentExpression::Check([[maybe_unused]] checker::ETSChecker } checker::AssignmentContext(checker->Relation(), relation_node, source_type, left_type, right_->Start(), - {"Initializers type is not assignable to the target type"}); + {"Type '", source_type, "' is not assignable to type '", left_type, "'."}); SetTsType(left_->TsType()); return TsType(); diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index f3b4b4ebff09da14eb37d8fd2e2cedca2209ae1e..cab36da7069e0e9cc9afa2194dcc0850368a9bef 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -790,7 +790,9 @@ checker::Type *ObjectExpression::Check(checker::ETSChecker *checker) checker->ThrowTypeError({"need to specify target type for class composite"}, Start()); } if (!PreferredType()->IsETSObjectType()) { - checker->ThrowTypeError({"target type for class composite needs to be an object type"}, Start()); + checker->ThrowTypeError({"Target type for class composite needs to be an object type. Found target type is '", + PreferredType(), "'."}, + Start()); } if (PreferredType()->IsETSDynamicType()) { @@ -808,8 +810,7 @@ checker::Type *ObjectExpression::Check(checker::ETSChecker *checker) checker::ETSObjectType *obj_type = PreferredType()->AsETSObjectType(); if (obj_type->HasObjectFlag(checker::ETSObjectFlags::ABSTRACT | checker::ETSObjectFlags::INTERFACE)) { - checker->ThrowTypeError({"target type for class composite ", obj_type->Name(), " is not instantiable"}, - Start()); + checker->ThrowTypeError({"target type for class composite ", obj_type, " is not instantiable"}, Start()); } bool have_empty_constructor = false; @@ -821,7 +822,7 @@ checker::Type *ObjectExpression::Check(checker::ETSChecker *checker) } } if (!have_empty_constructor) { - checker->ThrowTypeError({"type ", obj_type->Name(), " has no parameterless constructor"}, Start()); + checker->ThrowTypeError({"type ", obj_type, " has no parameterless constructor"}, Start()); } for (Expression *prop_expr : Properties()) { @@ -841,7 +842,7 @@ checker::Type *ObjectExpression::Check(checker::ETSChecker *checker) varbinder::LocalVariable *lv = obj_type->GetProperty( pname, checker::PropertySearchFlags::SEARCH_INSTANCE_FIELD | checker::PropertySearchFlags::SEARCH_IN_BASE); if (lv == nullptr) { - checker->ThrowTypeError({"type ", obj_type->Name(), " has no property named ", pname}, prop_expr->Start()); + checker->ThrowTypeError({"type ", obj_type, " has no property named ", pname}, prop_expr->Start()); } checker->ValidatePropertyAccess(lv, obj_type, prop_expr->Start()); if (lv->HasFlag(varbinder::VariableFlags::READONLY)) { @@ -855,8 +856,9 @@ checker::Type *ObjectExpression::Check(checker::ETSChecker *checker) value->AsObjectExpression()->SetPreferredType(prop_type); } value->SetTsType(value->Check(checker)); - checker::AssignmentContext(checker->Relation(), value, value->TsType(), prop_type, value->Start(), - {"value type is not assignable to the property type"}); + checker::AssignmentContext( + checker->Relation(), value, value->TsType(), prop_type, value->Start(), + {"Value's type '", value->TsType(), "' is not assignable to the property's type '", prop_type, "'."}); } SetTsType(obj_type); diff --git a/ets2panda/test/compiler/ets/FunctionType1-expected.txt b/ets2panda/test/compiler/ets/FunctionType1-expected.txt index 8a077af2aa1c71fa7e8cbec4bf39c1a4edcfc0f6..80fd6bb4b645c17560687bd316e2055de941b5ad 100644 --- a/ets2panda/test/compiler/ets/FunctionType1-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType1-expected.txt @@ -1001,4 +1001,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [FunctionType1.ets:24:12] +TypeError: Type '(a: int, b: int) => int' is not assignable to type '(a: int, b: int) => void'. [FunctionType1.ets:24:12] diff --git a/ets2panda/test/compiler/ets/FunctionType3-expected.txt b/ets2panda/test/compiler/ets/FunctionType3-expected.txt index ca35e1e27ca278512efc531856f662671c7d2acc..81eb2f3927e7c945ab497ec7dabdf48ddf5ca54c 100644 --- a/ets2panda/test/compiler/ets/FunctionType3-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType3-expected.txt @@ -809,4 +809,4 @@ } } } -TypeError: Call argument at index 1 is not compatible with the signature's type at that index. [FunctionType3.ets:23:16] +TypeError: Call argument at index 1 with type 'string' is not compatible with the signature's type 'int' at that index [FunctionType3.ets:23:16] diff --git a/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt index b96e1faf4dde097c1ef641d56283fd4c9e94cee5..28c9cd8746da8c1321b4715c629b566a6818e2f8 100644 --- a/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Double-to-Int_typeerror-expected.txt @@ -456,4 +456,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [conversion_Double-to-Int_typeerror.ets:17:17] +TypeError: Type 'Double' is not assignable to type 'Int'. [conversion_Double-to-Int_typeerror.ets:17:17] diff --git a/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt index 96c8b5fd3ce0843ef07e0e138bf3a338319926e7..f699a2c68ba161d255d7ef08589f6188871ca573 100644 --- a/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Double-to-Int_w_try_stmt_typerror-expected.txt @@ -718,4 +718,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [conversion_Double-to-Int_w_try_stmt_typerror.ets:17:18] +TypeError: Return statement's type 'Double' is not compatible with the enclosing method's return type 'Int'. [conversion_Double-to-Int_w_try_stmt_typerror.ets:17:18] diff --git a/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt index 18cfe0261dac23bdba4b96cf0cac7a060b2145d1..c64879fae0a901716b27e4f865b2d5d9623f119c 100644 --- a/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_Int-to-Double_typeerror-expected.txt @@ -456,4 +456,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [conversion_Int-to-Double_typeerror.ets:17:20] +TypeError: Type 'Int' is not assignable to type 'Double'. [conversion_Int-to-Double_typeerror.ets:17:20] diff --git a/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt b/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt index a4f0dff3f57cdd21a0e10bf2715d626c87ed8449..aeb8bbf21e21e4be6bbd038a7995176ddf5a42b0 100644 --- a/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt +++ b/ets2panda/test/compiler/ets/conversion_call-context_Int-to-Double_typeerror-expected.txt @@ -679,4 +679,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [conversion_call-context_Int-to-Double_typeerror.ets:20:7] +TypeError: Call argument at index 0 with type 'Int' is not compatible with the signature's type 'Double' at that index [conversion_call-context_Int-to-Double_typeerror.ets:20:7] diff --git a/ets2panda/test/compiler/ets/dynamicLambda_error-expected.txt b/ets2panda/test/compiler/ets/dynamicLambda_error-expected.txt index f52f74f5dac1dc9afbcab68c5e99ee060e1e0f49..7fcbe66856b5a03b5a96eb7a1dbdf7395aed963d 100644 --- a/ets2panda/test/compiler/ets/dynamicLambda_error-expected.txt +++ b/ets2panda/test/compiler/ets/dynamicLambda_error-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamicLambda_error.ets:25:39] +TypeError: Type 'JSValue' is not assignable to type '(x: int, y: int) => int'. [dynamicLambda_error.ets:25:39] diff --git a/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0758e8350a811a256873ed10e03eac8bf591179c --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt @@ -0,0 +1,584 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": [], + "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": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "test", + "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": "test", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Return statement's type 'A|null' is not compatible with the enclosing method's return type 'int'. [etsObjectToString0.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString0.ets b/ets2panda/test/compiler/ets/etsObjectToString0.ets new file mode 100644 index 0000000000000000000000000000000000000000..08e1c3e195343f712c2e1d7fd069378668778353 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString0.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +class A{} + +function test(): int{ + let a: A|null + return a +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2be087c277ad5d5a390b6e6b5ce6ae7d102f74fe --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt @@ -0,0 +1,640 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": [], + "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": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "test0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test0", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Return statement's type 'A|null' is not compatible with the enclosing method's return type 'A'. [etsObjectToString1.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString1.ets b/ets2panda/test/compiler/ets/etsObjectToString1.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b9bd875a92f4a3cb67627677c638dcc88c69517 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString1.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +class A{} + +function test0(): A{ + let a: A|null + return a +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..15acf6c89bcc10ff6bda78acb02a820bbb131db9 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt @@ -0,0 +1,668 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": [], + "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": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "test1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "test1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 33 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "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": 22, + "column": 1 + } + } +} +TypeError: Return statement's type 'A|null' is not compatible with the enclosing method's return type 'A|null'. [etsObjectToString2.ets:20:12] diff --git a/ets2panda/test/compiler/ets/etsObjectToString2.ets b/ets2panda/test/compiler/ets/etsObjectToString2.ets new file mode 100644 index 0000000000000000000000000000000000000000..e82acf91fa6c234a42870b685b50fb2214ce333f --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString2.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +class A{} + +function test1(): A|null{ + let a: A|null + return a +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..939731867479ecf7f6219228c910e25fff7f2ea2 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString3-expected.txt @@ -0,0 +1,890 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": [], + "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": "z", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 20, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 20, + "column": 11 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 20, + "column": 11 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "definite": false, + "decorators": [], + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} +TypeError: Type '() => A' is not assignable to type 'A'. [etsObjectToString3.ets:18:17] diff --git a/ets2panda/test/compiler/ets/etsObjectToString3.ets b/ets2panda/test/compiler/ets/etsObjectToString3.ets new file mode 100644 index 0000000000000000000000000000000000000000..9007b79acc4d4e1c57badddf6397ddde29ebbe1b --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString3.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +class A{} + +let z: A = (): A => { + let b : A = new A() + return b +} diff --git a/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..121bd1a53ca38c4cb2d612088a6dddbaa710f36e --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt @@ -0,0 +1,468 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": "f", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "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 + } + } + }, + "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": "f", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "definite": false, + "decorators": [], + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} +TypeError: Type 'int' is not assignable to type '(() => int)|null'. [etsObjectToString4.ets:18:29] diff --git a/ets2panda/test/compiler/ets/etsObjectToString4.ets b/ets2panda/test/compiler/ets/etsObjectToString4.ets new file mode 100644 index 0000000000000000000000000000000000000000..fd7a335c13a74ae0422dcb535c87721716c23be0 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString4.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +class A{} + +let f: (() => int) | null = 5 diff --git a/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c37a9feeabb407e87e2e39e1218be0d9b8cc8c8 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt @@ -0,0 +1,848 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + { + "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": [], + "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": "g", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "value": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 46 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 54 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 46 + }, + "end": { + "line": 18, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 55 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 58 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 66 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 66 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 58 + }, + "end": { + "line": 18, + "column": 66 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 67 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "y", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 75 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "definite": false, + "decorators": [], + "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 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Type '(y: A) => A|null' is not assignable to type '((y: A) => A|null)|null'. [etsObjectToString5.ets:18:42] diff --git a/ets2panda/test/compiler/ets/etsObjectToString5.ets b/ets2panda/test/compiler/ets/etsObjectToString5.ets new file mode 100644 index 0000000000000000000000000000000000000000..cacf921a8cfc77a8818e8abfbf65a6df669a8ed8 --- /dev/null +++ b/ets2panda/test/compiler/ets/etsObjectToString5.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. + */ + +class A{} + +let g:((y:A) => A|null)|null = (y:A): A|null => { + return y +} diff --git a/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt b/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt index d7f2b19147955e8a0c1b259fd76212c23baaec59..d8e1952590b1abe3b22aa4da133c9a943067b0ef 100644 --- a/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt +++ b/ets2panda/test/compiler/ets/generic_function_call_2-expected.txt @@ -982,4 +982,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [generic_function_call_2.ets:24:9] +TypeError: Call argument at index 0 with type 'B' is not compatible with the signature's type 'A' at that index [generic_function_call_2.ets:24:9] diff --git a/ets2panda/test/compiler/ets/identifierReference10-expected.txt b/ets2panda/test/compiler/ets/identifierReference10-expected.txt index 3eb9089b8257dc353155625959fde77cc80781f5..4cc73f5397b33a7a01972a49ad8e3dd41f0cbef1 100644 --- a/ets2panda/test/compiler/ets/identifierReference10-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference10-expected.txt @@ -870,4 +870,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference10.ets:24:16] +TypeError: Type 'string' is not assignable to type 'int'. [identifierReference10.ets:24:16] diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index 07248d61cc74133a3e39b310f113ced2d96a5c2d..656f8d63216669c91045ed8f4c4a696be583b77a 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -398,4 +398,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference2.ets:16:34] +TypeError: Type '(v: double, u: double) => double' is not assignable to type '(a: int, b: int) => void'. [identifierReference2.ets:16:34] diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index 6495cedbd507534806dc7aa04c65d78638513a60..f520e35fcf1032ab95db0e78e3a53d19b544a6c1 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -586,4 +586,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [identifierReference3.ets:20:9] +TypeError: Type 'string' is not assignable to type 'int'. [identifierReference3.ets:20:9] diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index aca5d358ee60330e2d0ffb7355d4224539765564..680802defddf25f4e27ceb2e386fca89e69fceb5 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -429,4 +429,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [inferTypeOfArrayNegative3.ets:17:8] +TypeError: Type 'string' is not assignable to type 'double'. [inferTypeOfArrayNegative3.ets:17:8] diff --git a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt index 1a6d15476768b54e8e3d1f7ab39781b98ea452bd..503e841840b95a2457f48caa99d86fd409f10b58 100644 --- a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt @@ -487,4 +487,4 @@ } } } -TypeError: Return statements return type is not compatible with the containing functions return type [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] +TypeError: Return statement's return type 'int' is not compatible with the arrow function's return type 'void'. [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] diff --git a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt index 7ea24132d85f3d62d07b9008fd4661f1826b0059..e5a4114b1d3da46d6c52c30680647f47af7c8343 100644 --- a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentTypeInfunction-expected.txt @@ -638,4 +638,4 @@ } } } -TypeError: Return statements return type is not compatible with the containing functions return type [lambdaExpressionWithoutBlockStatementDifferentTypeInfunction.ets:21:28] +TypeError: Return statement's return type 'String' is not compatible with the arrow function's return type 'int'. [lambdaExpressionWithoutBlockStatementDifferentTypeInfunction.ets:21:28] diff --git a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt index 4fbb638c04df7d6451ec90527c05dca886a76e23..45e0fa120d2184e37bc1ff04d96b5d40a271f124 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt @@ -642,4 +642,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [lambdaFunction3.ets:18:39] +TypeError: Type '(b: int) => void' is not assignable to type '(b: String) => void'. [lambdaFunction3.ets:18:39] diff --git a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt index 2cae57f050c12f9206ee759d2fff9109c6cac46a..7c80bf8ff951859caf0d9d1453a1ea92737a7f44 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt @@ -1705,4 +1705,4 @@ } } } -TypeError: Call argument at index 1 is not compatible with the signature's type at that index. [lambdaFunction5.ets:35:17] +TypeError: Call argument at index 1 with type 'string' is not compatible with the signature's type 'int' at that index [lambdaFunction5.ets:35:17] diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index 67be00033869b6b07c182be1b7272d5bdf81ce6e..37a3c7b89e13148ea1001948ff5a86f85d986749 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -257,4 +257,4 @@ } } } -TypeError: target type for class composite needs to be an object type [objectLiteralPrimitiveContextType.ets:16:14] +TypeError: Target type for class composite needs to be an object type. Found target type is 'int'. [objectLiteralPrimitiveContextType.ets:16:14] diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index cba33cf83f95878978207ba234016f9e56128c85..e61cbb9d03a44a57a7f43db856ee4c4e4211289e 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -518,4 +518,4 @@ } } } -TypeError: value type is not assignable to the property type [objectLiteralWrongValueType.ets:21:8] +TypeError: Value's type 'string' is not assignable to the property's type 'int'. [objectLiteralWrongValueType.ets:21:8] diff --git a/ets2panda/test/compiler/ets/union_types_4-expected.txt b/ets2panda/test/compiler/ets/union_types_4-expected.txt index f69abcff990d30f21f336bdbc510840c89d79cb4..d4232d1a2e9e42a3954f92cae859a3b55ae5e843 100644 --- a/ets2panda/test/compiler/ets/union_types_4-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_4-expected.txt @@ -1555,4 +1555,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [union_types_4.ets:30:9] +TypeError: Type 'B' is not assignable to type 'String | Short | A'. [union_types_4.ets:30:9] diff --git a/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt b/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt index f10a8253c6cf59df9b10891b6ea0675f9b1beb3e..f9f17f4c8ebe1b72fe073f88dfddffe937363250 100644 --- a/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt +++ b/ets2panda/test/parser/ets/async_func_return_type_bad-expected.txt @@ -342,4 +342,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [async_func_return_type_bad.ets:17:12] +TypeError: Return statement's type 'string' is not compatible with the enclosing method's return type 'Promise | Int'. [async_func_return_type_bad.ets:17:12] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt index fa2438b241b8161ab751fc2f22b9365c218d35a0..f1737d83d74a4b5e0e2ed54dba0aff2ef95587f0 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_ctor_decl_import_bad-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_class_ctor_decl_import_bad.ets:23:19] +TypeError: Call argument at index 0 with type 'string' is not compatible with the signature's type 'double' at that index [dynamic_class_ctor_decl_import_bad.ets:23:19] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt index 1a691d4d82cc9507b503a568bcb3ca76c361c5d4..5bd8c55bdcb9aa1b4ba380ccb27c24ad2aa82944 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_1-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_field_decl_import_bad_1.ets:23:12] +TypeError: Type 'int' is not assignable to type 'String'. [dynamic_class_field_decl_import_bad_1.ets:23:12] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt index 88718c571e3511fb93e4dc18c5864a3c4bc19e6c..b135db0049d55325f6db31d3f2ec74e0fdab9ab5 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_field_decl_import_bad_2-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_field_decl_import_bad_2.ets:23:21] +TypeError: Type 'double' is not assignable to type 'String'. [dynamic_class_field_decl_import_bad_2.ets:23:21] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt index 6eac80975caa1f8e56848f3aae0b121ba1549b4b..1c569acd207caf3c5ec5efd5a5b91e47296178e9 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_1-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_class_method_decl_import_bad_1.ets:23:11] +TypeError: Call argument at index 0 with type 'string' is not compatible with the signature's type 'double' at that index [dynamic_class_method_decl_import_bad_1.ets:23:11] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt index 9b52cc0ef3dbec6abfa2ef8c25abf2d751e2653e..9f5dcf3dabf54fbf89a3bcea37fc7fe685522866 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_class_method_decl_import_bad_2-expected.txt @@ -1 +1 @@ -TypeError: Initializers type is not assignable to the target type [dynamic_class_method_decl_import_bad_2.ets:23:21] +TypeError: Type 'double' is not assignable to type 'String'. [dynamic_class_method_decl_import_bad_2.ets:23:21] diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt index 3e84372b587dbd2db92a06f0a9a75f433b38d302..03c3e6774e0c488550e6d86b660a0374c1e90107 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/dynamic_func_decl_import_bad-expected.txt @@ -1 +1 @@ -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [dynamic_func_decl_import_bad.ets:23:9] +TypeError: Call argument at index 0 with type 'string' is not compatible with the signature's type 'A' at that index [dynamic_func_decl_import_bad.ets:23:9] diff --git a/ets2panda/test/parser/ets/enum8-expected.txt b/ets2panda/test/parser/ets/enum8-expected.txt index 67d246372e6536e86ad1277fc43383ee3afbf174..f22e386e9ad310961a30b381ede1eab195360a3f 100644 --- a/ets2panda/test/parser/ets/enum8-expected.txt +++ b/ets2panda/test/parser/ets/enum8-expected.txt @@ -563,4 +563,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [enum8.ets:20:20] +TypeError: Type 'Color2' is not assignable to type 'Color'. [enum8.ets:20:20] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt index e765b5e9e3e22a4c40d8e7145ad6bfd46973fb87..659bc5b99da65d6852e7e6f2e5b2dfd224e686fa 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt @@ -316,4 +316,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type2.ets:17:27] +TypeError: Type '() => void' is not assignable to type '(i: int) => int'. [function_implicit_return_type2.ets:17:27] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index 86c0bf3a67b14a00dad67ec7b52878c2d2541808..4a615f2ab6bd0cbb8a1e37abf5e2a42e95d79956 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -465,4 +465,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type3.ets:18:27] +TypeError: Type '(i: int) => void' is not assignable to type '(i: int) => int'. [function_implicit_return_type3.ets:18:27] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt index c942bc192dc2488e78bc4a373c507b264e0f0472..228514b4f278ac4eb669a94b74bf6a7ba59b67ef 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type6-expected.txt @@ -442,4 +442,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [function_implicit_return_type6.ets:20:16] +TypeError: Type 'void' is not assignable to type 'int'. [function_implicit_return_type6.ets:20:16] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt index 478d07c0ed0e85d640bad5451cad799687ee00d6..093d005aa15591274cff29d5c427f713258d49aa 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type7-expected.txt @@ -598,4 +598,4 @@ } } } -TypeError: Return statement type is not compatible with previous method's return statement type(s). [function_implicit_return_type7.ets:21:10] +TypeError: Return statement's type 'int' is not compatible with the enclosing method's previous return statement type(s) 'boolean'. [function_implicit_return_type7.ets:21:10] diff --git a/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt index d90b7f2cbad3f73a06054c2a7ad8ce30a6cdac3d..982a4d6c2242229aeb03b94e62ef3001de39723c 100644 --- a/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/n_arrayHoldingNullValue-expected.txt @@ -455,4 +455,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_arrayHoldingNullValue.ets:17:24] +TypeError: Type 'null' is not assignable to type 'float[]'. [n_arrayHoldingNullValue.ets:17:24] diff --git a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt index cf852cc4c9f8e79ebaff9db05a99a2370c323fb4..7e7ac30e3cb27859d3ca3c8cceb667d19d0da842 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt @@ -743,4 +743,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableFromFunctionToNonNullable.ets:23:22] +TypeError: Type 'A|null' is not assignable to type 'Object'. [n_assignNullableFromFunctionToNonNullable.ets:23:22] diff --git a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt index 2f57863379270d883e3c51ef185d743e23ee990e..50ba9c77601720ba00874b03d383603c25b1a345 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt @@ -913,4 +913,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableFromMethodToNullableParam.ets:24:22] +TypeError: Type 'A|null' is not assignable to type 'Object'. [n_assignNullableFromMethodToNullableParam.ets:24:22] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt index c8a3c89c3654e9524ca71a4129652428bfaec1ea..1624144742677334a60b031b4ab1b8519cf52ca9 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt @@ -707,4 +707,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullable.ets:22:9] +TypeError: Type 'A|null' is not assignable to type 'Object'. [n_assignNullableToNonNullable.ets:22:9] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt index 9b424caf23208fbe35f822459afa89f11846f049..37eba65c79eeb5552722febe7fda2d4356cc81be 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt @@ -803,4 +803,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullableArray.ets:22:10] +TypeError: Type 'A[]|null' is not assignable to type 'Object[]'. [n_assignNullableToNonNullableArray.ets:22:10] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt index 2ac81c66dd171fa491b4225ef1256f366c00ad42..23e5705055e6997d571bb57ece2207ad2d136dd7 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt @@ -776,4 +776,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [n_assignNullableToNonNullableTypeAlias.ets:24:9] +TypeError: Type 'A|null' is not assignable to type 'Object'. [n_assignNullableToNonNullableTypeAlias.ets:24:9] diff --git a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt index 5dffc7d900e674573395ae100ff05468f16059b6..8d7674b5ed152dbd71e73b19b5ea7da484ea2baf 100644 --- a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt @@ -828,4 +828,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callFunctionWithNullableParam.ets:23:9] +TypeError: Call argument at index 0 with type 'A|null' is not compatible with the signature's type 'A' at that index [n_callFunctionWithNullableParam.ets:23:9] diff --git a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt index 1aed437dc327df8abf08b3f8e11dca184dfc7825..2ffceddcd9f89299e2ca6f69c86799081b4a55cf 100644 --- a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt @@ -1149,4 +1149,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callInterfaceMethodWithNullableParam.ets:27:12] +TypeError: Call argument at index 0 with type 'I|null' is not compatible with the signature's type 'I' at that index [n_callInterfaceMethodWithNullableParam.ets:27:12] diff --git a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt index 66b6147871606ec2d4d837e67c5ab72fea6a0ba4..9bee3762009c7c6468805949495ab1653e161d7d 100644 --- a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt @@ -858,4 +858,4 @@ } } } -TypeError: Call argument at index 0 is not compatible with the signature's type at that index. [n_callMethodWithNullableParam.ets:23:12] +TypeError: Call argument at index 0 with type 'A|null' is not compatible with the signature's type 'A' at that index [n_callMethodWithNullableParam.ets:23:12] diff --git a/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt index 8d0cbdb7442d3b1d150397e933ecc5b5862d16ba..2f97a5bd3a2cd18a25125ee45909c24377898a82 100644 --- a/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullFromFunction-expected.txt @@ -451,4 +451,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullFromFunction.ets:19:12] +TypeError: Return statement's type 'null' is not compatible with the enclosing method's return type 'A'. [n_returnNullFromFunction.ets:19:12] diff --git a/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt index 6475dcf314bd6a18108d43742faddb1e2d281656..7f8e30a17555e8c454a3b4f514a087cbb6728a97 100644 --- a/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullFromMethod-expected.txt @@ -451,4 +451,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullFromMethod.ets:18:16] +TypeError: Return statement's type 'null' is not compatible with the enclosing method's return type 'A'. [n_returnNullFromMethod.ets:18:16] diff --git a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt index 7a4275b3329c44d21b6eac4df4ed0bd6933af59d..265c9065ba37b5b217adb23efefe7a5a2c8e2179 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt @@ -592,4 +592,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullableFromFunction.ets:21:12] +TypeError: Return statement's type 'A|null' is not compatible with the enclosing method's return type 'A'. [n_returnNullableFromFunction.ets:21:12] diff --git a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt index df711d1502c49da6a4a6a678fca403d1719b8860..3555c372db00699785d33a2f20b1e56ad8e700e6 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt @@ -592,4 +592,4 @@ } } } -TypeError: Return statement type is not compatible with the enclosing method's return type. [n_returnNullableFromMethod.ets:20:16] +TypeError: Return statement's type 'A|null' is not compatible with the enclosing method's return type 'A'. [n_returnNullableFromMethod.ets:20:16] diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 63b294b65cabc536d959139b79a669dbbacbc9b5..79f11b758b6052e1c4afe36c28053fb9562c30d2 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -336,4 +336,4 @@ } } } -TypeError: Initializers type is not assignable to the target type [null_invalid.ets:17:18] +TypeError: Type 'Object|null' is not assignable to type 'Object'. [null_invalid.ets:17:18] diff --git a/ets2panda/test/public/es2panda_public_test.cpp b/ets2panda/test/public/es2panda_public_test.cpp index 03846b4edb2ad52bc77c706bb89004f1a4cb8c28..adf6602db5c5d65d95517e894e83192c2bd7f661 100644 --- a/ets2panda/test/public/es2panda_public_test.cpp +++ b/ets2panda/test/public/es2panda_public_test.cpp @@ -57,6 +57,6 @@ TEST_F(Es2PandaLibTest, TypeError) impl_->ProceedToState(ctx, ES2PANDA_STATE_ASM_GENERATED); // don't produce any object files ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_ERROR); ASSERT_EQ(std::string(impl_->ContextErrorMessage(ctx)), - "TypeError: Initializers type is not assignable to the target type[no-error.ets:1,32]"); + "TypeError: Type 'string' is not assignable to type 'int'.[no-error.ets:1,32]"); impl_->DestroyContext(ctx); }