From baac12d0acb71022c87346202b15aa30f2534df7 Mon Sep 17 00:00:00 2001 From: Soma Simon Date: Wed, 13 Sep 2023 15:07:17 +0200 Subject: [PATCH] Extend error messages of TypeErrors to be more informative Add the type of the expected and the actual type to the message, extend object toString with generic and nullable type. Issue: I8JA25 Change-Id: Iba837c3f0a97dce11d534877d4db5dbbe5cc3b0a Signed-off-by: Soma Simon --- ets2panda/checker/ETSAnalyzer.cpp | 25 +- ets2panda/checker/ets/function.cpp | 15 +- ets2panda/checker/ets/helpers.cpp | 12 +- ets2panda/checker/ets/typeRelationContext.cpp | 7 +- ets2panda/checker/types/ets/etsArrayType.cpp | 5 + ets2panda/checker/types/ets/etsObjectType.cpp | 31 +- ets2panda/checker/types/ets/etsObjectType.h | 2 +- .../ir/expressions/assignmentExpression.cpp | 2 +- ets2panda/ir/expressions/objectExpression.cpp | 16 +- .../compiler/ets/FunctionType1-expected.txt | 2 +- .../compiler/ets/FunctionType3-expected.txt | 2 +- ...rsion_Double-to-Int_typeerror-expected.txt | 2 +- ...le-to-Int_w_try_stmt_typerror-expected.txt | 2 +- ...rsion_Int-to-Double_typeerror-expected.txt | 2 +- ...ntext_Int-to-Double_typeerror-expected.txt | 2 +- .../ets/dynamicLambda_error-expected.txt | 2 +- .../ets/etsObjectToString0-expected.txt | 584 ++++++++++++ .../test/compiler/ets/etsObjectToString0.ets | 21 + .../ets/etsObjectToString1-expected.txt | 640 +++++++++++++ .../test/compiler/ets/etsObjectToString1.ets | 21 + .../ets/etsObjectToString2-expected.txt | 668 +++++++++++++ .../test/compiler/ets/etsObjectToString2.ets | 21 + .../ets/etsObjectToString3-expected.txt | 890 ++++++++++++++++++ .../test/compiler/ets/etsObjectToString3.ets | 21 + .../ets/etsObjectToString4-expected.txt | 468 +++++++++ .../test/compiler/ets/etsObjectToString4.ets | 18 + .../ets/etsObjectToString5-expected.txt | 848 +++++++++++++++++ .../test/compiler/ets/etsObjectToString5.ets | 20 + .../ets/generic_function_call_2-expected.txt | 2 +- .../ets/identifierReference10-expected.txt | 2 +- .../ets/identifierReference2-expected.txt | 2 +- .../ets/identifierReference3-expected.txt | 2 +- .../inferTypeOfArrayNegative3-expected.txt | 2 +- ...utBlockStatementDifferentType-expected.txt | 2 +- ...tementDifferentTypeInfunction-expected.txt | 2 +- .../compiler/ets/lambdaFunction3-expected.txt | 2 +- .../compiler/ets/lambdaFunction5-expected.txt | 2 +- ...ctLiteralPrimitiveContextType-expected.txt | 2 +- .../objectLiteralWrongValueType-expected.txt | 2 +- .../compiler/ets/union_types_4-expected.txt | 2 +- .../async_func_return_type_bad-expected.txt | 2 +- ...ic_class_ctor_decl_import_bad-expected.txt | 2 +- ...class_field_decl_import_bad_1-expected.txt | 2 +- ...class_field_decl_import_bad_2-expected.txt | 2 +- ...lass_method_decl_import_bad_1-expected.txt | 2 +- ...lass_method_decl_import_bad_2-expected.txt | 2 +- .../dynamic_func_decl_import_bad-expected.txt | 2 +- ets2panda/test/parser/ets/enum8-expected.txt | 2 +- ...unction_implicit_return_type2-expected.txt | 2 +- ...unction_implicit_return_type3-expected.txt | 2 +- ...unction_implicit_return_type6-expected.txt | 2 +- ...unction_implicit_return_type7-expected.txt | 2 +- .../ets/n_arrayHoldingNullValue-expected.txt | 2 +- ...ableFromFunctionToNonNullable-expected.txt | 2 +- ...ableFromMethodToNullableParam-expected.txt | 2 +- ...n_assignNullableToNonNullable-expected.txt | 2 +- ...ignNullableToNonNullableArray-expected.txt | 2 +- ...ullableToNonNullableTypeAlias-expected.txt | 2 +- ...callFunctionWithNullableParam-expected.txt | 2 +- ...erfaceMethodWithNullableParam-expected.txt | 2 +- ...n_callMethodWithNullableParam-expected.txt | 2 +- .../ets/n_returnNullFromFunction-expected.txt | 2 +- .../ets/n_returnNullFromMethod-expected.txt | 2 +- .../n_returnNullableFromFunction-expected.txt | 2 +- .../n_returnNullableFromMethod-expected.txt | 2 +- .../test/parser/ets/null_invalid-expected.txt | 2 +- .../test/public/es2panda_public_test.cpp | 2 +- 67 files changed, 4342 insertions(+), 85 deletions(-) create mode 100644 ets2panda/test/compiler/ets/etsObjectToString0-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString0.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString1-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString1.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString2-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString2.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString3-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString3.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString4-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString4.ets create mode 100644 ets2panda/test/compiler/ets/etsObjectToString5-expected.txt create mode 100644 ets2panda/test/compiler/ets/etsObjectToString5.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index f91ee6ca74b..aac27417586 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 7e6538ad779..83c28c9a0cb 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 b1f99ba5be3..65c984c005b 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 ee23d088540..49b6b286b4d 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 5c2bdbac393..0413b698083 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 7d060c93c57..1b2ba7988fb 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 a083979f86f..cb9fa1e52df 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 a6ba7d6ee05..7f048d0a70b 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 f3b4b4ebff0..cab36da7069 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 8a077af2aa1..80fd6bb4b64 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 ca35e1e27ca..81eb2f3927e 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 b96e1faf4dd..28c9cd8746d 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 96c8b5fd3ce..f699a2c68ba 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 18cfe0261da..c64879fae0a 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 a4f0dff3f57..aeb8bbf21e2 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 f52f74f5dac..7fcbe66856b 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 00000000000..0758e8350a8 --- /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 00000000000..08e1c3e1953 --- /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 00000000000..2be087c277a --- /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 00000000000..9b9bd875a92 --- /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 00000000000..15acf6c89bc --- /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 00000000000..e82acf91fa6 --- /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 00000000000..93973186747 --- /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 00000000000..9007b79acc4 --- /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 00000000000..121bd1a53ca --- /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 00000000000..fd7a335c13a --- /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 00000000000..7c37a9feeab --- /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 00000000000..cacf921a8cf --- /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 d7f2b191479..d8e1952590b 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 3eb9089b825..4cc73f5397b 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 07248d61cc7..656f8d63216 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 6495cedbd50..f520e35fcf1 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 aca5d358ee6..680802defdd 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 1a6d1547676..503e841840b 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 7ea24132d85..e5a4114b1d3 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 4fbb638c04d..45e0fa120d2 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 2cae57f050c..7c80bf8ff95 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 67be0003386..37a3c7b89e1 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 cba33cf83f9..e61cbb9d03a 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 f69abcff990..d4232d1a2e9 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 f10a8253c6c..f9f17f4c8eb 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 fa2438b241b..f1737d83d74 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 1a691d4d82c..5bd8c55bdcb 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 88718c571e3..b135db0049d 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 6eac80975ca..1c569acd207 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 9b52cc0ef3d..9f5dcf3dabf 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 3e84372b587..03c3e6774e0 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 67d246372e6..f22e386e9ad 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 e765b5e9e3e..659bc5b99da 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 86c0bf3a67b..4a615f2ab6b 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 c942bc192dc..228514b4f27 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 478d07c0ed0..093d005aa15 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 d90b7f2cbad..982a4d6c224 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 cf852cc4c9f..7e7ac30e3cb 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 2f578633792..50ba9c77601 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 c8a3c89c365..16241447426 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 9b424caf232..37eba65c79e 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 2ac81c66dd1..23e5705055e 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 5dffc7d900e..8d7674b5ed1 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 1aed437dc32..2ffceddcd9f 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 66b61478716..9bee3762009 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 8d0cbdb7442..2f97a5bd3a2 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 6475dcf314b..7f8e30a1755 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 7a4275b3329..265c9065ba3 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 df711d1502c..3555c372db0 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 63b294b65ca..79f11b758b6 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 03846b4edb2..adf6602db5c 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); } -- Gitee