diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 6a29659a5f81d0b0b688016ff33f10360aa8f0b9..973abed82bc7a5ba8300cae7a63420fa03a29e8c 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -72,6 +72,7 @@ libes2panda_sources = [ "checker/types/ets/etsFunctionType.cpp", "checker/types/ets/etsObjectType.cpp", "checker/types/ets/etsStringType.cpp", + "checker/types/ets/etsTupleType.cpp", "checker/types/ets/etsTypeParameter.cpp", "checker/types/ets/etsUnionType.cpp", "checker/types/ets/etsVoidType.cpp", @@ -156,6 +157,7 @@ libes2panda_sources = [ "compiler/lowering/checkerPhase.cpp", "compiler/lowering/ets/generateDeclarations.cpp", "compiler/lowering/ets/opAssignment.cpp", + "compiler/lowering/ets/tupleLowering.cpp", "compiler/lowering/ets/unionLowering.cpp", "compiler/lowering/phase.cpp", "compiler/lowering/util.cpp", @@ -192,6 +194,7 @@ libes2panda_sources = [ "ir/ets/etsPrimitiveType.cpp", "ir/ets/etsScript.cpp", "ir/ets/etsStructDeclaration.cpp", + "ir/ets/etsTuple.cpp", "ir/ets/etsTypeReference.cpp", "ir/ets/etsTypeReferencePart.cpp", "ir/ets/etsUnionType.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 463ac9740cc65699399329dc2787691508ead700..c8d2db39d31288da5811b15a60e5748aca8e3dd8 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -138,6 +138,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/util.cpp compiler/lowering/ets/generateDeclarations.cpp compiler/lowering/ets/opAssignment.cpp + compiler/lowering/ets/tupleLowering.cpp compiler/lowering/ets/unionLowering.cpp ir/astDump.cpp ir/astNode.cpp @@ -242,6 +243,7 @@ set(ES2PANDA_LIB_SRC ir/ets/etsParameterExpression.cpp ir/ets/etsPrimitiveType.cpp ir/ets/etsScript.cpp + ir/ets/etsTuple.cpp ir/ets/etsTypeReference.cpp ir/ets/etsTypeReferencePart.cpp ir/ets/etsUnionType.cpp @@ -372,6 +374,7 @@ set(ES2PANDA_LIB_SRC checker/types/ets/etsFunctionType.cpp checker/types/ets/etsObjectType.cpp checker/types/ets/etsStringType.cpp + checker/types/ets/etsTupleType.cpp checker/types/ets/etsTypeParameter.cpp checker/types/ets/etsUnionType.cpp checker/types/ets/etsVoidType.cpp diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index c26e12302dfa23fe17414210e3865726446af043..9da39265662800a5392d0237cba0f385154df95e 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -453,6 +453,12 @@ checker::Type *ETSAnalyzer::Check(ir::ETSStructDeclaration *node) const return nullptr; } +checker::Type *ETSAnalyzer::Check(ir::ETSTuple *node) const +{ + (void)node; + UNREACHABLE(); +} + checker::Type *ETSAnalyzer::Check(ir::ETSTypeReference *node) const { ETSChecker *checker = GetETSChecker(); @@ -1545,8 +1551,8 @@ checker::Type *ETSAnalyzer::Check(ir::ReturnStatement *st) const } if ((st->argument_ != nullptr) && st->argument_->IsArrayExpression()) { - st->argument_->AsArrayExpression()->SetPreferredType( - func_return_type->IsETSArrayType() ? func_return_type->AsETSArrayType()->ElementType() : func_return_type); + checker->ModifyPreferredType(st->argument_->AsArrayExpression(), func_return_type); + st->argument_->Check(checker); } st->return_type_ = func_return_type; diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 87fc469310256e6f5cdb6c2ae77fe7c722b4cd85..4122f3aef908a6a9316487b2ea3b4f0c428b6d11 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -17,20 +17,20 @@ #define ES2PANDA_CHECKER_ETS_CHECKER_H #include "checker/checkerContext.h" -#include "checker/types/ets/etsObjectType.h" -#include "checker/checker.h" #include "varbinder/enumMemberResult.h" +#include "varbinder/scope.h" +#include "checker/checker.h" +#include "checker/ets/primitiveWrappers.h" +#include "checker/ets/typeConverter.h" +#include "checker/types/ets/etsObjectType.h" +#include "checker/types/ets/etsTupleType.h" +#include "checker/types/ets/types.h" +#include "checker/types/globalTypesHolder.h" #include "ir/ts/tsTypeParameter.h" #include "ir/ts/tsTypeParameterInstantiation.h" #include "util/enumbitops.h" #include "util/ustring.h" #include "checker/resolveResult.h" -#include "checker/types/ets/types.h" -#include "checker/ets/typeConverter.h" -#include "checker/ets/primitiveWrappers.h" -#include "checker/types/globalTypesHolder.h" -#include "varbinder/scope.h" - #include "macros.h" #include @@ -136,7 +136,9 @@ public: void ValidateImplementedInterface(ETSObjectType *type, Type *interface, std::unordered_set *extends_set, const lexer::SourcePosition &pos); void ResolveDeclaredMembersOfObject(ETSObjectType *type); + int32_t GetTupleElementAccessValue(const Type *type) const; Type *ValidateArrayIndex(ir::Expression *expr); + void ValidateTupleIndex(const ETSTupleType *tuple, const ir::MemberExpression *expr); ETSObjectType *CheckThisOrSuperAccess(ir::Expression *node, ETSObjectType *class_type, std::string_view msg); void CreateTypeForClassOrInterfaceTypeParameters(ETSObjectType *type); void SetTypeParameterType(ir::TSTypeParameter *type_param, Type *type_param_type); @@ -489,6 +491,8 @@ public: ETSChecker *checker); void SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpression *expr, Type *annotation_type); bool ExtensionETSFunctionType(checker::Type *type); + void ValidateTupleMinElementSize(ir::ArrayExpression *array_expr, ETSTupleType *tuple); + void ModifyPreferredType(ir::ArrayExpression *array_expr, Type *new_preferred_type); // Exception ETSObjectType *CheckExceptionOrErrorType(checker::Type *type, lexer::SourcePosition pos); diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 49ebfde42f51c16072b57f36c933341a4aee7e70..7717c57063227f4621221222d4326cc8eae60359 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -251,6 +251,12 @@ checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSStructDeclaration *node UNREACHABLE(); } +checker::Type *TSAnalyzer::Check(ir::ETSTuple *node) const +{ + (void)node; + UNREACHABLE(); +} + checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSTypeReference *node) const { UNREACHABLE(); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 73311393661a09964e961fe4673159a8a0ac6b8a..6cc2814a6fb82277e6663adfb31fd9c643a38f4d 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -888,7 +888,11 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T } if (init->IsArrayExpression() && annotation_type->IsETSArrayType()) { - init->AsArrayExpression()->SetPreferredType(annotation_type->AsETSArrayType()->ElementType()); + if (annotation_type->IsETSTupleType()) { + ValidateTupleMinElementSize(init->AsArrayExpression(), annotation_type->AsETSTupleType()); + } + + init->AsArrayExpression()->SetPreferredType(annotation_type); } if (init->IsObjectExpression()) { @@ -965,7 +969,7 @@ void ETSChecker::SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpre // Set explicit target type for array if ((object != nullptr) && (object->IsArrayExpression())) { ir::ArrayExpression *array = object->AsArrayExpression(); - array->SetPreferredType(element_type); + array->SetPreferredType(CreateETSArrayType(element_type)); } } @@ -2258,6 +2262,28 @@ bool ETSChecker::ExtensionETSFunctionType(checker::Type *type) return false; } +void ETSChecker::ValidateTupleMinElementSize(ir::ArrayExpression *const array_expr, ETSTupleType *tuple) +{ + if (array_expr->Elements().size() < static_cast(tuple->GetMinTupleSize())) { + ThrowTypeError({"Few elements in array initializer for tuple with size of ", + static_cast(tuple->GetMinTupleSize())}, + array_expr->Start()); + } +} + +void ETSChecker::ModifyPreferredType(ir::ArrayExpression *const array_expr, Type *const new_preferred_type) +{ + // After modifying the preferred type of an array expression, it needs to be rechecked at the call site + array_expr->SetPreferredType(new_preferred_type); + array_expr->SetTsType(nullptr); + + for (auto *const element : array_expr->Elements()) { + if (element->IsArrayExpression()) { + ModifyPreferredType(element->AsArrayExpression(), nullptr); + } + } +} + bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, const Type *resolved_type) { ASSERT(ident->Parent()->IsCallExpression()); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 3de0b51247e8420256b92e76e1292216d3413a91..a7d0055f07cb1ae426e7e141290725a9a175a6e2 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -14,6 +14,7 @@ */ #include "varbinder/variableFlags.h" +#include "checker/ets/castingContext.h" #include "checker/types/ets/etsObjectType.h" #include "ir/astNode.h" #include "ir/typeNode.h" @@ -923,6 +924,46 @@ Type *ETSChecker::ValidateArrayIndex(ir::Expression *expr) return index_type; } +int32_t ETSChecker::GetTupleElementAccessValue(const Type *const type) const +{ + ASSERT(type->HasTypeFlag(TypeFlag::CONSTANT | TypeFlag::ETS_NUMERIC)); + + switch (ETSType(type)) { + case TypeFlag::BYTE: { + return type->AsByteType()->GetValue(); + } + case TypeFlag::SHORT: { + return type->AsShortType()->GetValue(); + } + case TypeFlag::INT: { + return type->AsIntType()->GetValue(); + } + default: { + UNREACHABLE(); + } + } +} + +void ETSChecker::ValidateTupleIndex(const ETSTupleType *const tuple, const ir::MemberExpression *const expr) +{ + const auto *const expr_type = expr->Property()->TsType(); + ASSERT(expr_type != nullptr); + + if (!expr_type->HasTypeFlag(TypeFlag::CONSTANT) && !tuple->HasSpreadType()) { + ThrowTypeError("Only constant expression allowed for element access on tuples.", expr->Property()->Start()); + } + + if (!expr_type->HasTypeFlag(TypeFlag::ETS_ARRAY_INDEX)) { + ThrowTypeError("Only integer type allowed for element access on tuples.", expr->Property()->Start()); + } + + const int32_t expr_value = GetTupleElementAccessValue(expr_type); + + if (((expr_value >= tuple->GetTupleSize()) && !tuple->HasSpreadType()) || (expr_value < 0)) { + ThrowTypeError("Element accessor value is out of tuple size bounds.", expr->Property()->Start()); + } +} + ETSObjectType *ETSChecker::CheckThisOrSuperAccess(ir::Expression *node, ETSObjectType *class_type, std::string_view msg) { if ((Context().Status() & CheckerStatus::IGNORE_VISIBILITY) != 0U) { diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 03be8f6bda655f04b4c21ddc1fdb27d9c413541e..0bbde988c8a7f3b94d62a8202bd7a2d5e14fedcf 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -13,18 +13,24 @@ * limitations under the License. */ -#include "generated/signatures.h" #include "checker/ETSchecker.h" +#include "checker/types/ets/byteType.h" +#include "checker/types/ets/charType.h" #include "checker/types/ets/etsDynamicFunctionType.h" -#include "varbinder/varbinder.h" -#include "varbinder/ETSBinder.h" -#include "ir/ets/etsScript.h" +#include "checker/types/ets/etsDynamicType.h" +#include "checker/types/ets/etsStringType.h" +#include "checker/types/ets/etsUnionType.h" +#include "checker/types/ets/shortType.h" +#include "generated/signatures.h" #include "ir/base/classDefinition.h" #include "ir/base/scriptFunction.h" +#include "ir/ets/etsScript.h" #include "ir/expressions/identifier.h" #include "ir/ts/tsEnumDeclaration.h" #include "ir/ts/tsEnumMember.h" #include "ir/ts/tsInterfaceDeclaration.h" +#include "varbinder/varbinder.h" +#include "varbinder/ETSBinder.h" #include "parser/program/program.h" #include "util/helpers.h" diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index b89612f33a37925d9309f4b441c900b639d1bce8..df9af96acc4b39244c929d14ae6e467ce6d47aae 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -14,18 +14,21 @@ */ #include "typeRelationContext.h" -#include "varbinder/variable.h" #include "varbinder/scope.h" +#include "varbinder/variable.h" #include "varbinder/declaration.h" +#include "checker/types/ets/etsUnionType.h" #include "ir/expressions/arrayExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/ts/tsArrayType.h" #include "ir/ts/tsTypeParameter.h" namespace panda::es2panda::checker { void AssignmentContext::ValidateArrayTypeInitializerByElement(TypeRelation *relation, ir::ArrayExpression *node, ETSArrayType *target) { + if (target->IsETSTupleType()) { + return; + } + for (uint32_t index = 0; index < node->Elements().size(); index++) { ir::Expression *current_array_elem = node->Elements()[index]; AssignmentContext(relation, current_array_elem, diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp new file mode 100644 index 0000000000000000000000000000000000000000..616d74935dc38649f4a23c5353651fd89f2667f1 --- /dev/null +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -0,0 +1,191 @@ +/** + * 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. + */ + +#include "etsTupleType.h" +#include "checker/ets/conversion.h" + +namespace panda::es2panda::checker { +void ETSTupleType::ToString(std::stringstream &ss) const +{ + ss << "["; + for (const auto *const type : type_list_) { + type->ToString(ss); + } + + if (spread_type_ != nullptr) { + ss << ", ..."; + spread_type_->ToString(ss); + ss << "[]"; + } + + ss << "]"; +} + +Type *ETSTupleType::GetTypeAtIndex(const TupleSizeType index) const +{ + return index >= GetTupleSize() ? GetSpreadType() : GetTupleTypesList().at(static_cast(index)); +} + +void ETSTupleType::Identical([[maybe_unused]] TypeRelation *const relation, Type *const other) +{ + if (!other->IsETSTupleType()) { + return; + } + + const auto *const other_tuple = other->AsETSTupleType(); + + if (GetMinTupleSize() != other_tuple->GetMinTupleSize()) { + return; + } + + for (TupleSizeType idx = 0; idx < GetMinTupleSize(); ++idx) { + if (!relation->IsIdenticalTo(GetTypeAtIndex(idx), other_tuple->GetTypeAtIndex(idx))) { + relation->Result(false); + return; + } + } + + if (HasSpreadType() != other_tuple->HasSpreadType()) { + relation->Result(false); + return; + } + + relation->Result(true); +} + +bool ETSTupleType::AssignmentSource(TypeRelation *const relation, Type *const target) +{ + if (!(target->IsETSTupleType() || target->IsETSArrayType())) { + return false; + } + + if (!target->IsETSTupleType()) { + ASSERT(target->IsETSArrayType()); + auto *const array_target = target->AsETSArrayType(); + + const SavedTypeRelationFlagsContext saved_flags_ctx( + relation, TypeRelationFlag::NO_BOXING | TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_WIDENING); + + relation->Result(relation->IsAssignableTo(ElementType(), array_target->ElementType())); + } + + return relation->IsTrue(); +} + +void ETSTupleType::AssignmentTarget(TypeRelation *const relation, Type *const source) +{ + if (!(source->IsETSTupleType() || (source->IsETSArrayType() && HasSpreadType()))) { + return; + } + + if (!source->IsETSTupleType()) { + ASSERT(source->IsETSArrayType()); + auto *const array_source = source->AsETSArrayType(); + + const SavedTypeRelationFlagsContext saved_flags_ctx( + relation, TypeRelationFlag::NO_BOXING | TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_WIDENING); + + relation->Result(relation->IsAssignableTo(array_source->ElementType(), ElementType())); + return; + } + + const auto *const tuple_source = source->AsETSTupleType(); + + if (tuple_source->GetMinTupleSize() != GetMinTupleSize()) { + return; + } + + for (int32_t idx = 0; idx < GetMinTupleSize(); ++idx) { + // because an array assignment to another array simply copies it's memory address, then it's not possible to + // make boxing/unboxing/widening for types. Only conversion allowed is reference widening, which won't generate + // bytecode for the conversion, same as for arrays. + + const SavedTypeRelationFlagsContext saved_flags_ctx( + relation, TypeRelationFlag::NO_BOXING | TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_WIDENING); + + if (!relation->IsAssignableTo(tuple_source->GetTypeAtIndex(idx), GetTypeAtIndex(idx))) { + relation->Result(false); + return; + } + } + + if (!HasSpreadType() && tuple_source->HasSpreadType()) { + relation->Result(false); + return; + } + + relation->Result(true); +} + +void ETSTupleType::Cast(TypeRelation *const relation, Type *const target) +{ + // TODO(mmartin): Might be not the correct casting rules, as these aren't defined yet + + if (!(target->IsETSTupleType() || target->IsETSArrayType())) { + conversion::Forbidden(relation); + return; + } + + if (target->IsETSArrayType() && (!target->IsETSTupleType())) { + auto *const array_target = target->AsETSArrayType(); + + if (!array_target->ElementType()->IsETSObjectType()) { + conversion::Forbidden(relation); + return; + } + + const SavedTypeRelationFlagsContext saved_flags_ctx( + relation, TypeRelationFlag::NO_BOXING | TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_WIDENING); + + const bool elements_assignable = + std::all_of(GetTupleTypesList().begin(), GetTupleTypesList().end(), + [&relation, &array_target](auto *const tuple_type_at_idx) { + return relation->IsAssignableTo(tuple_type_at_idx, array_target->ElementType()); + }); + + bool spread_assignable = true; + if (HasSpreadType()) { + spread_assignable = relation->IsAssignableTo(GetSpreadType(), array_target->ElementType()); + } + + relation->Result(elements_assignable && spread_assignable); + return; + } + + const auto *const tuple_target = target->AsETSTupleType(); + + if (tuple_target->GetTupleSize() != GetTupleSize()) { + return; + } + + for (int32_t idx = 0; idx < GetTupleSize(); ++idx) { + const SavedTypeRelationFlagsContext saved_flags_ctx( + relation, TypeRelationFlag::NO_BOXING | TypeRelationFlag::NO_UNBOXING | TypeRelationFlag::NO_WIDENING); + + if (!relation->IsAssignableTo(tuple_target->GetTypeAtIndex(idx), GetTypeAtIndex(idx))) { + return; + } + } + + relation->Result(true); +} + +Type *ETSTupleType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, + [[maybe_unused]] GlobalTypesHolder *global_types) +{ + return this; +} + +} // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsTupleType.h b/ets2panda/checker/types/ets/etsTupleType.h new file mode 100644 index 0000000000000000000000000000000000000000..2daefee0deb8286dfb73dde5ea222d546cb2374a --- /dev/null +++ b/ets2panda/checker/types/ets/etsTupleType.h @@ -0,0 +1,99 @@ +/** + * 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. + */ + +#ifndef ES2PANDA_COMPILER_CHECKER_TYPES_ETS_TUPLE_TYPE_H +#define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_TUPLE_TYPE_H + +#include "checker/types/type.h" +#include "checker/types/ets/etsArrayType.h" + +namespace panda::es2panda::checker { + +class ETSTupleType : public ETSArrayType { + using TupleSizeType = int32_t; + +public: + explicit ETSTupleType(ArenaAllocator *const allocator, Type *const element_type = nullptr, + Type *const spread_type = nullptr) + : ETSArrayType(element_type), type_list_(allocator->Adapter()), spread_type_(spread_type) + { + type_flags_ |= TypeFlag::ETS_TUPLE; + } + + explicit ETSTupleType(ArenaAllocator *const allocator, const TupleSizeType size, Type *const element_type = nullptr, + Type *const spread_type = nullptr) + : ETSArrayType(element_type), type_list_(allocator->Adapter()), spread_type_(spread_type), size_(size) + { + type_flags_ |= TypeFlag::ETS_TUPLE; + } + explicit ETSTupleType(const ArenaVector &type_list, Type *const element_type = nullptr, + Type *const spread_type = nullptr) + : ETSArrayType(element_type), + type_list_(type_list), + spread_type_(spread_type), + size_(static_cast(type_list.size())) + { + type_flags_ |= TypeFlag::ETS_TUPLE; + } + + [[nodiscard]] TupleSizeType GetTupleSize() const + { + return size_; + } + + [[nodiscard]] TupleSizeType GetMinTupleSize() const + { + return size_ + (spread_type_ == nullptr ? 0 : 1); + } + + [[nodiscard]] ArenaVector GetTupleTypesList() const + { + return type_list_; + } + + [[nodiscard]] bool HasSpreadType() const + { + return spread_type_ != nullptr; + } + + [[nodiscard]] Type *GetSpreadType() const + { + return spread_type_; + } + + void SetSpreadType(Type *const new_spread_type) + { + spread_type_ = new_spread_type; + } + + [[nodiscard]] Type *GetTypeAtIndex(int32_t index) const; + + void ToString(std::stringstream &ss) const override; + + void Identical(TypeRelation *relation, Type *other) override; + void AssignmentTarget(TypeRelation *relation, Type *source) override; + bool AssignmentSource(TypeRelation *relation, Type *target) override; + void Cast(TypeRelation *relation, Type *target) override; + Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types) override; + +private: + ArenaVector type_list_; + Type *spread_type_ {}; + TupleSizeType size_ {0}; +}; + +} // namespace panda::es2panda::checker + +#endif /* ES2PANDA_COMPILER_CHECKER_TYPES_ETS_TUPLE_TYPE_H */ diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index 7a26628209dce4b89f47d4dae61efbe9f2ad3963..1d02fd05d8aa9127704bbdb5d4425054afc4e4d2 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -80,6 +80,7 @@ enum class TypeFlag : uint64_t { SETTER = 1ULL << 55ULL, // ETS Setter ETS_EXTENSION_FUNC_HELPER = 1ULL << 56ULL, // ETS Extension Function Helper ETS_UNION = 1ULL << 57ULL, // ETS union + ETS_TUPLE = 1ULL << 58ULL, // ETS tuple type ETS_DYNAMIC_TYPE = ETS_OBJECT | ETS_DYNAMIC_FLAG, ETS_DYNAMIC_FUNCTION_TYPE = FUNCTION | ETS_DYNAMIC_FLAG, ETS_TYPE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID | ETS_OBJECT | ETS_ARRAY | diff --git a/ets2panda/checker/types/typeMapping.h b/ets2panda/checker/types/typeMapping.h index 3d6d406d80b40dfd1b2daba10cc8576180a702cf..12bf57b7d4532a7d23292a1434e1b064f5ef2af2 100644 --- a/ets2panda/checker/types/typeMapping.h +++ b/ets2panda/checker/types/typeMapping.h @@ -19,47 +19,48 @@ #include "typeFlag.h" // NOLINTBEGIN(cppcoreguidelines-macro-usage) -#define TYPE_MAPPING(_) \ - _(TypeFlag::ARRAY, ArrayType) \ - _(TypeFlag::ANY, AnyType) \ - _(TypeFlag::BIGINT_LITERAL, BigintLiteralType) \ - _(TypeFlag::NUMBER, NumberType) \ - _(TypeFlag::STRING, StringType) \ - _(TypeFlag::BOOLEAN, BooleanType) \ - _(TypeFlag::VOID, VoidType) \ - _(TypeFlag::NULL_TYPE, NullType) \ - _(TypeFlag::UNDEFINED, UndefinedType) \ - _(TypeFlag::UNKNOWN, UnknownType) \ - _(TypeFlag::NEVER, NeverType) \ - _(TypeFlag::UNION, UnionType) \ - _(TypeFlag::OBJECT, ObjectType) \ - _(TypeFlag::BIGINT, BigintType) \ - _(TypeFlag::BOOLEAN_LITERAL, BooleanLiteralType) \ - _(TypeFlag::NUMBER_LITERAL, NumberLiteralType) \ - _(TypeFlag::STRING_LITERAL, StringLiteralType) \ - _(TypeFlag::ENUM, EnumType) \ - _(TypeFlag::ENUM_LITERAL, EnumLiteralType) \ - _(TypeFlag::TYPE_PARAMETER, TypeParameter) \ - _(TypeFlag::TYPE_REFERENCE, TypeReference) \ - _(TypeFlag::BYTE, ByteType) \ - _(TypeFlag::SHORT, ShortType) \ - _(TypeFlag::INT, IntType) \ - _(TypeFlag::LONG, LongType) \ - _(TypeFlag::FLOAT, FloatType) \ - _(TypeFlag::DOUBLE, DoubleType) \ - _(TypeFlag::CHAR, CharType) \ - _(TypeFlag::ETS_BOOLEAN, ETSBooleanType) \ - _(TypeFlag::ETS_VOID, ETSVoidType) \ - _(TypeFlag::FUNCTION, ETSFunctionType) \ - _(TypeFlag::ETS_OBJECT, ETSObjectType) \ - _(TypeFlag::ETS_ARRAY, ETSArrayType) \ - _(TypeFlag::ETS_UNION, ETSUnionType) \ - _(TypeFlag::NON_PRIMITIVE, NonPrimitiveType) \ - _(TypeFlag::WILDCARD, WildcardType) \ - _(TypeFlag::ETS_TYPE_PARAMETER, ETSTypeParameter) \ - _(TypeFlag::ETS_ENUM, ETSEnumType) \ - _(TypeFlag::ETS_STRING_ENUM, ETSStringEnumType) \ - _(TypeFlag::ETS_EXTENSION_FUNC_HELPER, ETSExtensionFuncHelperType) +#define TYPE_MAPPING(_) \ + _(TypeFlag::ARRAY, ArrayType) \ + _(TypeFlag::ANY, AnyType) \ + _(TypeFlag::BIGINT_LITERAL, BigintLiteralType) \ + _(TypeFlag::NUMBER, NumberType) \ + _(TypeFlag::STRING, StringType) \ + _(TypeFlag::BOOLEAN, BooleanType) \ + _(TypeFlag::VOID, VoidType) \ + _(TypeFlag::NULL_TYPE, NullType) \ + _(TypeFlag::UNDEFINED, UndefinedType) \ + _(TypeFlag::UNKNOWN, UnknownType) \ + _(TypeFlag::NEVER, NeverType) \ + _(TypeFlag::UNION, UnionType) \ + _(TypeFlag::OBJECT, ObjectType) \ + _(TypeFlag::BIGINT, BigintType) \ + _(TypeFlag::BOOLEAN_LITERAL, BooleanLiteralType) \ + _(TypeFlag::NUMBER_LITERAL, NumberLiteralType) \ + _(TypeFlag::STRING_LITERAL, StringLiteralType) \ + _(TypeFlag::ENUM, EnumType) \ + _(TypeFlag::ENUM_LITERAL, EnumLiteralType) \ + _(TypeFlag::TYPE_PARAMETER, TypeParameter) \ + _(TypeFlag::TYPE_REFERENCE, TypeReference) \ + _(TypeFlag::BYTE, ByteType) \ + _(TypeFlag::SHORT, ShortType) \ + _(TypeFlag::INT, IntType) \ + _(TypeFlag::LONG, LongType) \ + _(TypeFlag::FLOAT, FloatType) \ + _(TypeFlag::DOUBLE, DoubleType) \ + _(TypeFlag::CHAR, CharType) \ + _(TypeFlag::ETS_BOOLEAN, ETSBooleanType) \ + _(TypeFlag::ETS_VOID, ETSVoidType) \ + _(TypeFlag::FUNCTION, ETSFunctionType) \ + _(TypeFlag::ETS_OBJECT, ETSObjectType) \ + _(TypeFlag::ETS_ARRAY, ETSArrayType) \ + _(TypeFlag::ETS_UNION, ETSUnionType) \ + _(TypeFlag::NON_PRIMITIVE, NonPrimitiveType) \ + _(TypeFlag::WILDCARD, WildcardType) \ + _(TypeFlag::ETS_TYPE_PARAMETER, ETSTypeParameter) \ + _(TypeFlag::ETS_ENUM, ETSEnumType) \ + _(TypeFlag::ETS_STRING_ENUM, ETSStringEnumType) \ + _(TypeFlag::ETS_EXTENSION_FUNC_HELPER, ETSExtensionFuncHelperType) \ + _(TypeFlag::ETS_TUPLE, ETSTupleType) #define OBJECT_TYPE_MAPPING(_) \ _(ObjectType::ObjectTypeKind::FUNCTION, FunctionType) \ diff --git a/ets2panda/compiler/base/lreference.cpp b/ets2panda/compiler/base/lreference.cpp index eba0f7c898aee98c9666f3ee65c31a90ed968c7e..2087869948c7355e7ae5791a3252e2611b60e793 100644 --- a/ets2panda/compiler/base/lreference.cpp +++ b/ets2panda/compiler/base/lreference.cpp @@ -273,13 +273,26 @@ void ETSLReference::GetValue() const void ETSLReference::SetValueComputed(const ir::MemberExpression *member_expr) const { - auto object_type = member_expr->Object()->TsType(); + const auto *const object_type = member_expr->Object()->TsType(); + if (object_type->IsETSDynamicType()) { - auto lang = object_type->AsETSDynamicType()->Language(); + const auto lang = object_type->AsETSDynamicType()->Language(); etsg_->StoreElementDynamic(Node(), base_reg_, prop_reg_, lang); - } else { - etsg_->StoreArrayElement(Node(), base_reg_, prop_reg_, - etsg_->GetVRegType(base_reg_)->AsETSArrayType()->ElementType()); + return; + } + + // Same bypass for tuples, as at MemberExpression::Compile + const auto *const saved_vreg_type = etsg_->GetVRegType(base_reg_); + + if (object_type->IsETSTupleType()) { + etsg_->SetVRegType(base_reg_, object_type); + } + + etsg_->StoreArrayElement(Node(), base_reg_, prop_reg_, + etsg_->GetVRegType(base_reg_)->AsETSArrayType()->ElementType()); + + if (object_type->IsETSTupleType()) { + etsg_->SetVRegType(base_reg_, saved_vreg_type); } } @@ -299,49 +312,62 @@ void ETSLReference::SetValueGetterSetter(const ir::MemberExpression *member_expr void ETSLReference::SetValue() const { - if (Kind() == ReferenceKind::MEMBER) { - auto *member_expr = Node()->AsMemberExpression(); - if (!member_expr->IsIgnoreBox()) { - etsg_->ApplyConversion(Node(), member_expr->TsType()); - } + if (Kind() != ReferenceKind::MEMBER) { + etsg_->StoreVar(Node()->AsIdentifier(), Result()); + return; + } - if (member_expr->IsComputed()) { - SetValueComputed(member_expr); - return; - } + const auto *const member_expr = Node()->AsMemberExpression(); + const auto *const member_expr_ts_type = member_expr->Object()->TsType()->IsETSTupleType() + ? member_expr->Object()->TsType()->AsETSTupleType()->ElementType() + : member_expr->TsType(); - if (member_expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { - SetValueGetterSetter(member_expr); - return; - } + if (!member_expr->IsIgnoreBox()) { + etsg_->ApplyConversion(Node(), member_expr_ts_type); + } - auto &prop_name = member_expr->Property()->AsIdentifier()->Name(); - if (member_expr->PropVar()->HasFlag(varbinder::VariableFlags::STATIC)) { - util::StringView full_name = etsg_->FormClassPropReference(static_obj_ref_->AsETSObjectType(), prop_name); - if (static_obj_ref_->IsETSDynamicType()) { - auto lang = static_obj_ref_->AsETSDynamicType()->Language(); - etsg_->StorePropertyDynamic(Node(), member_expr->TsType(), base_reg_, prop_name, lang); - } else { - etsg_->StoreStaticProperty(Node(), member_expr->TsType(), full_name); - } - return; - } + if (member_expr->IsComputed()) { + SetValueComputed(member_expr); + return; + } + + if (member_expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { + SetValueGetterSetter(member_expr); + return; + } + + const auto &prop_name = member_expr->Property()->AsIdentifier()->Name(); + if (member_expr->PropVar()->HasFlag(varbinder::VariableFlags::STATIC)) { + const util::StringView full_name = etsg_->FormClassPropReference(static_obj_ref_->AsETSObjectType(), prop_name); if (static_obj_ref_->IsETSDynamicType()) { - auto lang = static_obj_ref_->AsETSDynamicType()->Language(); - etsg_->StorePropertyDynamic(Node(), member_expr->TsType(), base_reg_, prop_name, lang); - } else if (static_obj_ref_->IsETSUnionType()) { - etsg_->StoreUnionProperty(Node(), base_reg_, prop_name); + const auto lang = static_obj_ref_->AsETSDynamicType()->Language(); + etsg_->StorePropertyDynamic(Node(), member_expr_ts_type, base_reg_, prop_name, lang); } else { - auto type = etsg_->Checker()->MaybeBoxedType(member_expr->PropVar(), etsg_->Allocator()); - if (type->IsETSUnionType()) { - type = type->AsETSUnionType()->GetLeastUpperBoundType(); - } - etsg_->StoreProperty(Node(), type, base_reg_, prop_name); + etsg_->StoreStaticProperty(Node(), member_expr_ts_type, full_name); } - } else { - etsg_->StoreVar(Node()->AsIdentifier(), Result()); + + return; } + + if (static_obj_ref_->IsETSDynamicType()) { + const auto lang = static_obj_ref_->AsETSDynamicType()->Language(); + etsg_->StorePropertyDynamic(Node(), member_expr_ts_type, base_reg_, prop_name, lang); + return; + } + + if (static_obj_ref_->IsETSUnionType()) { + etsg_->StoreUnionProperty(Node(), base_reg_, prop_name); + return; + } + + const auto *type = etsg_->Checker()->MaybeBoxedType(member_expr->PropVar(), etsg_->Allocator()); + + if (type->IsETSUnionType()) { + type = type->AsETSUnionType()->GetLeastUpperBoundType(); + } + + etsg_->StoreProperty(Node(), type, base_reg_, prop_name); } } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 6ee70ad191040eb3ba06d358f357beeb3794599e..f87217da311c96c24f6460636a91eb80d57b0d0a 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -152,6 +152,12 @@ void ETSCompiler::Compile(const ir::ETSFunctionType *node) const UNREACHABLE(); } +void ETSCompiler::Compile(const ir::ETSTuple *node) const +{ + (void)node; + UNREACHABLE(); +} + void ETSCompiler::Compile(const ir::ETSImportDeclaration *node) const { (void)node; diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 30b85196537359b852c43094dea5fbb21599e6f6..1f93cf92610f4ae98cbd885ef3d3c444ad63228a 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -69,14 +69,24 @@ void ETSGen::CompileAndCheck(const ir::Expression *expr) // NOTE: vpukhov. bad accumulator type leads to terrible bugs in codegen // make exact types match mandatory expr->Compile(this); + + if (expr->TsType()->IsETSTupleType()) { + // This piece of code is necessary to handle multidimensional tuples. As a tuple is stored as an + // array of `Objects`. If we make an array inside of the tuple type, then we won't be able to derefer a + // 2 dimensional array, with an array that expects to return `Object` after index access. + EmitCheckedNarrowingReferenceConversion(expr, expr->TsType()); + } + auto const *const acc_type = GetAccumulatorType(); if (acc_type == expr->TsType()) { return; } + if (acc_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) && ((acc_type->TypeFlags() ^ expr->TsType()->TypeFlags()) & ~checker::TypeFlag::CONSTANT) == 0) { return; } + ASSERT(!"Type mismatch after Expression::Compile"); } diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index 090f5f4ec79163bae0faa14f87f884d41aa6d6dd..d30777586dac0f3de6432d07010d2fc1e8bc9d1c 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -481,6 +481,12 @@ void JSCompiler::Compile(const ir::ETSFunctionType *expr) const UNREACHABLE(); } +void JSCompiler::Compile(const ir::ETSTuple *expr) const +{ + (void)expr; + UNREACHABLE(); +} + void JSCompiler::Compile(const ir::ETSImportDeclaration *node) const { (void)node; diff --git a/ets2panda/compiler/lowering/ets/tupleLowering.cpp b/ets2panda/compiler/lowering/ets/tupleLowering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2761633d94e3086e218240009a94b0f249d0c24 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/tupleLowering.cpp @@ -0,0 +1,265 @@ +/** + * 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. + */ + +#include "tupleLowering.h" + +#include "checker/ETSchecker.h" +#include "checker/checker.h" +#include "checker/types/type.h" +#include "compiler/core/compilerContext.h" +#include "compiler/lowering/util.h" +#include "ir/astNode.h" +#include "ir/expression.h" +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/memberExpression.h" +#include "ir/expressions/sequenceExpression.h" +#include "ir/expressions/updateExpression.h" +#include "ir/opaqueTypeNode.h" +#include "ir/statements/blockStatement.h" +#include "ir/ts/tsAsExpression.h" + +namespace panda::es2panda::compiler { + +std::string const &TupleLowering::Name() +{ + static std::string const NAME = "tuple-lowering"; + return NAME; +} + +static ir::Expression *ConvertTupleUpdate(checker::ETSChecker *const checker, ir::UpdateExpression *const update) +{ + // Converts `tuple[n]++` to + // ``` + // let gensym = tuple[n] as ; // line 1 + // let gensym2 = (gensym)++; // line 2 + // tuple[n] = (gensym as ) as ; // line 3 + // gensym2 as ; // line 4 + // ``` + // Notes: + // --- + // Because we can modify only 1 expression in the lowering (we don't want to add statements to the enclosing block), + // the expressions will be in a wrapper SequenceExpression + // --- + // At line 3 the double as expression is needed. If we simply write `gensym as `, then a + // boxing flag may be put on the `gensym` identifier node. It'll be boxed in 'line 2' instead of 'line 3', which + // cause error. If we put another as expression inside (which won't do any conversion, because the type of `gensym` + // is already ), the boxing flag will be on the as expression, instead of the identifier, so + // the identifier node won't be unboxed at 'line 2'. + + // Check if argument of update expression is tuple + auto *const argument = update->Argument(); + const bool is_argument_member_expression = argument->IsMemberExpression(); + auto *const argument_type = + is_argument_member_expression ? argument->AsMemberExpression()->Object()->TsType() : nullptr; + + if ((argument_type == nullptr) || (!argument_type->IsETSTupleType())) { + return update; + } + // -------------- + + // Set tuple type to Object (because we'll need implicit boxing) + auto *const saved_type = argument->TsType(); + argument->SetTsType(argument_type->AsETSTupleType()->ElementType()); + // -------------- + + // Compute necessary types and OpaqueTypeNodes + auto *const tuple_type_at_idx = argument_type->AsETSTupleType()->GetTypeAtIndex( + checker->GetTupleElementAccessValue(argument->AsMemberExpression()->Property()->TsType())); + + auto *const tuple_element_type_node = + checker->AllocNode(argument_type->AsETSTupleType()->ElementType()); + auto *const tuple_type_at_idx_node = checker->AllocNode(tuple_type_at_idx); + // -------------- + + // Clone argument of update expression (conversion flag might be added to it, so we need to duplicate it to not make + // conversions on 'line 3', that belongs to 'line 1' ) + auto *const member_expr = argument->AsMemberExpression(); + auto *const argument_clone = + checker->AllocNode(member_expr->Object(), member_expr->Property(), member_expr->Kind(), + member_expr->IsComputed(), member_expr->IsOptional()); + argument_clone->SetPropVar(member_expr->PropVar()); + argument_clone->SetParent(member_expr->Parent()); + argument_clone->SetTsType(member_expr->TsType()); + argument_clone->SetObjectType(member_expr->ObjType()); + // -------------- + + // Generate temporary symbols + auto *gensym = Gensym(checker->Allocator()); + auto *const tmp_var = NearestScope(update)->AddDecl( + checker->Allocator(), gensym->Name(), varbinder::VariableFlags::LOCAL); + tmp_var->SetTsType(tuple_type_at_idx); + gensym->SetVariable(tmp_var); + gensym->SetTsType(tmp_var->TsType()); + + auto *gensym_2 = Gensym(checker->Allocator()); + auto *const tmp_var_2 = NearestScope(update)->AddDecl( + checker->Allocator(), gensym_2->Name(), varbinder::VariableFlags::LOCAL); + tmp_var_2->SetTsType(tuple_type_at_idx); + gensym_2->SetVariable(tmp_var_2); + gensym_2->SetTsType(tmp_var_2->TsType()); + // -------------- + + // make node: let gensym = tuple[n] as ; + auto *const gensym_ts_as = checker->AllocNode(argument_clone, tuple_type_at_idx_node, false); + auto *const tuple_as_type = + checker->AllocNode(gensym, gensym_ts_as, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + // -------------- + + // make node: let gensym2 = (gensym)++; + auto *gensym_update = checker->AllocNode(gensym, update->OperatorType(), update->IsPrefix()); + auto *const gensym_2_assignment = checker->AllocNode( + gensym_2, gensym_update, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + // -------------- + + // make node: tuple[n] = (gensym as ) as ; + auto *gensym_as = checker->AllocNode(gensym, tuple_type_at_idx_node, false); + auto *gensym_as_tuple_type_at_idx = + checker->AllocNode(gensym_as, tuple_element_type_node, false); + auto *const tuple_assignment = checker->AllocNode( + argument, gensym_as_tuple_type_at_idx, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + // -------------- + + // make node: gensym2 as ; + auto *const final_tuple_node = checker->AllocNode(gensym_2, tuple_type_at_idx_node, false); + // -------------- + + // Construct sequence expression order + ArenaVector expression_list(checker->Allocator()->Adapter()); + expression_list.push_back(tuple_as_type); + expression_list.push_back(gensym_2_assignment); + expression_list.push_back(tuple_assignment); + expression_list.push_back(final_tuple_node); + // -------------- + + // Check the new sequence expression + auto *const sequence_expr = checker->AllocNode(std::move(expression_list)); + sequence_expr->SetParent(update->Parent()); + sequence_expr->Check(checker); + // -------------- + + // Set back TsType of argument (not necessarily needed now, but there can be a phase later, that need to get the + // right type of it) + argument->SetTsType(saved_type); + // -------------- + + return sequence_expr; +} + +static ir::AssignmentExpression *ConvertTupleAssignment(checker::ETSChecker *const checker, + ir::AssignmentExpression *const assignment) +{ + // Converts `tuple[n] = variable;` to + // `tuple[n] = ((variable as ) as )` + // This lowering is necessary to handle `an unboxing conversion followed by a widening primitive + // conversion`, eg. when `tuple[n]` has type of `int`, and assignment::right_ has type of `Short`. Because every + // type is stored as the LUB type in the tuple (which can be Object), then the following conversions need to be done + // for this case: Short->short->int->Int->Object which can't be made implicitly, hence lowering is needed + + // Check if the left side of an assignment expression is a tuple element access + auto *const left = assignment->Left(); + auto *const left_object_type = left->AsMemberExpression()->Object()->TsType(); + + if ((left_object_type == nullptr) || (!left_object_type->IsETSTupleType())) { + return assignment; + } + // -------------- + + // Set tuple type to (because we may need implicit boxing) + auto *const saved_left_type = left->TsType(); + left->SetTsType(left_object_type->AsETSTupleType()->ElementType()); + // -------------- + + // Compute necessary types and OpaqueTypeNodes + auto *const element_type_type_node = + checker->AllocNode(left_object_type->AsETSTupleType()->ElementType()); + auto *const tuple_type_at_idx_type_node = checker->AllocNode(saved_left_type); + // -------------- + + // make node: tuple[n] = ((variable as ) as ) + auto *const ts_as_expression_left = + checker->AllocNode(assignment->Right(), tuple_type_at_idx_type_node, false); + + auto *const ts_as_expression = + checker->AllocNode(ts_as_expression_left, element_type_type_node, false); + auto *const new_assignment = + checker->AllocNode(left, ts_as_expression, assignment->OperatorType()); + // -------------- + + // Check the new assignment + new_assignment->SetParent(assignment->Parent()); + new_assignment->Check(checker); + left->SetTsType(saved_left_type); + // -------------- + + return new_assignment; +} + +bool TupleLowering::Perform(CompilerContext *const ctx, parser::Program *const program) +{ + for (const auto &[_, ext_programs] : program->ExternalSources()) { + (void)_; + for (auto *const ext_prog : ext_programs) { + Perform(ctx, ext_prog); + } + } + + checker::ETSChecker *const checker = ctx->Checker()->AsETSChecker(); + + program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *const ast) -> ir::AstNode * { + // Check if node is an 'assignment expression', with a member expression on the left (potentially tuple) + if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->Left()->IsMemberExpression()) { + return ConvertTupleAssignment(checker, ast->AsAssignmentExpression()); + } + + // Check if node is an 'update expression', with a member expression as an argument (potentially tuple) + if (ast->IsUpdateExpression() && ast->AsUpdateExpression()->Argument()->IsMemberExpression()) { + return ConvertTupleUpdate(checker, ast->AsUpdateExpression()); + } + + return ast; + }); + + return true; +} + +bool TupleLowering::Postcondition(CompilerContext *const ctx, const parser::Program *const program) +{ + for (const auto &[_, ext_programs] : program->ExternalSources()) { + (void)_; + for (const auto *const ext_prog : ext_programs) { + if (!Postcondition(ctx, ext_prog)) { + return false; + } + } + } + + return !program->Ast()->IsAnyChild([](const ir::AstNode *const ast) { + const bool is_left_member_expr = + ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->Left()->IsMemberExpression(); + const bool is_left_tuple = + is_left_member_expr + ? (ast->AsAssignmentExpression()->Left()->AsMemberExpression()->TsType() != nullptr) && + ast->AsAssignmentExpression()->Left()->AsMemberExpression()->TsType()->IsETSTupleType() + : false; + // Check if there is an 'assignment expression' with a 'member expression' on it's left, which is a tuple. If + // yes, then the right hand side must be a type of the element type. + return is_left_member_expr && is_left_tuple && + (ast->AsAssignmentExpression()->Right()->TsType() == + ast->AsAssignmentExpression()->Left()->AsMemberExpression()->TsType()->AsETSTupleType()->ElementType()); + }); +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/tupleLowering.h b/ets2panda/compiler/lowering/ets/tupleLowering.h new file mode 100644 index 0000000000000000000000000000000000000000..f3110d0a526911ea9d0376fecc107b816a583d99 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/tupleLowering.h @@ -0,0 +1,32 @@ +/** + * 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. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_TUPLE_LOWERING_H +#define ES2PANDA_COMPILER_LOWERING_TUPLE_LOWERING_H + +#include "compiler/lowering/phase.h" + +namespace panda::es2panda::compiler { + +class TupleLowering : public Phase { +public: + std::string const &Name() override; + bool Perform(CompilerContext *ctx, parser::Program *program) override; + bool Postcondition(CompilerContext *ctx, const parser::Program *program) override; +}; + +} // namespace panda::es2panda::compiler + +#endif // ES2PANDA_COMPILER_LOWERING_TUPLE_LOWERING_H diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index f3b2ff83a6ee0aba42f56ab2082eb0483dc834ac..93849ccacf52a1f6a7fbe49998558fc4ca906bec 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -21,6 +21,7 @@ #include "compiler/lowering/checkerPhase.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/opAssignment.h" +#include "compiler/lowering/ets/tupleLowering.h" #include "compiler/lowering/ets/unionLowering.h" namespace panda::es2panda::compiler { @@ -36,15 +37,13 @@ std::vector GetTrivialPhaseList() static GenerateTsDeclarationsPhase GENERATE_TS_DECLARATIONS_PHASE; static OpAssignmentLowering OP_ASSIGNMENT_LOWERING; +static TupleLowering TUPLE_LOWERING; // Can be only applied after checking phase, and OP_ASSIGNMENT_LOWERING phase static UnionLowering UNION_LOWERING; std::vector GetETSPhaseList() { return std::vector { - &CHECKER_PHASE, - &GENERATE_TS_DECLARATIONS_PHASE, - &OP_ASSIGNMENT_LOWERING, - &UNION_LOWERING, + &CHECKER_PHASE, &GENERATE_TS_DECLARATIONS_PHASE, &OP_ASSIGNMENT_LOWERING, &TUPLE_LOWERING, &UNION_LOWERING, }; } diff --git a/ets2panda/ir/astNodeMapping.h b/ets2panda/ir/astNodeMapping.h index e05e9a9c2fe3cbcb6303983fc3fbe7aca42cdbb7..6a1dd0e6d39a74f712539a6f44c532983336e695 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -90,6 +90,7 @@ _(ETS_NEW_CLASS_INSTANCE_EXPRESSION, ETSNewClassInstanceExpression) \ _(ETS_IMPORT_DECLARATION, ETSImportDeclaration) \ _(ETS_PARAMETER_EXPRESSION, ETSParameterExpression) \ + _(ETS_TUPLE, ETSTuple) \ _(SUPER_EXPRESSION, SuperExpression) \ _(STRUCT_DECLARATION, ETSStructDeclaration) \ _(SWITCH_CASE_STATEMENT, SwitchCaseStatement) \ diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e289cfd474ba62bcbfa752f53d041d5f1662f6c3 --- /dev/null +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -0,0 +1,142 @@ +/** + * 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. + */ + +#include "etsTuple.h" + +#include "checker/ETSchecker.h" +#include "checker/types/ets/etsTupleType.h" +#include "ir/astDump.h" + +namespace panda::es2panda::ir { + +void ETSTuple::TransformChildren([[maybe_unused]] const NodeTransformer &cb) +{ + for (auto *&it : GetTupleTypeAnnotationsList()) { + it = static_cast(cb(it)); + } + + if (HasSpreadType()) { + cb(spread_type_); + } +} + +void ETSTuple::Iterate([[maybe_unused]] const NodeTraverser &cb) const +{ + for (auto *const it : GetTupleTypeAnnotationsList()) { + cb(it); + } + + if (HasSpreadType()) { + cb(spread_type_); + } +} + +void ETSTuple::Dump(ir::AstDumper *const dumper) const +{ + dumper->Add({{"type", "ETSTuple"}, + {"types", AstDumper::Optional(type_annotation_list_)}, + {"spreadType", AstDumper::Nullish(spread_type_)}}); +} + +void ETSTuple::Compile([[maybe_unused]] compiler::PandaGen *const pg) const {} +void ETSTuple::Compile([[maybe_unused]] compiler::ETSGen *const etsg) const {} + +checker::Type *ETSTuple::Check([[maybe_unused]] checker::TSChecker *const checker) +{ + return nullptr; +} + +checker::Type *ETSTuple::Check([[maybe_unused]] checker::ETSChecker *const checker) +{ + return GetType(checker); +} + +checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker, + ArenaVector &type_list, checker::Type *const spread_type) +{ + if (type_list.empty()) { + return spread_type == nullptr ? checker->GlobalETSObjectType() : spread_type; + } + + bool all_elements_are_same = std::all_of(type_list.begin(), type_list.end(), [&checker, &type_list](auto *element) { + return checker->Relation()->IsIdenticalTo(type_list[0], element); + }); + + if (spread_type != nullptr) { + all_elements_are_same = all_elements_are_same && checker->Relation()->IsIdenticalTo(type_list[0], spread_type); + } + + // If only one type present in the tuple, that will be the holder array type. If any two not identical types + // present, primitives will be boxed, and LUB is calculated for all of them. + // That makes it possible to assign eg. `[int, int, ...int[]]` tuple type to `int[]` array type. Because a `short[]` + // array already isn't assignable to `int[]` array, that preserve that the `[int, short, ...int[]]` tuple type's + // element type will be calculated to `Object[]`, which is not assignable to `int[]` array either. + if (all_elements_are_same) { + return type_list[0]; + } + + auto *const saved_relation_node = checker->Relation()->GetNode(); + checker->Relation()->SetNode(this); + + auto get_boxed_type_or_type = [&checker](checker::Type *const type) { + auto *const boxed_type = checker->PrimitiveTypeAsETSBuiltinType(type); + return boxed_type == nullptr ? type : boxed_type; + }; + + checker::Type *lub_type = get_boxed_type_or_type(type_list[0]); + + for (std::size_t idx = 1; idx < type_list.size(); ++idx) { + lub_type = checker->FindLeastUpperBound(lub_type, get_boxed_type_or_type(type_list[idx])); + } + + if (spread_type != nullptr) { + lub_type = checker->FindLeastUpperBound(lub_type, get_boxed_type_or_type(spread_type)); + } + + checker->Relation()->SetNode(saved_relation_node); + + return lub_type; +} + +checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) +{ + if (TsType() != nullptr) { + return TsType(); + } + + ArenaVector type_list(checker->Allocator()->Adapter()); + + for (auto *const type_annotation : GetTupleTypeAnnotationsList()) { + auto *const checked_type = checker->GetTypeFromTypeAnnotation(type_annotation); + type_list.emplace_back(checked_type); + } + + if (HasSpreadType()) { + ASSERT(spread_type_->IsTSArrayType()); + auto *const array_type = spread_type_->GetType(checker); + ASSERT(array_type->IsETSArrayType()); + spread_type_->SetTsType(array_type->AsETSArrayType()->ElementType()); + } + + auto *const spread_element_type = spread_type_ != nullptr ? spread_type_->TsType() : nullptr; + + auto *const tuple_type = checker->Allocator()->New( + type_list, CalculateLUBForTuple(checker, type_list, spread_element_type), spread_element_type); + + SetTsType(tuple_type); + return TsType(); +} + +} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsTuple.h b/ets2panda/ir/ets/etsTuple.h new file mode 100644 index 0000000000000000000000000000000000000000..5b4b28ddfe9d4b2ac19c2305015a1d23edf022c8 --- /dev/null +++ b/ets2panda/ir/ets/etsTuple.h @@ -0,0 +1,88 @@ +/** + * 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. + */ + +#ifndef ES2PANDA_IR_ETS_TUPLE_H +#define ES2PANDA_IR_ETS_TUPLE_H + +#include "ir/typeNode.h" + +namespace panda::es2panda::ir { + +class ETSTuple : public TypeNode { +public: + using TupleSizeType = uint32_t; + + explicit ETSTuple(ArenaAllocator *const allocator) + : TypeNode(AstNodeType::ETS_TUPLE), type_annotation_list_(allocator->Adapter()) + { + } + + explicit ETSTuple(ArenaAllocator *const allocator, const TupleSizeType size) + : TypeNode(AstNodeType::ETS_TUPLE), type_annotation_list_(allocator->Adapter()), size_(size) + { + } + explicit ETSTuple(const ArenaVector &type_list) + : TypeNode(AstNodeType::ETS_TUPLE), + type_annotation_list_(type_list), + size_(static_cast(type_list.size())) + { + } + + [[nodiscard]] TupleSizeType GetTupleSize() const + { + return size_; + } + + [[nodiscard]] ArenaVector GetTupleTypeAnnotationsList() const + { + return type_annotation_list_; + } + + [[nodiscard]] bool HasSpreadType() const + { + return spread_type_ != nullptr; + } + + void SetSpreadType(TypeNode *const new_spread_type) + { + spread_type_ = new_spread_type; + } + + void SetTypeAnnotationsList(const ArenaVector &type_node_list) + { + type_annotation_list_ = type_node_list; + } + + void TransformChildren(const NodeTransformer &cb) override; + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; + + checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector &type_list, + checker::Type *spread_type); + +private: + ArenaVector type_annotation_list_; + TypeNode *spread_type_ {}; + TupleSizeType size_ {0}; +}; + +} // namespace panda::es2panda::ir + +#endif /* ES2PANDA_IR_ETS_TUPLE_H */ diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index 6b46553a1db6a6056dc7b3861fd1441f719e0535..649d191b40ab5cec5c5c5a61003856dc17edfe80 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -15,21 +15,21 @@ #include "arrayExpression.h" -#include "ir/base/decorator.h" -#include "util/helpers.h" -#include "checker/TSchecker.h" #include "checker/ETSchecker.h" +#include "checker/TSchecker.h" +#include "checker/ets/castingContext.h" #include "checker/ets/typeRelationContext.h" #include "checker/ts/destructuringContext.h" -#include "compiler/base/literals.h" -#include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" #include "ir/astDump.h" -#include "ir/typeNode.h" +#include "ir/base/decorator.h" #include "ir/base/spreadElement.h" -#include "ir/expressions/identifier.h" #include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/identifier.h" #include "ir/expressions/objectExpression.h" +#include "ir/typeNode.h" +#include "util/helpers.h" namespace panda::es2panda::ir { ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression const &other, @@ -239,7 +239,12 @@ void ArrayExpression::Compile(compiler::ETSGen *const etsg) const etsg->ApplyConversion(expr, nullptr); etsg->ApplyConversion(expr); - etsg->StoreArrayElement(this, arr, index_reg, TsType()->AsETSArrayType()->ElementType()); + + if (expr->TsType()->IsETSArrayType()) { + etsg->StoreArrayElement(this, arr, index_reg, expr->TsType()); + } else { + etsg->StoreArrayElement(this, arr, index_reg, TsType()->AsETSArrayType()->ElementType()); + } } etsg->LoadAccumulator(this, arr); @@ -479,30 +484,97 @@ checker::Type *ArrayExpression::CheckPattern(checker::TSChecker *checker) false); } +void ArrayExpression::HandleNestedArrayExpression(checker::ETSChecker *const checker, + ArrayExpression *const current_element, const bool is_array, + const bool is_preferred_tuple, const std::size_t idx) +{ + if (is_preferred_tuple) { + current_element->SetPreferredType(is_array ? preferred_type_ + : preferred_type_->AsETSTupleType()->GetTypeAtIndex(idx)); + + if (current_element->GetPreferredType()->IsETSTupleType()) { + checker->ValidateTupleMinElementSize(current_element, + current_element->GetPreferredType()->AsETSTupleType()); + } + + return; + } + + if (preferred_type_->IsETSArrayType()) { + if (preferred_type_->AsETSArrayType()->ElementType()->IsETSTupleType()) { + checker->ValidateTupleMinElementSize(current_element, + preferred_type_->AsETSArrayType()->ElementType()->AsETSTupleType()); + } + + current_element->SetPreferredType(is_array ? preferred_type_ + : preferred_type_->AsETSArrayType()->ElementType()); + return; + } + + if (current_element->GetPreferredType() == nullptr) { + current_element->SetPreferredType(preferred_type_); + } +} + checker::Type *ArrayExpression::Check(checker::ETSChecker *checker) { if (TsType() != nullptr) { return TsType(); } + const bool is_array = + (preferred_type_ != nullptr) && preferred_type_->IsETSArrayType() && !preferred_type_->IsETSTupleType(); + + if (is_array) { + preferred_type_ = preferred_type_->AsETSArrayType()->ElementType(); + } + if (!elements_.empty()) { if (preferred_type_ == nullptr) { preferred_type_ = elements_[0]->Check(checker); } - for (auto *element : elements_) { - if (element->IsArrayExpression() && preferred_type_->IsETSArrayType()) { - element->AsArrayExpression()->SetPreferredType(preferred_type_->AsETSArrayType()->ElementType()); + const bool is_preferred_tuple = preferred_type_->IsETSTupleType(); + auto *const target_element_type = + is_preferred_tuple && !is_array ? preferred_type_->AsETSTupleType()->ElementType() : preferred_type_; + + for (std::size_t idx = 0; idx < elements_.size(); ++idx) { + auto *const current_element = elements_[idx]; + + if (current_element->IsArrayExpression()) { + HandleNestedArrayExpression(checker, current_element->AsArrayExpression(), is_array, is_preferred_tuple, + idx); } - if (element->IsObjectExpression()) { - element->AsObjectExpression()->SetPreferredType(preferred_type_); + + if (current_element->IsObjectExpression()) { + current_element->AsObjectExpression()->SetPreferredType(preferred_type_); } - checker::Type *element_type = element->Check(checker); - checker::AssignmentContext(checker->Relation(), element, element_type, preferred_type_, element->Start(), + checker::Type *element_type = current_element->Check(checker); + + if (!element_type->IsETSArrayType() && is_preferred_tuple) { + auto *const compare_type = preferred_type_->AsETSTupleType()->GetTypeAtIndex(idx); + + if (compare_type == nullptr) { + checker->ThrowTypeError({"Too many elements in array initializer for tuple with size of ", + static_cast(preferred_type_->AsETSTupleType()->GetTupleSize())}, + current_element->Start()); + } + + const checker::CastingContext cast( + checker->Relation(), current_element, element_type, compare_type, current_element->Start(), + {"Array initializer's type is not assignable to tuple type at index: ", idx}); + + element_type = compare_type; + } + + checker::AssignmentContext(checker->Relation(), current_element, element_type, target_element_type, + current_element->Start(), {"Array element type '", element_type, "' is not assignable to explicit type '", GetPreferredType(), "'"}); } + + SetPreferredType(target_element_type); } if (preferred_type_ == nullptr) { @@ -510,7 +582,7 @@ checker::Type *ArrayExpression::Check(checker::ETSChecker *checker) } SetTsType(checker->CreateETSArrayType(preferred_type_)); - auto array_type = TsType()->AsETSArrayType(); + auto *const array_type = TsType()->AsETSArrayType(); checker->CreateBuiltinArraySignature(array_type, array_type->Rank()); return TsType(); } diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index bbe3c830fd3821c261f45761942007d95714d70e..51e6e2c84b7b4feb89c6cbebcbcb72428760ea50 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -112,6 +112,8 @@ public: checker::Type *Check(checker::TSChecker *checker) override; checker::Type *Check(checker::ETSChecker *checker) override; checker::Type *CheckPattern(checker::TSChecker *checker); + void HandleNestedArrayExpression(checker::ETSChecker *checker, ArrayExpression *current_element, bool is_array, + bool is_preferred_tuple, std::size_t idx); private: ArenaVector decorators_; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index 4c3d14510fcfa13de7075c78b778596fc9d5fa17..f2f88644a8aed04199bda5ceb0845cd4e2bdb6aa 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -284,8 +284,9 @@ checker::Type *AssignmentExpression::Check([[maybe_unused]] checker::ETSChecker } case lexer::TokenType::PUNCTUATOR_SUBSTITUTION: { if (left_type->IsETSArrayType() && right_->IsArrayExpression()) { - right_->AsArrayExpression()->SetPreferredType(left_type->AsETSArrayType()->ElementType()); + checker->ModifyPreferredType(right_->AsArrayExpression(), left_type); } + if (right_->IsObjectExpression()) { right_->AsObjectExpression()->SetPreferredType(left_type); } diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index eda32a4f54bc8b03bc90d84116794cfc99a46cad..dbebdcd9af0ef4ba78fc580c197185a12cc68a85 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -15,9 +15,10 @@ #include "memberExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" +#include "checker/ets/castingContext.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { MemberExpression::MemberExpression([[maybe_unused]] Tag const tag, MemberExpression const &other, @@ -135,6 +136,12 @@ bool MemberExpression::CompileComputed(compiler::ETSGen *etsg) const } else { etsg->LoadArrayElement(this, obj_reg); } + + if (object_->TsType()->IsETSTupleType() && (GetTupleConvertedType() != nullptr)) { + etsg->EmitCheckedNarrowingReferenceConversion(this, GetTupleConvertedType()); + } + + etsg->ApplyConversion(this); }; etsg->EmitMaybeOptional(this, load_element, IsOptional()); @@ -398,8 +405,13 @@ checker::Type *MemberExpression::CheckComputed(checker::ETSChecker *checker, che if (!base_type->IsETSArrayType() && !base_type->IsETSDynamicType()) { checker->ThrowTypeError("Indexed access expression can only be used in array type.", Object()->Start()); } + checker->ValidateArrayIndex(Property()); + if (base_type->IsETSTupleType()) { + checker->ValidateTupleIndex(base_type->AsETSTupleType(), this); + } + if (Property()->IsIdentifier()) { SetPropVar(Property()->AsIdentifier()->Variable()->AsLocalVariable()); } else if (auto var = Property()->Variable(); (var != nullptr) && var->IsLocalVariable()) { @@ -408,7 +420,38 @@ checker::Type *MemberExpression::CheckComputed(checker::ETSChecker *checker, che // NOTE: apply capture conversion on this type if (base_type->IsETSArrayType()) { - return base_type->AsETSArrayType()->ElementType(); + if (!base_type->IsETSTupleType()) { + return base_type->AsETSArrayType()->ElementType(); + } + + auto *const tuple_type_at_idx = + base_type->AsETSTupleType()->GetTypeAtIndex(checker->GetTupleElementAccessValue(Property()->TsType())); + + if ((!Parent()->IsAssignmentExpression() || Parent()->AsAssignmentExpression()->Left() != this) && + (!Parent()->IsUpdateExpression())) { + // Error never should be thrown by this call, because LUB of types can be converted to any type which LUB + // was calculated by casting + const checker::CastingContext cast(checker->Relation(), this, base_type->AsETSArrayType()->ElementType(), + tuple_type_at_idx, Start(), {"Tuple type couldn't be converted "}); + + // TODO(mmartin): this can be replaced with the general type mapper, once implemented + if ((GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U) { + auto *const saved_node = checker->Relation()->GetNode(); + if (saved_node == nullptr) { + checker->Relation()->SetNode(this); + } + + SetTupleConvertedType(checker->PrimitiveTypeAsETSBuiltinType(tuple_type_at_idx)); + + checker->Relation()->SetNode(saved_node); + } + + if (tuple_type_at_idx->IsETSObjectType() && base_type->AsETSArrayType()->ElementType()->IsETSObjectType()) { + SetTupleConvertedType(tuple_type_at_idx); + } + } + + return tuple_type_at_idx; } // Dynamic diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 7b638ddffec515f5712ffac6680ccb603c5378b0..c2be88f833cb2bce5bb716cf4437914c70be4099 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -139,6 +139,16 @@ public: ignore_box_ = true; } + checker::Type *GetTupleConvertedType() const noexcept + { + return tuple_converted_type_; + } + + void SetTupleConvertedType(checker::Type *conv_type) noexcept + { + tuple_converted_type_ = conv_type; + } + [[nodiscard]] bool IsPrivateReference() const noexcept; // NOLINTNEXTLINE(google-default-arguments) @@ -183,6 +193,7 @@ private: bool ignore_box_ {false}; varbinder::LocalVariable *prop_var_ {}; checker::ETSObjectType *obj_type_ {}; + checker::Type *tuple_converted_type_ {}; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index ae49e98ae65b35975ade9f7f3a03571012e813f3..a69523073b689f8422cacf5624250e329e1f8740 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -24,6 +24,7 @@ #include "checker/ETSchecker.h" #include "ir/astDump.h" #include "ir/expressions/unaryExpression.h" +#include "ir/ts/tsAsExpression.h" #include "ir/expressions/identifier.h" #include "ir/expressions/memberExpression.h" @@ -126,6 +127,10 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) checker::Type *operand_type = argument_->Check(checker); if (argument_->IsIdentifier()) { checker->ValidateUnaryOperatorOperand(argument_->AsIdentifier()->Variable()); + } else if (argument_->IsTSAsExpression()) { + if (auto *const as_expr_var = argument_->AsTSAsExpression()->Variable(); as_expr_var != nullptr) { + checker->ValidateUnaryOperatorOperand(as_expr_var); + } } else { ASSERT(argument_->IsMemberExpression()); varbinder::LocalVariable *prop_var = argument_->AsMemberExpression()->PropVar(); diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 494fbaf2981e13e3c443338068176a4fb929d465..9ceba3011ef30792ea45b8bd54e41e61def4a47a 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -43,6 +43,11 @@ public: return operator_; } + [[nodiscard]] Expression *Argument() noexcept + { + return argument_; + } + [[nodiscard]] const Expression *Argument() const noexcept { return argument_; diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 1100af3be59744c72fa13015407b4cf5ab5d647c..db563ffe073858a81e6bcda57caad26ba8cec64c 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -88,6 +88,7 @@ #include "ir/ets/etsPackageDeclaration.h" #include "ir/ets/etsWildcardType.h" #include "ir/ets/etsNewArrayInstanceExpression.h" +#include "ir/ets/etsTuple.h" #include "ir/ets/etsFunctionType.h" #include "ir/ets/etsNewClassInstanceExpression.h" #include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" @@ -2635,6 +2636,77 @@ ir::TypeNode *ETSParser::ParseFunctionType() return func_type; } +ir::TypeNode *ETSParser::ParseETSTupleType(TypeAnnotationParsingOptions *const options) +{ + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET); + + const auto start_loc = Lexer()->GetToken().Start(); + Lexer()->NextToken(); // eat '[' + + ArenaVector tuple_type_list(Allocator()->Adapter()); + auto *const tuple_type = AllocNode(Allocator()); + + bool spread_type_present = false; + + while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { + // Parse named parameter if name presents + if ((Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT) && + (Lexer()->Lookahead() == lexer::LEX_CHAR_COLON)) { + ExpectIdentifier(); + Lexer()->NextToken(); // eat ':' + } + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD_PERIOD_PERIOD) { + if (spread_type_present) { + ThrowSyntaxError("Only one spread type declaration allowed, at the last index"); + } + + spread_type_present = true; + Lexer()->NextToken(); // eat '...' + } else if (spread_type_present) { + // This can't be implemented to any index, with type consistency. If a spread type is in the middle of the + // tuple, then bounds check can't be made for element access, so the type of elements after the spread can't + // be determined in compile time. + ThrowSyntaxError("Spread type must be at the last index in the tuple type"); + } + + auto *const current_type_annotation = ParseTypeAnnotation(options); + current_type_annotation->SetParent(tuple_type); + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { + // TODO(mmartin): implement optional types for tuples + ThrowSyntaxError("Optional types in tuples are not yet implemented."); + } + + if (spread_type_present) { + if (!current_type_annotation->IsTSArrayType()) { + ThrowSyntaxError("Spread type must be an array type"); + } + + tuple_type->SetSpreadType(current_type_annotation); + } else { + tuple_type_list.push_back(current_type_annotation); + } + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { + Lexer()->NextToken(); // eat comma + continue; + } + + if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET) { + ThrowSyntaxError("Comma is mandatory between elements in a tuple type declaration"); + } + } + + Lexer()->NextToken(); // eat ']' + + tuple_type->SetTypeAnnotationsList(tuple_type_list); + const auto end_loc = Lexer()->GetToken().End(); + tuple_type->SetRange({start_loc, end_loc}); + + return tuple_type; +} + // Just to reduce the size of ParseTypeAnnotation(...) method std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnotationParsingOptions *options) { @@ -2720,6 +2792,10 @@ std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnota type_annotation = ParseTypeFormatPlaceholder(); break; } + case lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET: { + type_annotation = ParseETSTupleType(options); + break; + } default: { break; } diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index d1eb419aa82dbb2f77527a06167cf6a8af77ef07..49c4825bd77a5f1785876a5e0f98595eba380988 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -164,6 +164,7 @@ private: ir::TSIntersectionType *ParseIntersectionType(ir::Expression *type); ir::TypeNode *ParseWildcardType(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseFunctionType(); + ir::TypeNode *ParseETSTupleType(TypeAnnotationParsingOptions *options); void CreateClassFunctionDeclaration(ir::MethodDefinition *method); bool HasDefaultParam(const ir::ScriptFunction *function); std::string CreateProxyMethodName(const ir::ScriptFunction *function, ir::MethodDefinition *method, diff --git a/ets2panda/test/compiler/ets/tuple_types_1-expected.txt b/ets2panda/test/compiler/ets/tuple_types_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1fa7dad85ccf7b373d40cfabfe8231e8d165d1e1 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_1-expected.txt @@ -0,0 +1,7466 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + { + "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": 20 + }, + "end": { + "line": 16, + "column": 20 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 20 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 17, + "column": 27 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + { + "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": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "num_str_str_type", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 6 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 26 + }, + "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 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 42 + }, + "end": { + "line": 19, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 42 + }, + "end": { + "line": 19, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 42 + }, + "end": { + "line": 19, + "column": 49 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "num_str_str_with_spread", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "num_str_str_type", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 50 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 54 + }, + "end": { + "line": 20, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 54 + }, + "end": { + "line": 20, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 54 + }, + "end": { + "line": 20, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 62 + }, + "end": { + "line": 20, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 64 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 64 + } + } + }, + { + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 22, + "column": 25 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "args", + "typeAnnotation": { + "type": "ETSTuple", + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 36 + }, + "end": { + "line": 22, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 36 + }, + "end": { + "line": 22, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 36 + }, + "end": { + "line": 22, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 44 + }, + "end": { + "line": 22, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 46 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 48 + }, + "end": { + "line": 22, + "column": 56 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 23, + "column": 12 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 55 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 13 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 18 + }, + "end": { + "line": 27, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tup_arr_1", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "num_str_str_type", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 41 + }, + "end": { + "line": 28, + "column": 42 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 11 + }, + "end": { + "line": 28, + "column": 20 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 11 + } + } + }, + { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 29, + "column": 16 + } + } + }, + { + "type": "StringLiteral", + "value": "d", + "loc": { + "start": { + "line": 29, + "column": 18 + }, + "end": { + "line": 29, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 22 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 11 + } + } + }, + { + "type": "StringLiteral", + "value": "b", + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 30, + "column": 16 + } + } + }, + { + "type": "StringLiteral", + "value": "e", + "loc": { + "start": { + "line": 30, + "column": 18 + }, + "end": { + "line": 30, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 22 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 11 + } + } + }, + { + "type": "StringLiteral", + "value": "c", + "loc": { + "start": { + "line": 31, + "column": 13 + }, + "end": { + "line": 31, + "column": 16 + } + } + }, + { + "type": "StringLiteral", + "value": "f", + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 43 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 11 + }, + "end": { + "line": 32, + "column": 6 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 32, + "column": 7 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tup_arr_2", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "num_str_str_with_spread", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 22 + }, + "end": { + "line": 34, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 22 + }, + "end": { + "line": 34, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 22 + }, + "end": { + "line": 34, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 48 + }, + "end": { + "line": 34, + "column": 49 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 11 + }, + "end": { + "line": 34, + "column": 20 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_1", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 10 + }, + "end": { + "line": 35, + "column": 19 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 35, + "column": 20 + }, + "end": { + "line": 35, + "column": 21 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 35, + "column": 10 + }, + "end": { + "line": 35, + "column": 22 + } + } + }, + { + "type": "NumberLiteral", + "value": 250, + "loc": { + "start": { + "line": 35, + "column": 24 + }, + "end": { + "line": 35, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 28 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_1", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 10 + }, + "end": { + "line": 36, + "column": 19 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 36, + "column": 20 + }, + "end": { + "line": 36, + "column": 21 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 36, + "column": 10 + }, + "end": { + "line": 36, + "column": 22 + } + } + }, + { + "type": "NumberLiteral", + "value": 250, + "loc": { + "start": { + "line": 36, + "column": 24 + }, + "end": { + "line": 36, + "column": 27 + } + } + }, + { + "type": "NumberLiteral", + "value": 260, + "loc": { + "start": { + "line": 36, + "column": 29 + }, + "end": { + "line": 36, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 33 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_1", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 19 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 37, + "column": 20 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + { + "type": "NumberLiteral", + "value": 300, + "loc": { + "start": { + "line": 37, + "column": 24 + }, + "end": { + "line": 37, + "column": 27 + } + } + }, + { + "type": "NumberLiteral", + "value": 300, + "loc": { + "start": { + "line": 37, + "column": 29 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + { + "type": "NumberLiteral", + "value": 300, + "loc": { + "start": { + "line": 37, + "column": 34 + }, + "end": { + "line": 37, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 34, + "column": 50 + }, + "end": { + "line": 38, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 11 + }, + "end": { + "line": 38, + "column": 6 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 38, + "column": 7 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a_var", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 11 + }, + "end": { + "line": 40, + "column": 16 + } + } + }, + "init": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 19 + }, + "end": { + "line": 40, + "column": 28 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 40, + "column": 29 + }, + "end": { + "line": 40, + "column": 30 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 19 + }, + "end": { + "line": 40, + "column": 31 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 40, + "column": 32 + }, + "end": { + "line": 40, + "column": 33 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 19 + }, + "end": { + "line": 40, + "column": 34 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 37 + }, + "end": { + "line": 40, + "column": 46 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 40, + "column": 47 + }, + "end": { + "line": 40, + "column": 48 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 37 + }, + "end": { + "line": 40, + "column": 49 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 40, + "column": 50 + }, + "end": { + "line": 40, + "column": 51 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 37 + }, + "end": { + "line": 40, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 19 + }, + "end": { + "line": 40, + "column": 52 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 55 + }, + "end": { + "line": 40, + "column": 64 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 40, + "column": 65 + }, + "end": { + "line": 40, + "column": 66 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 55 + }, + "end": { + "line": 40, + "column": 67 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 40, + "column": 68 + }, + "end": { + "line": 40, + "column": 69 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 55 + }, + "end": { + "line": 40, + "column": 70 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 19 + }, + "end": { + "line": 40, + "column": 70 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 11 + }, + "end": { + "line": 40, + "column": 70 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 40, + "column": 71 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b_var", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 11 + }, + "end": { + "line": 41, + "column": 16 + } + } + }, + "init": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 19 + }, + "end": { + "line": 41, + "column": 28 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 41, + "column": 29 + }, + "end": { + "line": 41, + "column": 30 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 41, + "column": 19 + }, + "end": { + "line": 41, + "column": 31 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 41, + "column": 32 + }, + "end": { + "line": 41, + "column": 33 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 41, + "column": 19 + }, + "end": { + "line": 41, + "column": 34 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 37 + }, + "end": { + "line": 41, + "column": 46 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 41, + "column": 47 + }, + "end": { + "line": 41, + "column": 48 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 41, + "column": 37 + }, + "end": { + "line": 41, + "column": 49 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 41, + "column": 50 + }, + "end": { + "line": 41, + "column": 51 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 41, + "column": 37 + }, + "end": { + "line": 41, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 19 + }, + "end": { + "line": 41, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 11 + }, + "end": { + "line": 41, + "column": 52 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 53 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c_var", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 11 + }, + "end": { + "line": 42, + "column": 16 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 19 + }, + "end": { + "line": 42, + "column": 28 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 42, + "column": 29 + }, + "end": { + "line": 42, + "column": 30 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 42, + "column": 19 + }, + "end": { + "line": 42, + "column": 31 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 42, + "column": 32 + }, + "end": { + "line": 42, + "column": 33 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 42, + "column": 19 + }, + "end": { + "line": 42, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 11 + }, + "end": { + "line": 42, + "column": 34 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 35 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_1", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 9 + }, + "end": { + "line": 44, + "column": 18 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 44, + "column": 19 + }, + "end": { + "line": 44, + "column": 20 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 9 + }, + "end": { + "line": 44, + "column": 21 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 44, + "column": 22 + }, + "end": { + "line": 44, + "column": 23 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 9 + }, + "end": { + "line": 44, + "column": 24 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 44, + "column": 27 + }, + "end": { + "line": 44, + "column": 36 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 44, + "column": 37 + }, + "end": { + "line": 44, + "column": 38 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 27 + }, + "end": { + "line": 44, + "column": 39 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 44, + "column": 40 + }, + "end": { + "line": 44, + "column": 41 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 27 + }, + "end": { + "line": 44, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 44, + "column": 26 + }, + "end": { + "line": 44, + "column": 43 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 44, + "column": 5 + }, + "end": { + "line": 44, + "column": 45 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 45, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_1", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 9 + }, + "end": { + "line": 45, + "column": 18 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 45, + "column": 19 + }, + "end": { + "line": 45, + "column": 20 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 9 + }, + "end": { + "line": 45, + "column": 21 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 45, + "column": 22 + }, + "end": { + "line": 45, + "column": 23 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 9 + }, + "end": { + "line": 45, + "column": 24 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 27 + }, + "end": { + "line": 45, + "column": 36 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 45, + "column": 37 + }, + "end": { + "line": 45, + "column": 38 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 27 + }, + "end": { + "line": 45, + "column": 39 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 45, + "column": 40 + }, + "end": { + "line": 45, + "column": 41 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 27 + }, + "end": { + "line": 45, + "column": 42 + } + } + }, + { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "tup_arr_2", + "decorators": [], + "loc": { + "start": { + "line": 45, + "column": 44 + }, + "end": { + "line": 45, + "column": 53 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 45, + "column": 54 + }, + "end": { + "line": 45, + "column": 55 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 44 + }, + "end": { + "line": 45, + "column": 56 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 45, + "column": 57 + }, + "end": { + "line": 45, + "column": 58 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 44 + }, + "end": { + "line": 45, + "column": 59 + } + } + } + ], + "loc": { + "start": { + "line": 45, + "column": 26 + }, + "end": { + "line": 45, + "column": 60 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 45, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 45, + "column": 5 + }, + "end": { + "line": 45, + "column": 62 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "arr", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 47, + "column": 14 + }, + "end": { + "line": 47, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 14 + }, + "end": { + "line": 47, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 14 + }, + "end": { + "line": 47, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 23 + }, + "end": { + "line": 47, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 47, + "column": 9 + }, + "end": { + "line": 47, + "column": 12 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 47, + "column": 26 + }, + "end": { + "line": 47, + "column": 27 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 47, + "column": 28 + }, + "end": { + "line": 47, + "column": 29 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 47, + "column": 30 + }, + "end": { + "line": 47, + "column": 31 + } + } + }, + { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 47, + "column": 32 + }, + "end": { + "line": 47, + "column": 33 + } + } + }, + { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 47, + "column": 34 + }, + "end": { + "line": 47, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 47, + "column": 25 + }, + "end": { + "line": 47, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 47, + "column": 9 + }, + "end": { + "line": 47, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 47, + "column": 5 + }, + "end": { + "line": 47, + "column": 37 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "double_ref_tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 26 + }, + "end": { + "line": 48, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 26 + }, + "end": { + "line": 48, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 26 + }, + "end": { + "line": 48, + "column": 33 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 34 + }, + "end": { + "line": 48, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 34 + }, + "end": { + "line": 48, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 34 + }, + "end": { + "line": 48, + "column": 41 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 42 + }, + "end": { + "line": 48, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 42 + }, + "end": { + "line": 48, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 42 + }, + "end": { + "line": 48, + "column": 49 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 48, + "column": 25 + }, + "end": { + "line": 48, + "column": 51 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 9 + }, + "end": { + "line": 48, + "column": 23 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 6, + "loc": { + "start": { + "line": 48, + "column": 53 + }, + "end": { + "line": 48, + "column": 54 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 48, + "column": 58 + }, + "end": { + "line": 48, + "column": 64 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 53 + }, + "end": { + "line": 48, + "column": 54 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 7, + "loc": { + "start": { + "line": 48, + "column": 66 + }, + "end": { + "line": 48, + "column": 67 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 48, + "column": 71 + }, + "end": { + "line": 48, + "column": 77 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 66 + }, + "end": { + "line": 48, + "column": 67 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 8, + "loc": { + "start": { + "line": 48, + "column": 79 + }, + "end": { + "line": 48, + "column": 80 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 48, + "column": 84 + }, + "end": { + "line": 48, + "column": 90 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 79 + }, + "end": { + "line": 48, + "column": 80 + } + } + } + ], + "loc": { + "start": { + "line": 48, + "column": 52 + }, + "end": { + "line": 48, + "column": 91 + } + } + }, + "loc": { + "start": { + "line": 48, + "column": 9 + }, + "end": { + "line": 48, + "column": 91 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 48, + "column": 5 + }, + "end": { + "line": 48, + "column": 92 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a_arr", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 49, + "column": 16 + }, + "end": { + "line": 49, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 16 + }, + "end": { + "line": 49, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 16 + }, + "end": { + "line": 49, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 49, + "column": 19 + }, + "end": { + "line": 49, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 49, + "column": 9 + }, + "end": { + "line": 49, + "column": 14 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 49, + "column": 9 + }, + "end": { + "line": 49, + "column": 14 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 49, + "column": 5 + }, + "end": { + "line": 49, + "column": 20 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b_tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 50, + "column": 17 + }, + "end": { + "line": 50, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 17 + }, + "end": { + "line": 50, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 17 + }, + "end": { + "line": 50, + "column": 19 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 50, + "column": 20 + }, + "end": { + "line": 50, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 20 + }, + "end": { + "line": 50, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 20 + }, + "end": { + "line": 50, + "column": 22 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 50, + "column": 16 + }, + "end": { + "line": 50, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 50, + "column": 9 + }, + "end": { + "line": 50, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 50, + "column": 30 + }, + "end": { + "line": 50, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 30 + }, + "end": { + "line": 50, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 30 + }, + "end": { + "line": 50, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 50, + "column": 26 + }, + "end": { + "line": 50, + "column": 34 + } + } + }, + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 50, + "column": 39 + }, + "end": { + "line": 50, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 39 + }, + "end": { + "line": 50, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 39 + }, + "end": { + "line": 50, + "column": 41 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 50, + "column": 35 + }, + "end": { + "line": 50, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 50, + "column": 25 + }, + "end": { + "line": 50, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 50, + "column": 9 + }, + "end": { + "line": 50, + "column": 43 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 50, + "column": 5 + }, + "end": { + "line": 50, + "column": 44 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b_arr", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 16 + }, + "end": { + "line": 51, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 16 + }, + "end": { + "line": 51, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 16 + }, + "end": { + "line": 51, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 20 + }, + "end": { + "line": 51, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 9 + }, + "end": { + "line": 51, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 27 + }, + "end": { + "line": 51, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 27 + }, + "end": { + "line": 51, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 27 + }, + "end": { + "line": 51, + "column": 29 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 51, + "column": 23 + }, + "end": { + "line": 51, + "column": 31 + } + } + }, + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 36 + }, + "end": { + "line": 51, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 36 + }, + "end": { + "line": 51, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 36 + }, + "end": { + "line": 51, + "column": 38 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 51, + "column": 32 + }, + "end": { + "line": 51, + "column": 40 + } + } + } + ], + "loc": { + "start": { + "line": 51, + "column": 22 + }, + "end": { + "line": 51, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 51, + "column": 9 + }, + "end": { + "line": 51, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 51, + "column": 5 + }, + "end": { + "line": 51, + "column": 41 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "arr", + "decorators": [], + "loc": { + "start": { + "line": 53, + "column": 5 + }, + "end": { + "line": 53, + "column": 8 + } + } + }, + "right": { + "type": "Identifier", + "name": "double_ref_tup", + "decorators": [], + "loc": { + "start": { + "line": 53, + "column": 11 + }, + "end": { + "line": 53, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 53, + "column": 5 + }, + "end": { + "line": 53, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 53, + "column": 5 + }, + "end": { + "line": 53, + "column": 26 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "a_arr", + "decorators": [], + "loc": { + "start": { + "line": 54, + "column": 5 + }, + "end": { + "line": 54, + "column": 10 + } + } + }, + "right": { + "type": "Identifier", + "name": "b_tup", + "decorators": [], + "loc": { + "start": { + "line": 54, + "column": 13 + }, + "end": { + "line": 54, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 54, + "column": 5 + }, + "end": { + "line": 54, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 54, + "column": 5 + }, + "end": { + "line": 54, + "column": 19 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b_arr", + "decorators": [], + "loc": { + "start": { + "line": 55, + "column": 5 + }, + "end": { + "line": 55, + "column": 10 + } + } + }, + "right": { + "type": "Identifier", + "name": "b_tup", + "decorators": [], + "loc": { + "start": { + "line": 55, + "column": 13 + }, + "end": { + "line": 55, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 5 + }, + "end": { + "line": 55, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 55, + "column": 5 + }, + "end": { + "line": 55, + "column": 19 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "spread_tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 57, + "column": 22 + }, + "end": { + "line": 57, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 22 + }, + "end": { + "line": 57, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 22 + }, + "end": { + "line": 57, + "column": 29 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 57, + "column": 33 + }, + "end": { + "line": 57, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 33 + }, + "end": { + "line": 57, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 33 + }, + "end": { + "line": 57, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 41 + }, + "end": { + "line": 57, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 21 + }, + "end": { + "line": 57, + "column": 44 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 57, + "column": 9 + }, + "end": { + "line": 57, + "column": 19 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 6, + "loc": { + "start": { + "line": 57, + "column": 46 + }, + "end": { + "line": 57, + "column": 47 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 57, + "column": 51 + }, + "end": { + "line": 57, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 46 + }, + "end": { + "line": 57, + "column": 47 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 7, + "loc": { + "start": { + "line": 57, + "column": 58 + }, + "end": { + "line": 57, + "column": 59 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 57, + "column": 63 + }, + "end": { + "line": 57, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 58 + }, + "end": { + "line": 57, + "column": 59 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 8, + "loc": { + "start": { + "line": 57, + "column": 70 + }, + "end": { + "line": 57, + "column": 71 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 57, + "column": 75 + }, + "end": { + "line": 57, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 70 + }, + "end": { + "line": 57, + "column": 71 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 9, + "loc": { + "start": { + "line": 57, + "column": 83 + }, + "end": { + "line": 57, + "column": 84 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 57, + "column": 88 + }, + "end": { + "line": 57, + "column": 94 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 83 + }, + "end": { + "line": 57, + "column": 84 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 57, + "column": 96 + }, + "end": { + "line": 57, + "column": 98 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 57, + "column": 102 + }, + "end": { + "line": 57, + "column": 108 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 96 + }, + "end": { + "line": 57, + "column": 98 + } + } + } + ], + "loc": { + "start": { + "line": 57, + "column": 45 + }, + "end": { + "line": 57, + "column": 109 + } + } + }, + "loc": { + "start": { + "line": 57, + "column": 9 + }, + "end": { + "line": 57, + "column": 109 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 57, + "column": 5 + }, + "end": { + "line": 57, + "column": 110 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "num_ref_arr", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 58, + "column": 22 + }, + "end": { + "line": 58, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 22 + }, + "end": { + "line": 58, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 22 + }, + "end": { + "line": 58, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 31 + }, + "end": { + "line": 58, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 58, + "column": 9 + }, + "end": { + "line": 58, + "column": 20 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 58, + "column": 34 + }, + "end": { + "line": 58, + "column": 35 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 58, + "column": 39 + }, + "end": { + "line": 58, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 34 + }, + "end": { + "line": 58, + "column": 35 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 58, + "column": 46 + }, + "end": { + "line": 58, + "column": 47 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 58, + "column": 51 + }, + "end": { + "line": 58, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 46 + }, + "end": { + "line": 58, + "column": 47 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 58, + "column": 58 + }, + "end": { + "line": 58, + "column": 59 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 58, + "column": 63 + }, + "end": { + "line": 58, + "column": 69 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 58 + }, + "end": { + "line": 58, + "column": 59 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 58, + "column": 70 + }, + "end": { + "line": 58, + "column": 71 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 58, + "column": 75 + }, + "end": { + "line": 58, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 70 + }, + "end": { + "line": 58, + "column": 71 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 58, + "column": 82 + }, + "end": { + "line": 58, + "column": 83 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 58, + "column": 87 + }, + "end": { + "line": 58, + "column": 93 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 82 + }, + "end": { + "line": 58, + "column": 83 + } + } + } + ], + "loc": { + "start": { + "line": 58, + "column": 33 + }, + "end": { + "line": 58, + "column": 94 + } + } + }, + "loc": { + "start": { + "line": 58, + "column": 9 + }, + "end": { + "line": 58, + "column": 94 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 58, + "column": 5 + }, + "end": { + "line": 58, + "column": 95 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "spread_tup", + "decorators": [], + "loc": { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 15 + } + } + }, + "right": { + "type": "Identifier", + "name": "num_ref_arr", + "decorators": [], + "loc": { + "start": { + "line": 60, + "column": 18 + }, + "end": { + "line": 60, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 60, + "column": 5 + }, + "end": { + "line": 60, + "column": 30 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "num_tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 62, + "column": 19 + }, + "end": { + "line": 62, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 62, + "column": 19 + }, + "end": { + "line": 62, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 62, + "column": 19 + }, + "end": { + "line": 62, + "column": 26 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 62, + "column": 27 + }, + "end": { + "line": 62, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 62, + "column": 27 + }, + "end": { + "line": 62, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 62, + "column": 27 + }, + "end": { + "line": 62, + "column": 34 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 62, + "column": 18 + }, + "end": { + "line": 62, + "column": 36 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 62, + "column": 9 + }, + "end": { + "line": 62, + "column": 16 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 11, + "loc": { + "start": { + "line": 62, + "column": 38 + }, + "end": { + "line": 62, + "column": 40 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 62, + "column": 41 + }, + "end": { + "line": 62, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 62, + "column": 37 + }, + "end": { + "line": 62, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 62, + "column": 9 + }, + "end": { + "line": 62, + "column": 43 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 62, + "column": 5 + }, + "end": { + "line": 62, + "column": 44 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "num_prim_arr", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 63, + "column": 23 + }, + "end": { + "line": 63, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 63, + "column": 23 + }, + "end": { + "line": 63, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 63, + "column": 23 + }, + "end": { + "line": 63, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 63, + "column": 32 + }, + "end": { + "line": 63, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 63, + "column": 9 + }, + "end": { + "line": 63, + "column": 21 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 63, + "column": 35 + }, + "end": { + "line": 63, + "column": 36 + } + } + }, + { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 63, + "column": 37 + }, + "end": { + "line": 63, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 63, + "column": 34 + }, + "end": { + "line": 63, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 63, + "column": 9 + }, + "end": { + "line": 63, + "column": 39 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 63, + "column": 5 + }, + "end": { + "line": 63, + "column": 40 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "num_prim_arr", + "decorators": [], + "loc": { + "start": { + "line": 65, + "column": 5 + }, + "end": { + "line": 65, + "column": 17 + } + } + }, + "right": { + "type": "Identifier", + "name": "num_tup", + "decorators": [], + "loc": { + "start": { + "line": 65, + "column": 20 + }, + "end": { + "line": 65, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 65, + "column": 5 + }, + "end": { + "line": 65, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 65, + "column": 5 + }, + "end": { + "line": 65, + "column": 28 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "d_var", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 67, + "column": 17 + }, + "end": { + "line": 67, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 67, + "column": 17 + }, + "end": { + "line": 67, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 67, + "column": 17 + }, + "end": { + "line": 67, + "column": 24 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 67, + "column": 25 + }, + "end": { + "line": 67, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 67, + "column": 25 + }, + "end": { + "line": 67, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 67, + "column": 25 + }, + "end": { + "line": 67, + "column": 32 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 67, + "column": 16 + }, + "end": { + "line": 67, + "column": 34 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 67, + "column": 9 + }, + "end": { + "line": 67, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 67, + "column": 36 + }, + "end": { + "line": 67, + "column": 37 + } + } + }, + { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 67, + "column": 39 + }, + "end": { + "line": 67, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 67, + "column": 35 + }, + "end": { + "line": 67, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 67, + "column": 9 + }, + "end": { + "line": 67, + "column": 43 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 67, + "column": 5 + }, + "end": { + "line": 67, + "column": 44 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "e_var", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 68, + "column": 17 + }, + "end": { + "line": 68, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 68, + "column": 17 + }, + "end": { + "line": 68, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 68, + "column": 17 + }, + "end": { + "line": 68, + "column": 24 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 68, + "column": 25 + }, + "end": { + "line": 68, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 68, + "column": 25 + }, + "end": { + "line": 68, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 68, + "column": 25 + }, + "end": { + "line": 68, + "column": 32 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 68, + "column": 33 + }, + "end": { + "line": 68, + "column": 40 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 68, + "column": 16 + }, + "end": { + "line": 68, + "column": 43 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 68, + "column": 9 + }, + "end": { + "line": 68, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 68, + "column": 45 + }, + "end": { + "line": 68, + "column": 46 + } + } + }, + { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 68, + "column": 48 + }, + "end": { + "line": 68, + "column": 51 + } + } + }, + { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 68, + "column": 53 + }, + "end": { + "line": 68, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 68, + "column": 44 + }, + "end": { + "line": 68, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 68, + "column": 9 + }, + "end": { + "line": 68, + "column": 58 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 68, + "column": 5 + }, + "end": { + "line": 68, + "column": 59 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "f_var", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 69, + "column": 17 + }, + "end": { + "line": 69, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 17 + }, + "end": { + "line": 69, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 17 + }, + "end": { + "line": 69, + "column": 24 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 69, + "column": 25 + }, + "end": { + "line": 69, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 25 + }, + "end": { + "line": 69, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 25 + }, + "end": { + "line": 69, + "column": 32 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 69, + "column": 33 + }, + "end": { + "line": 69, + "column": 40 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 69, + "column": 42 + }, + "end": { + "line": 69, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 42 + }, + "end": { + "line": 69, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 42 + }, + "end": { + "line": 69, + "column": 49 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 69, + "column": 50 + }, + "end": { + "line": 69, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 50 + }, + "end": { + "line": 69, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 69, + "column": 50 + }, + "end": { + "line": 69, + "column": 57 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 69, + "column": 16 + }, + "end": { + "line": 69, + "column": 58 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 69, + "column": 9 + }, + "end": { + "line": 69, + "column": 14 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 69, + "column": 9 + }, + "end": { + "line": 69, + "column": 14 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 69, + "column": 5 + }, + "end": { + "line": 69, + "column": 58 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "f_var", + "decorators": [], + "loc": { + "start": { + "line": 70, + "column": 5 + }, + "end": { + "line": 70, + "column": 10 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 70, + "column": 14 + }, + "end": { + "line": 70, + "column": 15 + } + } + }, + { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 70, + "column": 17 + }, + "end": { + "line": 70, + "column": 20 + } + } + }, + { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 70, + "column": 22 + }, + "end": { + "line": 70, + "column": 26 + } + } + }, + { + "type": "NumberLiteral", + "value": 20, + "loc": { + "start": { + "line": 70, + "column": 28 + }, + "end": { + "line": 70, + "column": 30 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 70, + "column": 32 + }, + "end": { + "line": 70, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 70, + "column": 13 + }, + "end": { + "line": 70, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 70, + "column": 5 + }, + "end": { + "line": 70, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 70, + "column": 5 + }, + "end": { + "line": 70, + "column": 37 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "g_var", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 72, + "column": 17 + }, + "end": { + "line": 72, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 72, + "column": 17 + }, + "end": { + "line": 72, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 72, + "column": 17 + }, + "end": { + "line": 72, + "column": 24 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 72, + "column": 25 + }, + "end": { + "line": 72, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 72, + "column": 25 + }, + "end": { + "line": 72, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 72, + "column": 25 + }, + "end": { + "line": 72, + "column": 32 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 72, + "column": 16 + }, + "end": { + "line": 72, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 72, + "column": 34 + }, + "end": { + "line": 72, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 72, + "column": 9 + }, + "end": { + "line": 72, + "column": 14 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 72, + "column": 9 + }, + "end": { + "line": 72, + "column": 14 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 72, + "column": 5 + }, + "end": { + "line": 72, + "column": 35 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "g_var", + "decorators": [], + "loc": { + "start": { + "line": 73, + "column": 5 + }, + "end": { + "line": 73, + "column": 10 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 73, + "column": 15 + }, + "end": { + "line": 73, + "column": 16 + } + } + }, + { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 73, + "column": 18 + }, + "end": { + "line": 73, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 73, + "column": 14 + }, + "end": { + "line": 73, + "column": 22 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 73, + "column": 25 + }, + "end": { + "line": 73, + "column": 26 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 73, + "column": 28 + }, + "end": { + "line": 73, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 73, + "column": 24 + }, + "end": { + "line": 73, + "column": 32 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 73, + "column": 35 + }, + "end": { + "line": 73, + "column": 36 + } + } + }, + { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 73, + "column": 38 + }, + "end": { + "line": 73, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 73, + "column": 34 + }, + "end": { + "line": 73, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 73, + "column": 13 + }, + "end": { + "line": 73, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 73, + "column": 5 + }, + "end": { + "line": 73, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 73, + "column": 5 + }, + "end": { + "line": 73, + "column": 44 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "h_var", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 75, + "column": 17 + }, + "end": { + "line": 75, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 17 + }, + "end": { + "line": 75, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 17 + }, + "end": { + "line": 75, + "column": 24 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 75, + "column": 25 + }, + "end": { + "line": 75, + "column": 28 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 75, + "column": 30 + }, + "end": { + "line": 75, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 30 + }, + "end": { + "line": 75, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 30 + }, + "end": { + "line": 75, + "column": 37 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 75, + "column": 38 + }, + "end": { + "line": 75, + "column": 45 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 75, + "column": 47 + }, + "end": { + "line": 75, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 47 + }, + "end": { + "line": 75, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 47 + }, + "end": { + "line": 75, + "column": 54 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 75, + "column": 16 + }, + "end": { + "line": 75, + "column": 56 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 75, + "column": 9 + }, + "end": { + "line": 75, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 75, + "column": 58 + }, + "end": { + "line": 75, + "column": 59 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 75, + "column": 61 + }, + "end": { + "line": 75, + "column": 62 + } + } + }, + { + "type": "StringLiteral", + "value": "asd", + "loc": { + "start": { + "line": 75, + "column": 64 + }, + "end": { + "line": 75, + "column": 69 + } + } + }, + { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 75, + "column": 71 + }, + "end": { + "line": 75, + "column": 76 + } + } + }, + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 75, + "column": 82 + }, + "end": { + "line": 75, + "column": 88 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 82 + }, + "end": { + "line": 75, + "column": 89 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 82 + }, + "end": { + "line": 75, + "column": 89 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 75, + "column": 78 + }, + "end": { + "line": 75, + "column": 91 + } + } + } + ], + "loc": { + "start": { + "line": 75, + "column": 57 + }, + "end": { + "line": 75, + "column": 91 + } + } + }, + "loc": { + "start": { + "line": 75, + "column": 9 + }, + "end": { + "line": 75, + "column": 91 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 75, + "column": 5 + }, + "end": { + "line": 75, + "column": 92 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "i_var", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 76, + "column": 16 + }, + "end": { + "line": 76, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 76, + "column": 9 + }, + "end": { + "line": 76, + "column": 14 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "h_var", + "decorators": [], + "loc": { + "start": { + "line": 76, + "column": 24 + }, + "end": { + "line": 76, + "column": 29 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 76, + "column": 30 + }, + "end": { + "line": 76, + "column": 31 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 76, + "column": 24 + }, + "end": { + "line": 76, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 76, + "column": 9 + }, + "end": { + "line": 76, + "column": 32 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 76, + "column": 5 + }, + "end": { + "line": 76, + "column": 33 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "j_var", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 78, + "column": 17 + }, + "end": { + "line": 78, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 78, + "column": 22 + }, + "end": { + "line": 78, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 78, + "column": 22 + }, + "end": { + "line": 78, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 78, + "column": 22 + }, + "end": { + "line": 78, + "column": 29 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 78, + "column": 30 + }, + "end": { + "line": 78, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 78, + "column": 30 + }, + "end": { + "line": 78, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 78, + "column": 30 + }, + "end": { + "line": 78, + "column": 37 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 78, + "column": 38 + }, + "end": { + "line": 78, + "column": 45 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 78, + "column": 47 + }, + "end": { + "line": 78, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 78, + "column": 47 + }, + "end": { + "line": 78, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 78, + "column": 47 + }, + "end": { + "line": 78, + "column": 54 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 78, + "column": 16 + }, + "end": { + "line": 78, + "column": 56 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 78, + "column": 9 + }, + "end": { + "line": 78, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 6, + "loc": { + "start": { + "line": 78, + "column": 58 + }, + "end": { + "line": 78, + "column": 59 + } + } + }, + { + "type": "NumberLiteral", + "value": 7, + "loc": { + "start": { + "line": 78, + "column": 61 + }, + "end": { + "line": 78, + "column": 62 + } + } + }, + { + "type": "StringLiteral", + "value": "abc", + "loc": { + "start": { + "line": 78, + "column": 64 + }, + "end": { + "line": 78, + "column": 69 + } + } + }, + { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 78, + "column": 71 + }, + "end": { + "line": 78, + "column": 75 + } + } + }, + { + "type": "NumberLiteral", + "value": 666, + "loc": { + "start": { + "line": 78, + "column": 77 + }, + "end": { + "line": 78, + "column": 80 + } + } + } + ], + "loc": { + "start": { + "line": 78, + "column": 57 + }, + "end": { + "line": 78, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 78, + "column": 9 + }, + "end": { + "line": 78, + "column": 81 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 78, + "column": 5 + }, + "end": { + "line": 78, + "column": 82 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "empty", + "typeAnnotation": { + "type": "ETSTuple", + "spreadType": null, + "loc": { + "start": { + "line": 82, + "column": 16 + }, + "end": { + "line": 82, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 82, + "column": 9 + }, + "end": { + "line": 82, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [], + "loc": { + "start": { + "line": 82, + "column": 21 + }, + "end": { + "line": 82, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 82, + "column": 9 + }, + "end": { + "line": 82, + "column": 23 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 82, + "column": 5 + }, + "end": { + "line": 82, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 23 + }, + "end": { + "line": 83, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 83, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 83, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 83, + "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": 84, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_1.ets b/ets2panda/test/compiler/ets/tuple_types_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..72de48fbadc209f634d2b658c732986ddcfb5be4 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_1.ets @@ -0,0 +1,83 @@ +/* + * 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 { foo() {}} +class B extends A { bar() {}} + +type num_str_str_type = [number, string, string]; +type num_str_str_with_spread = [num_str_str_type, ...number[]]; + +function foo(a0: number, args: [...number[]]): number { + return 2; +} + + +function main(): void { + const tup_arr_1: num_str_str_type[] = [ + [0, "a", "d"], + [1, "b", "e"], + [2, "c", "f"], + ]; + + const tup_arr_2: num_str_str_with_spread[] = [ + [tup_arr_1[0], 250], + [tup_arr_1[1], 250, 260], + [tup_arr_1[0], 300, 300, 300], + ]; + + const a_var = tup_arr_2[0][1] + tup_arr_2[1][1] + tup_arr_2[2][1]; + const b_var = tup_arr_2[1][2] + tup_arr_2[2][2]; + const c_var = tup_arr_2[2][2]; + + foo(tup_arr_1[0][0], [tup_arr_2[0][1]]); + foo(tup_arr_1[1][0], [tup_arr_2[1][1], tup_arr_2[1][2]]); + + let arr: Object[] = [1,2,3,4,5]; + let double_ref_tup: [Number, Number, Number] = [6 as double, 7 as double, 8 as double]; + let a_arr: A[]; + let b_tup: [B, B] = [new B(), new B()]; + let b_arr: B[] = [new B(), new B()]; + + arr = double_ref_tup; + a_arr = b_tup; + b_arr = b_tup; + + let spread_tup: [Number, ...Number[]] = [6 as double,7 as double,8 as double, 9 as double, 10 as double]; + let num_ref_arr: Number[] = [1 as double,2 as double,3 as double,4 as double,5 as double]; + + spread_tup = num_ref_arr; + + let num_tup: [number, number] = [11,2]; + let num_prim_arr: number[] = [3,4]; + + num_prim_arr = num_tup; + + let d_var: [number, string] = [1, "A"]; + let e_var: [number, string, boolean] = [1, "A", true]; + let f_var: [number, string, boolean, number, string]; + f_var = [1, "A", true, 20, "B"]; + + let g_var: [number, string][]; + g_var = [[1, "A"], [2, "B"], [3, "C"]]; + + let h_var: [number, int, string, boolean, Object] = [1, 2, "asd", false, new Object()]; + let i_var: float = h_var[1]; + + let j_var: [int, number, string, boolean, Object] = [6, 7, "abc", true, 666]; + // NOTE: Bug in op_assignment lowering (removes const from property) + // j_var[0] += new Short(2 as short); + + let empty: [] = []; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d72397b08129f0c4baff9b180854da7793e1d7b8 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_10_neg-expected.txt @@ -0,0 +1,673 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "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 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 18, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 37 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 36 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 39 + }, + "end": { + "line": 19, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Initializers type is not assignable to the target type [tuple_types_10_neg.ets:19:39] diff --git a/ets2panda/test/compiler/ets/tuple_types_10_neg.ets b/ets2panda/test/compiler/ets/tuple_types_10_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..1757a67a057f40882604c4db7fe7b662358b7cca --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_10_neg.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. + */ + + +function main(): void { + let a: [number, number] = [2, 3]; + let b: [number, number, number] = a; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..669daa1144697c1a660006e303b6418a12aff12f --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_11_neg-expected.txt @@ -0,0 +1,687 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "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 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 36 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 40 + }, + "end": { + "line": 18, + "column": 41 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 44 + } + } + }, + { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 18, + "column": 46 + }, + "end": { + "line": 18, + "column": 47 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 39 + }, + "end": { + "line": 18, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 48 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 49 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 32 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Initializers type is not assignable to the target type [tuple_types_11_neg.ets:19:31] diff --git a/ets2panda/test/compiler/ets/tuple_types_11_neg.ets b/ets2panda/test/compiler/ets/tuple_types_11_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..e50a7e53f338572a4cd5ded770ac4d1809f69e42 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_11_neg.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. + */ + + +function main(): void { + let a: [number, number, number] = [2, 3, 4]; + let b: [number, number] = a; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_12-expected.txt b/ets2panda/test/compiler/ets/tuple_types_12-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..19124a264bc8b876bc2b360fc99ea265c1ec0f3f --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_12-expected.txt @@ -0,0 +1,2204 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "custom_tuple_type", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 38 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + { + "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": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + { + "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": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a_tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 22, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 22, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 22, + "column": 30 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 31 + } + } + }, + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "custom_tuple_type", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 51 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 52 + } + } + }, + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 54 + }, + "end": { + "line": 22, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 54 + }, + "end": { + "line": 22, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 54 + }, + "end": { + "line": 22, + "column": 56 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 57 + }, + "end": { + "line": 22, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 57 + }, + "end": { + "line": 22, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 57 + }, + "end": { + "line": 22, + "column": 59 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 22, + "column": 53 + }, + "end": { + "line": 22, + "column": 60 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "custom_tuple_type", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 64 + }, + "end": { + "line": 22, + "column": 81 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 64 + }, + "end": { + "line": 22, + "column": 82 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 64 + }, + "end": { + "line": 22, + "column": 82 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 83 + }, + "end": { + "line": 22, + "column": 84 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 86 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 22, + "column": 89 + }, + "end": { + "line": 22, + "column": 90 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 22, + "column": 92 + }, + "end": { + "line": 22, + "column": 93 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 88 + }, + "end": { + "line": 22, + "column": 94 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 22, + "column": 98 + }, + "end": { + "line": 22, + "column": 101 + } + } + }, + { + "type": "NumberLiteral", + "value": 6, + "loc": { + "start": { + "line": 22, + "column": 103 + }, + "end": { + "line": 22, + "column": 104 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 97 + }, + "end": { + "line": 22, + "column": 105 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 96 + }, + "end": { + "line": 22, + "column": 106 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 113 + }, + "end": { + "line": 22, + "column": 114 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 113 + }, + "end": { + "line": 22, + "column": 115 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 113 + }, + "end": { + "line": 22, + "column": 115 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 22, + "column": 109 + }, + "end": { + "line": 22, + "column": 117 + } + } + }, + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 122 + }, + "end": { + "line": 22, + "column": 123 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 122 + }, + "end": { + "line": 22, + "column": 124 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 122 + }, + "end": { + "line": 22, + "column": 124 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 22, + "column": 118 + }, + "end": { + "line": 22, + "column": 126 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 108 + }, + "end": { + "line": 22, + "column": 126 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "StringLiteral", + "value": "b", + "loc": { + "start": { + "line": 22, + "column": 129 + }, + "end": { + "line": 22, + "column": 132 + } + } + }, + { + "type": "NumberLiteral", + "value": 8, + "loc": { + "start": { + "line": 22, + "column": 134 + }, + "end": { + "line": 22, + "column": 135 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 128 + }, + "end": { + "line": 22, + "column": 136 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "StringLiteral", + "value": "c", + "loc": { + "start": { + "line": 22, + "column": 139 + }, + "end": { + "line": 22, + "column": 142 + } + } + }, + { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 22, + "column": 144 + }, + "end": { + "line": 22, + "column": 146 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 138 + }, + "end": { + "line": 22, + "column": 147 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "StringLiteral", + "value": "d", + "loc": { + "start": { + "line": 22, + "column": 150 + }, + "end": { + "line": 22, + "column": 153 + } + } + }, + { + "type": "NumberLiteral", + "value": 12, + "loc": { + "start": { + "line": 22, + "column": 155 + }, + "end": { + "line": 22, + "column": 157 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 149 + }, + "end": { + "line": 22, + "column": 158 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 87 + }, + "end": { + "line": 22, + "column": 159 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 159 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 160 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "my_str", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a_tup", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 23, + "column": 32 + }, + "end": { + "line": 23, + "column": 33 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 36 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 37 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 23, + "column": 38 + }, + "end": { + "line": 23, + "column": 39 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 40 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 41 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "my_str_2", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 19 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 17 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a_tup", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 33 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 6, + "loc": { + "start": { + "line": 24, + "column": 34 + }, + "end": { + "line": 24, + "column": 35 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 36 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 24, + "column": 37 + }, + "end": { + "line": 24, + "column": 38 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 39 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 40 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a_tup", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 10 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 25, + "column": 11 + }, + "end": { + "line": 25, + "column": 12 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 16 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 17 + }, + "end": { + "line": 25, + "column": 20 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 20 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a_tup", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 10 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 26, + "column": 11 + }, + "end": { + "line": 26, + "column": 12 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 26, + "column": 14 + }, + "end": { + "line": 26, + "column": 15 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 16 + } + } + }, + "property": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 27, + "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": 28, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_12.ets b/ets2panda/test/compiler/ets/tuple_types_12.ets new file mode 100644 index 0000000000000000000000000000000000000000..fce85859fd6262fdbc0d3e46c8a6164d073870b6 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_12.ets @@ -0,0 +1,27 @@ +/* + * 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. + */ + +type custom_tuple_type = [string, int]; + +class A {foo(){}} +class B extends A {bar(){}} + +function main(): void { + let a_tup: [[int, number], [custom_tuple_type], [A, B], ...custom_tuple_type[]] = [[2, 3], [["a", 6]], [new B(), new B()], ["b", 8], ["c", 10], ["d", 12]]; + let my_str: String = a_tup[1][0][0]; + let my_str_2: String = a_tup[6][0]; + a_tup[2][0].foo(); + a_tup[2][1].bar(); +} diff --git a/ets2panda/test/compiler/ets/tuple_types_13-expected.txt b/ets2panda/test/compiler/ets/tuple_types_13-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa16620a4d9ed0d571c23e28caf553a558e2bfbf --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_13-expected.txt @@ -0,0 +1,482 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "num_str_str", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 36 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 44 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + { + "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": "tup_2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "value": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 13, + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "num_str_str", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 29 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "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 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_13.ets b/ets2panda/test/compiler/ets/tuple_types_13.ets new file mode 100644 index 0000000000000000000000000000000000000000..00fca809cf59bcfe0803308708d8e40ed5974726 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_13.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. + */ + +type num_str_str = [number, string, string]; + + +const tup_2: num_str_str[] = [ + [13, "A", "D"] +]; diff --git a/ets2panda/test/compiler/ets/tuple_types_14-expected.txt b/ets2panda/test/compiler/ets/tuple_types_14-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fa310986d8a254bb9dca205b7a55a77ebe934ef5 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_14-expected.txt @@ -0,0 +1,2056 @@ +{ + "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": "ClassProperty", + "key": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 9 + } + } + }, + "accessibility": "public", + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 15 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + { + "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": 22, + "column": 2 + }, + "end": { + "line": 22, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + { + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 18 + }, + "end": { + "line": 24, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 18 + }, + "end": { + "line": 24, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 18 + }, + "end": { + "line": 24, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "my_var", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 17 + }, + "end": { + "line": 25, + "column": 18 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 25, + "column": 20 + }, + "end": { + "line": 25, + "column": 23 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 25 + }, + "end": { + "line": 25, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 25 + }, + "end": { + "line": 25, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 25 + }, + "end": { + "line": 25, + "column": 32 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 25, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 17 + }, + "end": { + "line": 25, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 17 + }, + "end": { + "line": 25, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 40 + }, + "end": { + "line": 25, + "column": 41 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 25, + "column": 43 + }, + "end": { + "line": 25, + "column": 46 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 48 + }, + "end": { + "line": 25, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 48 + }, + "end": { + "line": 25, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 48 + }, + "end": { + "line": 25, + "column": 55 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 25, + "column": 42 + }, + "end": { + "line": 25, + "column": 56 + } + } + } + ], + "loc": { + "start": { + "line": 25, + "column": 41 + }, + "end": { + "line": 25, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 40 + }, + "end": { + "line": 25, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 40 + }, + "end": { + "line": 25, + "column": 57 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 25, + "column": 36 + }, + "end": { + "line": 25, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 59 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 59 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "my_var", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 11 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 12 + }, + "end": { + "line": 26, + "column": 16 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 16 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 26, + "column": 20 + }, + "end": { + "line": 26, + "column": 21 + } + } + }, + { + "type": "StringLiteral", + "value": "b", + "loc": { + "start": { + "line": 26, + "column": 23 + }, + "end": { + "line": 26, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 19 + }, + "end": { + "line": 26, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 28 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 20 + }, + "end": { + "line": 27, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 20 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 20 + }, + "end": { + "line": 27, + "column": 27 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 12 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 6, + "loc": { + "start": { + "line": 27, + "column": 31 + }, + "end": { + "line": 27, + "column": 32 + } + } + }, + { + "type": "StringLiteral", + "value": "c", + "loc": { + "start": { + "line": 27, + "column": 34 + }, + "end": { + "line": 27, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 30 + }, + "end": { + "line": 27, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 38 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 39 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "my_var", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 11 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 15 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 15 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "tup", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 16 + }, + "end": { + "line": 28, + "column": 19 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "my_var_2", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 19 + }, + "end": { + "line": 30, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 22 + }, + "end": { + "line": 30, + "column": 25 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 27 + }, + "end": { + "line": 30, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 27 + }, + "end": { + "line": 30, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 27 + }, + "end": { + "line": 30, + "column": 34 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 20 + }, + "end": { + "line": 30, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 19 + }, + "end": { + "line": 30, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 19 + }, + "end": { + "line": 30, + "column": 37 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 17 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 42 + }, + "end": { + "line": 30, + "column": 43 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 45 + }, + "end": { + "line": 30, + "column": 48 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 50 + }, + "end": { + "line": 30, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 50 + }, + "end": { + "line": 30, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 50 + }, + "end": { + "line": 30, + "column": 57 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 30, + "column": 44 + }, + "end": { + "line": 30, + "column": 58 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 43 + }, + "end": { + "line": 30, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 42 + }, + "end": { + "line": 30, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 42 + }, + "end": { + "line": 30, + "column": 59 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 30, + "column": 38 + }, + "end": { + "line": 30, + "column": 61 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 61 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 61 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "my_var_2", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "memb", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 31, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 18 + } + } + }, + "right": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "my_var", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 21 + }, + "end": { + "line": 31, + "column": 27 + } + } + }, + "property": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 28 + }, + "end": { + "line": 31, + "column": 31 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 21 + }, + "end": { + "line": 31, + "column": 31 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 21 + }, + "end": { + "line": 31, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 32, + "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": 33, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_14.ets b/ets2panda/test/compiler/ets/tuple_types_14.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5b8c72e73f795c4a43856dc6506f1d4d0a658f8 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_14.ets @@ -0,0 +1,32 @@ +/* + * 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 { + memb: T; + foo(a0: T): void {} + bar(): T { + return this.memb; + } +} + +function main(): void { + let my_var: A<[int, String]> = new A<[int, String]>(); + my_var.memb = [1, "b"]; + let tup: [int, String] = [6, "c"]; + my_var.foo(tup); + + let my_var_2: A<[int, String]> = new A<[int, String]>(); + my_var_2.memb = my_var.bar(); +} diff --git a/ets2panda/test/compiler/ets/tuple_types_15-expected.txt b/ets2panda/test/compiler/ets/tuple_types_15-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..754f6acb255ba185d3da9537fb9053c1665b2011 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_15-expected.txt @@ -0,0 +1,2104 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "array_tuple", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 28 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 16, + "column": 36 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + { + "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": "getIntAndString", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "getIntAndString", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 30 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 30 + }, + "end": { + "line": 18, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 30 + }, + "end": { + "line": 18, + "column": 37 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 38 + }, + "end": { + "line": 18, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 38 + }, + "end": { + "line": 18, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 38 + }, + "end": { + "line": 18, + "column": 45 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 47 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tup", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 30 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 12 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 19, + "column": 34 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + { + "type": "StringLiteral", + "value": "c", + "loc": { + "start": { + "line": 19, + "column": 38 + }, + "end": { + "line": 19, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 42 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 43 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "tup", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 46 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 21, + "column": 4 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "sample_tuple", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 24 + }, + "end": { + "line": 24, + "column": 31 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 24, + "column": 32 + }, + "end": { + "line": 24, + "column": 39 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 41 + }, + "end": { + "line": 24, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 41 + }, + "end": { + "line": 24, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 41 + }, + "end": { + "line": 24, + "column": 48 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 49 + }, + "end": { + "line": 24, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 49 + }, + "end": { + "line": 24, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 49 + }, + "end": { + "line": 24, + "column": 56 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 24, + "column": 58 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 21 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 10, + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 11 + } + } + }, + { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 12 + } + } + }, + { + "type": "NumberLiteral", + "value": 90, + "loc": { + "start": { + "line": 28, + "column": 9 + }, + "end": { + "line": 28, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 59 + }, + "end": { + "line": 29, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 29, + "column": 6 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 29, + "column": 7 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "values", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 17 + }, + "end": { + "line": 31, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 17 + }, + "end": { + "line": 31, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 17 + }, + "end": { + "line": 31, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + "init": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "BinaryExpression", + "operator": "+", + "left": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "sample_tuple", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 38 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 31, + "column": 39 + }, + "end": { + "line": 31, + "column": 40 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 41 + } + } + }, + "right": { + "type": "StringLiteral", + "value": " ", + "loc": { + "start": { + "line": 31, + "column": 44 + }, + "end": { + "line": 31, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 47 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "sample_tuple", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 50 + }, + "end": { + "line": 31, + "column": 62 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 31, + "column": 63 + }, + "end": { + "line": 31, + "column": 64 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 50 + }, + "end": { + "line": 31, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 65 + } + } + }, + "right": { + "type": "StringLiteral", + "value": " ", + "loc": { + "start": { + "line": 31, + "column": 68 + }, + "end": { + "line": 31, + "column": 71 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 71 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "sample_tuple", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 74 + }, + "end": { + "line": 31, + "column": 86 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 31, + "column": 87 + }, + "end": { + "line": 31, + "column": 88 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 74 + }, + "end": { + "line": 31, + "column": 89 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 89 + } + } + }, + "right": { + "type": "StringLiteral", + "value": " ", + "loc": { + "start": { + "line": 31, + "column": 92 + }, + "end": { + "line": 31, + "column": 95 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 95 + } + } + }, + "right": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "sample_tuple", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 98 + }, + "end": { + "line": 31, + "column": 110 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 31, + "column": 111 + }, + "end": { + "line": 31, + "column": 112 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 31, + "column": 98 + }, + "end": { + "line": 31, + "column": 113 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 113 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 113 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 114 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "array", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "array_tuple", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 16 + }, + "end": { + "line": 32, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 16 + }, + "end": { + "line": 32, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 16 + }, + "end": { + "line": 32, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 30 + }, + "end": { + "line": 32, + "column": 31 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 9 + }, + "end": { + "line": 32, + "column": 14 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 32, + "column": 34 + }, + "end": { + "line": 32, + "column": 35 + } + } + }, + { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 32, + "column": 37 + }, + "end": { + "line": 32, + "column": 41 + } + } + } + ], + "loc": { + "start": { + "line": 32, + "column": 33 + }, + "end": { + "line": 32, + "column": 42 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 32, + "column": 45 + }, + "end": { + "line": 32, + "column": 46 + } + } + }, + { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 32, + "column": 48 + }, + "end": { + "line": 32, + "column": 53 + } + } + } + ], + "loc": { + "start": { + "line": 32, + "column": 44 + }, + "end": { + "line": 32, + "column": 54 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 32, + "column": 57 + }, + "end": { + "line": 32, + "column": 58 + } + } + }, + { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 32, + "column": 60 + }, + "end": { + "line": 32, + "column": 65 + } + } + } + ], + "loc": { + "start": { + "line": 32, + "column": 56 + }, + "end": { + "line": 32, + "column": 66 + } + } + }, + { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 4, + "loc": { + "start": { + "line": 32, + "column": 69 + }, + "end": { + "line": 32, + "column": 70 + } + } + }, + { + "type": "BooleanLiteral", + "value": true, + "loc": { + "start": { + "line": 32, + "column": 72 + }, + "end": { + "line": 32, + "column": 76 + } + } + } + ], + "loc": { + "start": { + "line": 32, + "column": 68 + }, + "end": { + "line": 32, + "column": 77 + } + } + } + ], + "loc": { + "start": { + "line": 32, + "column": 32 + }, + "end": { + "line": 32, + "column": 79 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 9 + }, + "end": { + "line": 32, + "column": 79 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 32, + "column": 5 + }, + "end": { + "line": 32, + "column": 80 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "array", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 10 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 33, + "column": 11 + }, + "end": { + "line": 33, + "column": 12 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 14 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "array", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 10 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 34, + "column": 11 + }, + "end": { + "line": 34, + "column": 12 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 14 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "array", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 10 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 35, + "column": 11 + }, + "end": { + "line": 35, + "column": 12 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 13 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 35, + "column": 15 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 17 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "tuple", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 17 + }, + "end": { + "line": 37, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 17 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 17 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 25 + }, + "end": { + "line": 37, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 25 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 25 + }, + "end": { + "line": 37, + "column": 32 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 37, + "column": 16 + }, + "end": { + "line": 37, + "column": 34 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 14 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "getIntAndString", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 35 + }, + "end": { + "line": 37, + "column": 50 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 35 + }, + "end": { + "line": 37, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 52 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 37, + "column": 5 + }, + "end": { + "line": 37, + "column": 53 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 23 + }, + "end": { + "line": 41, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 41, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 41, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 41, + "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": 42, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_15.ets b/ets2panda/test/compiler/ets/tuple_types_15.ets new file mode 100644 index 0000000000000000000000000000000000000000..d32c8f2a30e356b2fc89e0b8bb36c43dc8e0d0b0 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_15.ets @@ -0,0 +1,41 @@ +/* + * 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. + */ + +type array_tuple = [number, boolean]; + +function getIntAndString(): [number, string] { + let tup: [number, string] = [10, "c"]; + return tup; + } + +function main(): void { + let sample_tuple: [number, boolean, string, number] = [ + 10, + true, + "B", + 90, + ]; + + let values: string = sample_tuple[0] + " " + sample_tuple[1] + " " + sample_tuple[2] + " " + sample_tuple[3]; + let array: array_tuple[] = [[1, true], [2, false], [3, false], [4, true],]; + array[1]; + array[2]; + array[3][1]; + + let tuple: [number, string] = getIntAndString(); + + + +} diff --git a/ets2panda/test/compiler/ets/tuple_types_2_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_2_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b32a3a2104acb7fab23c9cf75758e03fd233c55c --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_2_neg-expected.txt @@ -0,0 +1,532 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "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 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 18, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 37 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 10 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Element accessor value is out of tuple size bounds. [tuple_types_2_neg.ets:19:7] diff --git a/ets2panda/test/compiler/ets/tuple_types_2_neg.ets b/ets2panda/test/compiler/ets/tuple_types_2_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..32de880ce63099236be36fadd2247dd5cb6c9e73 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_2_neg.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. + */ + + +function main(): void { + let a: [number, number] = [1, 2]; + a[2]; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_3_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_3_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cca4b7497d07671b2c9efd6f0d0039a535eaeafc --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_3_neg-expected.txt @@ -0,0 +1,434 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 29 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "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": 20, + "column": 1 + } + } +} +TypeError: Too many elements in array initializer for tuple with size of 1 [tuple_types_3_neg.ets:18:27] diff --git a/ets2panda/test/compiler/ets/tuple_types_3_neg.ets b/ets2panda/test/compiler/ets/tuple_types_3_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..f5ff5c2f70e365ff014782aed5b8f836288757c8 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_3_neg.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +function main(): void { + let a: [number] = [1, 2]; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_4_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_4_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..db9deb2371bc0cb683e83701cdb22bc5022e2fb0 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_4_neg-expected.txt @@ -0,0 +1,461 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "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 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "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": 20, + "column": 1 + } + } +} +TypeError: Few elements in array initializer for tuple with size of 2 [tuple_types_4_neg.ets:18:31] diff --git a/ets2panda/test/compiler/ets/tuple_types_4_neg.ets b/ets2panda/test/compiler/ets/tuple_types_4_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..12cc1cfde84d237798f6e250e18b16155e2d0180 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_4_neg.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +function main(): void { + let a: [number, number] = [1]; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_5_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_5_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c17eebbf4d311a0cf910e149a5ab435eab8088d2 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_5_neg-expected.txt @@ -0,0 +1,473 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 36 + }, + "end": { + "line": 18, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 39 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 40 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "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": 20, + "column": 1 + } + } +} +TypeError: Few elements in array initializer for tuple with size of 2 [tuple_types_5_neg.ets:18:36] diff --git a/ets2panda/test/compiler/ets/tuple_types_5_neg.ets b/ets2panda/test/compiler/ets/tuple_types_5_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..f89f1a8abe83d8eaacb736cf674e85a03ffeb2da --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_5_neg.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +function main(): void { + let a: [number, ...number[]] = [1]; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b54e94654925d1e947df0a94a2a422e77fb8d7d7 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_6_neg-expected.txt @@ -0,0 +1,536 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 26 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Initializers type is not assignable to the target type [tuple_types_6_neg.ets:19:23] diff --git a/ets2panda/test/compiler/ets/tuple_types_6_neg.ets b/ets2panda/test/compiler/ets/tuple_types_6_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ea94146207182ef99d6be586f150fe4fa55df12 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_6_neg.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. + */ + + +function main(): void { + let a: [number] = [1]; + let b: [Number] = a; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_7-expected.txt b/ets2panda/test/compiler/ets/tuple_types_7-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1793aff6858ff7283910686fc9066fa3998a9daa --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_7-expected.txt @@ -0,0 +1,937 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "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 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 33 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 18, + "column": 40 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 46 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 36 + }, + "end": { + "line": 18, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 47 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 48 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 33 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 37 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 28 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 32 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 37 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 41 + }, + "end": { + "line": 20, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 42 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "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 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_7.ets b/ets2panda/test/compiler/ets/tuple_types_7.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d1d70565f072c44bbe4101334f077036f0174b5 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_7.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. + */ + + +function main(): void { + let a: [number, string, Int] = [2, "a", 3]; + let b: [number, string, Int] = a; + let c: [number, string, ...Int[]] = a; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_8-expected.txt b/ets2panda/test/compiler/ets/tuple_types_8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5443c594f1e4a36e3517d28c026c449d6ffac225 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_8-expected.txt @@ -0,0 +1,855 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "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 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 18, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 37 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "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 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 20 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 21, + "column": 37 + }, + "end": { + "line": 21, + "column": 38 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 21, + "column": 40 + }, + "end": { + "line": 21, + "column": 41 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 21, + "column": 43 + }, + "end": { + "line": 21, + "column": 44 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 36 + }, + "end": { + "line": 21, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 45 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 46 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "right": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 23, + "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": 24, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/tuple_types_8.ets b/ets2panda/test/compiler/ets/tuple_types_8.ets new file mode 100644 index 0000000000000000000000000000000000000000..10506b0ea204c8ed3a4972d32d3537137f22314e --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_8.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + + +function main(): void { + let a: [number, number] = [1, 2]; + let b: number[] = a; + + let c: [number, ...number[]] = [1, 2, 3]; + c = b; +} diff --git a/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt b/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b3ff7ada9a55d8e924a21cbf03450f3a735d4d72 --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_9_neg-expected.txt @@ -0,0 +1,740 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "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": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + { + "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 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 32 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "init": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, + { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 18, + "column": 45 + }, + "end": { + "line": 18, + "column": 48 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 18, + "column": 50 + }, + "end": { + "line": 18, + "column": 51 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 41 + }, + "end": { + "line": 18, + "column": 52 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 52 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 53 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 33 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 37 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Initializers type is not assignable to the target type [tuple_types_9_neg.ets:19:36] diff --git a/ets2panda/test/compiler/ets/tuple_types_9_neg.ets b/ets2panda/test/compiler/ets/tuple_types_9_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..090eb69040a7ca0890206cfe52ffa1b0b00fd18e --- /dev/null +++ b/ets2panda/test/compiler/ets/tuple_types_9_neg.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. + */ + + +function main(): void { + let a: [number, string, ...Int[]] = [2, "a", 3]; + let b: [number, string, Int] = a; +} diff --git a/ets2panda/test/parser/ets/tuple_type_1-expected.txt b/ets2panda/test/parser/ets/tuple_type_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..101d5111ac1423c4ab01bfac717452d510f6307e --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_1-expected.txt @@ -0,0 +1,2035 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "my_type", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 35 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 47 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 48 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 25 + }, + "end": { + "line": 16, + "column": 49 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 50 + } + } + }, + { + "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": "a", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 22, + "column": 28 + }, + "end": { + "line": 22, + "column": 29 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 22, + "column": 31 + }, + "end": { + "line": 22, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 27 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + { + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 23, + "column": 31 + }, + "end": { + "line": 23, + "column": 32 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 23, + "column": 36 + }, + "end": { + "line": 23, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 31 + }, + "end": { + "line": 23, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 23, + "column": 44 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 24, + "column": 41 + }, + "end": { + "line": 24, + "column": 42 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 24, + "column": 44 + }, + "end": { + "line": 24, + "column": 45 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 24, + "column": 47 + }, + "end": { + "line": 24, + "column": 48 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 40 + }, + "end": { + "line": 24, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 24, + "column": 50 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 6 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [], + "loc": { + "start": { + "line": 25, + "column": 13 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 25, + "column": 16 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "e", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 26, + "column": 36 + }, + "end": { + "line": 26, + "column": 37 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 26, + "column": 39 + }, + "end": { + "line": 26, + "column": 40 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 35 + }, + "end": { + "line": 26, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 26, + "column": 42 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 6 + } + } + }, + "right": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 27, + "column": 41 + }, + "end": { + "line": 27, + "column": 42 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 27, + "column": 44 + }, + "end": { + "line": 27, + "column": 45 + } + } + }, + { + "type": "NumberLiteral", + "value": 3, + "loc": { + "start": { + "line": 27, + "column": 47 + }, + "end": { + "line": 27, + "column": 48 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 40 + }, + "end": { + "line": 27, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 27, + "column": 50 + } + } + } + ], + "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": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a0", + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 31 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 42 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 43 + }, + "end": { + "line": 18, + "column": 50 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 18, + "column": 34 + }, + "end": { + "line": 18, + "column": 52 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "ArrayExpression", + "elements": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 51 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 24 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 24 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 23, + "column": 8 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 26 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 16 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 24 + } + } + } + ], + "spreadType": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 36 + }, + "end": { + "line": 24, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 8 + }, + "end": { + "line": 24, + "column": 39 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 39 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "spreadType": null, + "loc": { + "start": { + "line": 25, + "column": 8 + }, + "end": { + "line": 25, + "column": 12 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 12 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "e", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 32 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 26, + "column": 8 + }, + "end": { + "line": 26, + "column": 34 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 26, + "column": 34 + } + } + }, + { + "type": "ClassProperty", + "key": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 6 + } + } + }, + "accessibility": "public", + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "ETSTuple", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 27, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 27, + "column": 20 + } + } + }, + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 24 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 30 + }, + "end": { + "line": 27, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 30 + }, + "end": { + "line": 27, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 30 + }, + "end": { + "line": 27, + "column": 37 + } + } + } + ], + "spreadType": null, + "loc": { + "start": { + "line": 27, + "column": 8 + }, + "end": { + "line": 27, + "column": 39 + } + } + }, + "definite": false, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 39 + } + } + } + ], + "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": 28, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/tuple_type_1.ets b/ets2panda/test/parser/ets/tuple_type_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..00298b8b96986b3f90cdcaf52842c6470754c705 --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_1.ets @@ -0,0 +1,27 @@ +/* + * 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. + */ + +type my_type = [Number, [Number, [int, Object]]]; + +function foo(a0: [int, number]): [number, number] { + return [1, 2]; +} + +let a: [number, number] = [1, 2]; +let b: [Object, Number] = [1, 2 as double]; +let c: [number, number, ...number[]] = [1, 2, 3]; +let d: [] = []; +let e: [a0: number, a1: number] = [1, 2]; +let f: [a0: number, int, a1: number] = [1, 2, 3]; diff --git a/ets2panda/test/parser/ets/tuple_type_2_neg-expected.txt b/ets2panda/test/parser/ets/tuple_type_2_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..af3ec97047149b82892ae9742fcb2d6354329b54 --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_2_neg-expected.txt @@ -0,0 +1 @@ +SyntaxError: Spread type must be at the last index in the tuple type [tuple_type_2_neg.ets:17:30] diff --git a/ets2panda/test/parser/ets/tuple_type_2_neg.ets b/ets2panda/test/parser/ets/tuple_type_2_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..551fe58e836c5af47dc4073b7ac25aa3fbdd6748 --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_2_neg.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +let a: [number, ...number[], number] = [1, 2, 3]; diff --git a/ets2panda/test/parser/ets/tuple_type_3_neg-expected.txt b/ets2panda/test/parser/ets/tuple_type_3_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ffd97331c7d84e0a9525b1690cd5b42126e1da5 --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_3_neg-expected.txt @@ -0,0 +1 @@ +SyntaxError: Comma is mandatory between elements in a tuple type declaration [tuple_type_3_neg.ets:17:24] diff --git a/ets2panda/test/parser/ets/tuple_type_3_neg.ets b/ets2panda/test/parser/ets/tuple_type_3_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..112d7709a7ab8c87c63059f887f8d6559c3a6a6d --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_3_neg.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +let a: [number, number number] = [1, 2, 3]; diff --git a/ets2panda/test/parser/ets/tuple_type_4_neg-expected.txt b/ets2panda/test/parser/ets/tuple_type_4_neg-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..bc0cf53ee585f9d203d72d67ddf878b7ff7ead3d --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_4_neg-expected.txt @@ -0,0 +1 @@ +SyntaxError: Invalid Type [tuple_type_4_neg.ets:17:13] diff --git a/ets2panda/test/parser/ets/tuple_type_4_neg.ets b/ets2panda/test/parser/ets/tuple_type_4_neg.ets new file mode 100644 index 0000000000000000000000000000000000000000..94226d0d8437ccd33cc78a7a490671c38ffd4bc2 --- /dev/null +++ b/ets2panda/test/parser/ets/tuple_type_4_neg.ets @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +let a: [a0: , a1: number] = [1, 2, 3]; diff --git a/ets2panda/test/runtime/ets/tuple_types_runtime.ets b/ets2panda/test/runtime/ets/tuple_types_runtime.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f57797cab21335e752f5e8d7956c1866ebe4774 --- /dev/null +++ b/ets2panda/test/runtime/ets/tuple_types_runtime.ets @@ -0,0 +1,129 @@ +/* + * 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. + */ + +type num_str_str = [number, string, string]; +type num_str_str_with_spread = [num_str_str, ...number[]]; + +class A { + foo(): int { + return 1; + } +} + +class B extends A { + override foo(): int { + return 2; + } +} + + +function main(): void { + const tup_1: [string, number] = ["a", 12]; + + assert(tup_1[0] == "a"); + assert(tup_1[1] == 12); + + const tup_2: num_str_str[] = [ + [13, "A", "D"], + [14, "B", "E"], + [25, "C", "F"], + ]; + + const tup_3: num_str_str_with_spread[] = [ + [tup_2[0], 250], + [tup_2[1], 250, 260], + [tup_2[0], 300, 300, 300], + ]; + + const sum = tup_3[0][1] + tup_3[1][1] + tup_3[1][2] + tup_3[2][1] + tup_3[2][2] + tup_3[2][3]; + assert(sum == 1660); + + // Runs correctly, but fails on verifier + // It sees the type of `tup_3[0][0]` as an `Object`, what it really is an Array type. + + // tup_3[0][0][0]++; + // assert(tup_3[0][0][0] == 14); + // tup_3[0][0][0] = 4; + // assert(tup_3[0][0][0] == 4); + + let int_update: [int] = [42]; + assert(int_update[0] == 42); + assert(int_update[0]++ == 42); + assert(int_update[0] == 43); + assert(++int_update[0] == 44); + int_update[0]++; + assert(int_update[0] == 45); + + let spread_tup: [Number, ...Number[]] = [6 as double,7 as double,8 as double, 9 as double, 10 as double]; + let num_arr: Number[] = [1 as double,2 as double,3 as double,4 as double,5 as double, 6 as double]; + + spread_tup = num_arr; + + let test_arr: Number[] = [1 as double,2 as double,3 as double,4 as double,5 as double, 6 as double]; + for(let idx = 0; idx < spread_tup.length; idx++){ + assert(spread_tup[idx] == test_arr[idx]); + } + + let tup_4: [number, number] = [11,2]; + let prim_num_arr: number[] = [3,4]; + + prim_num_arr = tup_4; + + let test_arr_2: number[] = [11, 2]; + for(let idx = 0; idx < prim_num_arr.length; idx++){ + assert(prim_num_arr[idx] == test_arr_2[idx]); + } + + let tup_8: [number, string][]; + tup_8 = [[1, "E"], [2, "F"], [3, "G"]]; + assert(tup_8[0][0] == 1 && tup_8[0][1] == "E"); + assert(tup_8[1][0] == 2 && tup_8[1][1] == "F"); + assert(tup_8[2][0] == 3 && tup_8[2][1] == "G"); + + let tup_10: [number, int, string, boolean, Object] = [1, 2, "I", false, new Object()]; + let var_float: float = tup_10[1]; + let var_float_2: float = 2.0; + assert(var_float == var_float_2); + + let tup_11: [int, number, string, boolean, Object] = [6, 7, "J", true, 789]; + // NOTE: Bug in op_assignment lowering (removes const from property) + // tup_11[0] += new Short(2 as short); + // assert(tup_11[0] == 8); + assert(tup_11[4] == (789 as Object)); + + let tup_12: [number, ...number[]] = [1, 2, 3, 4]; + try { + tup_12[4]; + } catch (e: ArrayIndexOutOfBoundsException) { + } catch (f) { + assert(false); + } + + let tup_13: [number, number] = [8, 9]; + let tup_14: [number, number] = [10, 11]; + + tup_13 = tup_14; + assert(tup_13[0] == 10); + assert(tup_13[1] == 11); + tup_13[0] = 12; + tup_13[1] = Double.valueOf(13.0); + assert(tup_13[0] == 12); + assert(tup_13[1] == 13); + + let a_b_tup: [A, A, B] = [new A(), new B(), new B()]; + assert(a_b_tup[0].foo() == 1); + assert(a_b_tup[1].foo() == 2); + assert(a_b_tup[2].foo() == 2); +}