From 33613e786499be98dbf7f9f29a017706855a7d63 Mon Sep 17 00:00:00 2001 From: Vsevolod Pukhov Date: Mon, 13 Nov 2023 21:02:32 +0300 Subject: [PATCH] Support nullish types and 'undefined' value * Support undefined type and literal * Complete nullish values handling in "o?.m" "l??r" "c?.()" "e!" "instanceof" * Generate specific bytecode based on type nullability * Add missing nullish CTEs in checker and relax them with runtime checks * Use undefined as optional parameter value * Refine relations and casts for primitives in unions * Fix bad uses of ApplyConversion and acc. types in etsg Issue:I8GI02 Signed-off-by: Vsevolod Pukhov Change-Id: I1c1153803359bb5cc7defcd427b0addb581c5cab --- .gitignore | 2 + ets2panda/BUILD.gn | 1 + ets2panda/CMakeLists.txt | 1 + ets2panda/checker/ETSAnalyzer.cpp | 7 + ets2panda/checker/ETSchecker.cpp | 5 + ets2panda/checker/ETSchecker.h | 17 +- ets2panda/checker/TSAnalyzer.cpp | 7 + ets2panda/checker/checker.cpp | 2 +- ets2panda/checker/ets/arithmetic.cpp | 41 +- ets2panda/checker/ets/boxingConverter.cpp | 81 +- ets2panda/checker/ets/boxingConverter.h | 6 +- ets2panda/checker/ets/function.cpp | 1 + ets2panda/checker/ets/helpers.cpp | 167 +- ets2panda/checker/ets/object.cpp | 46 +- ets2panda/checker/ets/typeCreation.cpp | 10 +- ets2panda/checker/ts/helpers.cpp | 4 +- ets2panda/checker/types/ets/etsArrayType.cpp | 10 +- .../checker/types/ets/etsDynamicType.cpp | 8 +- ets2panda/checker/types/ets/etsDynamicType.h | 6 +- ets2panda/checker/types/ets/etsObjectType.cpp | 49 +- ets2panda/checker/types/ets/etsObjectType.h | 3 +- ets2panda/checker/types/ets/etsStringType.cpp | 6 + ets2panda/checker/types/ets/etsStringType.h | 5 +- ets2panda/checker/types/ets/etsUnionType.cpp | 47 +- ets2panda/checker/types/ets/etsUnionType.h | 2 + ets2panda/checker/types/ets/intType.cpp | 2 +- ets2panda/checker/types/globalTypesHolder.cpp | 11 + ets2panda/checker/types/globalTypesHolder.h | 2 + ets2panda/checker/types/type.cpp | 30 +- ets2panda/checker/types/type.h | 7 +- ets2panda/checker/types/typeFlag.h | 9 +- ets2panda/compiler/base/condition.cpp | 2 +- ets2panda/compiler/base/literals.h | 6 + ets2panda/compiler/base/lreference.cpp | 4 +- ets2panda/compiler/core/ETSCompiler.cpp | 10 +- ets2panda/compiler/core/ETSGen.cpp | 309 ++- ets2panda/compiler/core/ETSGen.h | 133 +- ets2panda/compiler/core/JSCompiler.cpp | 7 + .../compiler/lowering/ets/unionLowering.cpp | 72 +- ets2panda/ir/astDump.cpp | 4 + ets2panda/ir/astDump.h | 13 +- ets2panda/ir/astNode.h | 9 +- ets2panda/ir/astNodeFlags.h | 9 +- ets2panda/ir/astNodeMapping.h | 1 + ets2panda/ir/base/catchClause.cpp | 2 +- ets2panda/ir/base/classDefinition.cpp | 4 +- ets2panda/ir/base/scriptFunction.cpp | 2 +- ets2panda/ir/ets/etsTypeReference.cpp | 9 +- ets2panda/ir/ets/etsUnionType.cpp | 2 + ets2panda/ir/expression.h | 42 + .../ir/expressions/assignmentExpression.cpp | 9 +- ets2panda/ir/expressions/awaitExpression.cpp | 2 +- ets2panda/ir/expressions/binaryExpression.cpp | 43 +- ets2panda/ir/expressions/callExpression.cpp | 52 +- ets2panda/ir/expressions/callExpression.h | 6 +- .../ir/expressions/conditionalExpression.cpp | 4 + ets2panda/ir/expressions/identifier.cpp | 7 - .../ir/expressions/literals/stringLiteral.cpp | 1 + .../expressions/literals/undefinedLiteral.cpp | 53 + .../expressions/literals/undefinedLiteral.h | 36 + ets2panda/ir/expressions/memberExpression.cpp | 296 +-- ets2panda/ir/expressions/memberExpression.h | 27 +- ets2panda/ir/expressions/superExpression.cpp | 3 +- ets2panda/ir/expressions/unaryExpression.cpp | 2 +- ets2panda/ir/expressions/updateExpression.cpp | 3 +- ets2panda/ir/expressions/yieldExpression.cpp | 2 +- ets2panda/ir/module/exportAllDeclaration.cpp | 2 +- .../ir/module/exportNamedDeclaration.cpp | 4 +- ets2panda/ir/statements/assertStatement.cpp | 14 +- ets2panda/ir/statements/breakStatement.cpp | 2 +- ets2panda/ir/statements/continueStatement.cpp | 2 +- .../ir/statements/forUpdateStatement.cpp | 6 +- ets2panda/ir/statements/ifStatement.cpp | 2 +- ets2panda/ir/statements/returnStatement.cpp | 2 +- .../ir/statements/switchCaseStatement.cpp | 2 +- ets2panda/ir/statements/tryStatement.cpp | 2 +- .../ir/statements/variableDeclarator.cpp | 3 +- ets2panda/ir/ts/tsAsExpression.cpp | 4 +- ets2panda/ir/ts/tsNonNullExpression.cpp | 21 +- ets2panda/ir/ts/tsTypePredicate.cpp | 2 +- ets2panda/lexer/scripts/keywords.yaml | 1 + ets2panda/lexer/token/token.cpp | 1 - ets2panda/lexer/token/tokenType.h | 1 - ets2panda/parser/ETSparser.cpp | 138 +- ets2panda/parser/ETSparser.h | 3 +- ets2panda/parser/expressionParser.cpp | 14 + ets2panda/parser/parserImpl.h | 1 + .../ets/generic_arrayaslist-expected.txt | 957 +++---- .../ets/generics_instantiation_2-expected.txt | 500 ++-- .../ets/generics_instantiation_4-expected.txt | 500 ++-- .../n_nullableTypeInArgNotRef-expected.txt | 72 +- .../n_nullableTypeInReturnNotRef-expected.txt | 19 +- .../ets/n_nullableTypeNotRef-expected.txt | 19 +- .../ets/optionalLambdaParameter-expected.txt | 65 +- .../ets/parenthesizedType-expected.txt | 53 +- .../compiler/ets/union_types_4-expected.txt | 54 +- ets2panda/test/compiler/ets/union_types_4.ets | 4 +- .../parser/ets/AccessBinaryTrees-expected.txt | 212 +- .../ets/arrayHoldingNullValue-expected.txt | 209 +- .../parser/ets/async_function-expected.txt | 500 ++-- .../parser/ets/async_overload-expected.txt | 606 ++--- .../parser/ets/async_with_lambda-expected.txt | 375 ++- .../parser/ets/await_keyword-expected.txt | 1000 ++++--- .../test/parser/ets/binary_op-expected.txt | 53 +- ...ableFromFunctionToNonNullable-expected.txt | 53 +- ...ableFromMethodToNullableParam-expected.txt | 106 +- ...n_assignNullableToNonNullable-expected.txt | 53 +- ...ignNullableToNonNullableArray-expected.txt | 61 +- ...ullableToNonNullableTypeAlias-expected.txt | 53 +- ...callFunctionWithNullableParam-expected.txt | 53 +- ...erfaceMethodWithNullableParam-expected.txt | 53 +- ...n_callMethodWithNullableParam-expected.txt | 53 +- .../ets/n_overrideWithNullable-expected.txt | 106 +- .../n_returnNullableFromFunction-expected.txt | 53 +- .../n_returnNullableFromMethod-expected.txt | 53 +- ets2panda/test/parser/ets/null-expected.txt | 1243 +++------ ets2panda/test/parser/ets/null.ets | 12 +- .../test/parser/ets/null_valid-expected.txt | 53 +- .../test/parser/ets/nullableType-expected.txt | 2308 ++++++----------- ets2panda/test/runtime/ets/DefaultParam_2.ets | 24 +- ets2panda/test/runtime/ets/DefaultParam_4.ets | 24 +- .../test/runtime/ets/NullishComparison.ets | 46 + .../test/runtime/ets/NullishConditionals.ets | 34 + .../test/runtime/ets/NullishInstanceof.ets | 85 + ets2panda/test/runtime/ets/OptionalCall.ets | 43 + ets2panda/test/runtime/ets/class-init.ets | 2 +- .../ets/optional-chaining-lazy-evaluation.ets | 2 +- ets2panda/test/runtime/ets/struct-init.ets | 2 +- ets2panda/test/union_types_4-expected.txt | 0 ets2panda/util/declgenEts2Ts.cpp | 24 +- ets2panda/util/declgenEts2Ts.h | 1 + ets2panda/util/helpers.cpp | 6 + 132 files changed, 5208 insertions(+), 6604 deletions(-) create mode 100644 ets2panda/ir/expressions/literals/undefinedLiteral.cpp create mode 100644 ets2panda/ir/expressions/literals/undefinedLiteral.h create mode 100644 ets2panda/test/runtime/ets/NullishComparison.ets create mode 100644 ets2panda/test/runtime/ets/NullishConditionals.ets create mode 100644 ets2panda/test/runtime/ets/NullishInstanceof.ets create mode 100644 ets2panda/test/runtime/ets/OptionalCall.ets create mode 100644 ets2panda/test/union_types_4-expected.txt diff --git a/.gitignore b/.gitignore index c856180cc4..d0f42167db 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ ets2panda/linter*/**/.cache ets2panda/linter*/test/**/results ets2panda/linter*/test_rules/**/results ets2panda/linter*/**/package-lock.json +**/compile_commands.json +.cache diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 9b136af98d..26f273d668 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -218,6 +218,7 @@ libes2panda_sources = [ "ir/expressions/literals/numberLiteral.cpp", "ir/expressions/literals/regExpLiteral.cpp", "ir/expressions/literals/stringLiteral.cpp", + "ir/expressions/literals/undefinedLiteral.cpp", "ir/expressions/memberExpression.cpp", "ir/expressions/newExpression.cpp", "ir/expressions/objectExpression.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 10bf1f40a6..75f77a2394 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -182,6 +182,7 @@ set(ES2PANDA_LIB_SRC ir/expressions/literals/numberLiteral.cpp ir/expressions/literals/regExpLiteral.cpp ir/expressions/literals/stringLiteral.cpp + ir/expressions/literals/undefinedLiteral.cpp ir/expressions/memberExpression.cpp ir/expressions/newExpression.cpp ir/expressions/objectExpression.cpp diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 2efdf0aa7d..ec729cf229 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -549,6 +549,13 @@ checker::Type *ETSAnalyzer::Check(ir::StringLiteral *expr) const (void)expr; UNREACHABLE(); } + +checker::Type *ETSAnalyzer::Check(ir::UndefinedLiteral *expr) const +{ + (void)expr; + UNREACHABLE(); +} + // compile methods for MODULE-related nodes in alphabetical order checker::Type *ETSAnalyzer::Check(ir::ExportAllDeclaration *st) const { diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index b3271a635d..4d5cfde2fe 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -206,6 +206,11 @@ Type *ETSChecker::GlobalETSNullType() const return GetGlobalTypesHolder()->GlobalETSNullType(); } +Type *ETSChecker::GlobalETSUndefinedType() const +{ + return GetGlobalTypesHolder()->GlobalETSUndefinedType(); +} + Type *ETSChecker::GlobalETSStringLiteralType() const { return GetGlobalTypesHolder()->GlobalETSStringLiteralType(); diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index f1eda74ff4..756489ee87 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -96,6 +96,7 @@ public: Type *GlobalETSBooleanType() const; Type *GlobalVoidType() const; Type *GlobalETSNullType() const; + Type *GlobalETSUndefinedType() const; Type *GlobalETSStringLiteralType() const; Type *GlobalWildcardType() const; @@ -136,7 +137,6 @@ public: const lexer::SourcePosition &pos); void ResolveDeclaredMembersOfObject(ETSObjectType *type); Type *ValidateArrayIndex(ir::Expression *expr); - Type *CheckArrayElementAccess(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); @@ -230,6 +230,8 @@ public: lexer::TokenType operation_type, lexer::SourcePosition pos, checker::Type *left_type, checker::Type *right_type, Type *unboxed_l, Type *unboxed_r); + std::tuple CheckBinaryOperatorEqualDynamic(ir::Expression *left, ir::Expression *right, + lexer::SourcePosition pos); std::tuple CheckBinaryOperatorLessGreater(ir::Expression *left, ir::Expression *right, lexer::TokenType operation_type, lexer::SourcePosition pos, bool is_equal_op, @@ -392,7 +394,7 @@ public: Type *GetTypeFromEnumReference(varbinder::Variable *var); Type *GetTypeFromTypeParameterReference(varbinder::LocalVariable *var, const lexer::SourcePosition &pos); Type *GetNonConstantTypeFromPrimitiveType(Type *type); - bool IsNullOrVoidExpression(const ir::Expression *expr) const; + bool IsNullLikeOrVoidExpression(const ir::Expression *expr) const; bool IsConstantExpression(ir::Expression *expr, Type *type); void ValidateUnaryOperatorOperand(varbinder::Variable *variable); std::tuple ApplyBinaryOperatorPromotion(Type *left, Type *right, TypeFlag test, @@ -406,6 +408,12 @@ public: checker::Type *CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *type_annotation, ir::Expression *init, ir::ModifierFlags flags); void CheckTruthinessOfType(ir::Expression *expr); + Type *CreateNullishType(Type *otype, checker::TypeFlag nullish_flags, ArenaAllocator *allocator, + TypeRelation *relation, GlobalTypesHolder *global_types); + void CheckNonNullishType(Type *type, lexer::SourcePosition line_info); + Type *CreateOptionalResultType(Type *type); + Type *GetNonNullishType(Type *type) const; + const Type *GetNonNullishType(const Type *type) const; void ConcatConstantString(util::UString &target, Type *type); Type *HandleStringConcatenation(Type *left_type, Type *right_type); Type *ResolveIdentifier(ir::Identifier *ident); @@ -469,8 +477,9 @@ public: util::StringView GetHashFromSubstitution(const Substitution *substitution); ETSObjectType *GetOriginalBaseType(Type *object); Type *GetTypeFromTypeAnnotation(ir::TypeNode *type_annotation); - void AddNullParamsForDefaultParams(const Signature *signature, - ArenaVector &arguments, ETSChecker *checker); + void AddUndefinedParamsForDefaultParams(const Signature *signature, + ArenaVector &arguments, + ETSChecker *checker); void SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpression *expr, Type *annotation_type); bool ExtensionETSFunctionType(checker::Type *type); diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 7f6acbba2a..d3e96e821f 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -446,6 +446,13 @@ checker::Type *TSAnalyzer::Check(ir::StringLiteral *expr) const (void)expr; UNREACHABLE(); } + +checker::Type *TSAnalyzer::Check(ir::UndefinedLiteral *expr) const +{ + (void)expr; + UNREACHABLE(); +} + // compile methods for MODULE-related nodes in alphabetical order checker::Type *TSAnalyzer::Check(ir::ExportAllDeclaration *st) const { diff --git a/ets2panda/checker/checker.cpp b/ets2panda/checker/checker.cpp index 292edd9efc..693548efa5 100644 --- a/ets2panda/checker/checker.cpp +++ b/ets2panda/checker/checker.cpp @@ -198,7 +198,7 @@ bool Checker::AreTypesComparable(Type *source, Type *target) bool Checker::IsTypeEqualityComparableTo(Type *source, Type *target) { - return target->HasTypeFlag(TypeFlag::NULLABLE) || IsTypeComparableTo(source, target); + return target->IsNullish() || IsTypeComparableTo(source, target); } parser::Program *Checker::Program() const diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index 9cb2bdbe06..c78ac64ba9 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -317,6 +317,10 @@ std::tuple ETSChecker::CheckBinaryOperatorEqual( return {ts_type, left_type}; } + if (left_type->IsETSDynamicType() || right_type->IsETSDynamicType()) { + return CheckBinaryOperatorEqualDynamic(left, right, pos); + } + if (IsReferenceType(left_type) && IsReferenceType(right_type)) { ts_type = GlobalETSBooleanType(); auto *op_type = GlobalETSObjectType(); @@ -342,6 +346,30 @@ std::tuple ETSChecker::CheckBinaryOperatorEqual( return {nullptr, nullptr}; } +std::tuple ETSChecker::CheckBinaryOperatorEqualDynamic(ir::Expression *left, ir::Expression *right, + lexer::SourcePosition pos) +{ + // NOTE: vpukhov. enforce intrinsic call in any case? + // canonicalize + auto *const dyn_exp = left->TsType()->IsETSDynamicType() ? left : right; + auto *const other_exp = dyn_exp == left ? right : left; + + if (other_exp->TsType()->IsETSDynamicType()) { + return {GlobalETSBooleanType(), GlobalBuiltinJSValueType()}; + } + if (dyn_exp->TsType()->AsETSDynamicType()->IsConvertibleTo(other_exp->TsType())) { + // NOTE: vpukhov. boxing flags are not set in dynamic values + return {GlobalETSBooleanType(), other_exp->TsType()}; + } + if (other_exp->TsType()->IsETSObjectType()) { + // have to prevent casting dyn_exp via ApplyCast without nullish flag + auto *nullish_obj = CreateNullishType(GlobalETSObjectType(), checker::TypeFlag::NULLISH, Allocator(), + Relation(), GetGlobalTypesHolder()); + return {GlobalETSBooleanType(), nullish_obj}; + } + ThrowTypeError("Unimplemented case in dynamic type comparison.", pos); +} + std::tuple ETSChecker::CheckBinaryOperatorLessGreater( ir::Expression *left, ir::Expression *right, lexer::TokenType operation_type, lexer::SourcePosition pos, bool is_equal_op, checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) @@ -405,14 +433,13 @@ Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, le ThrowTypeError("Left-hand side expression must be a reference type.", pos); } - checker::Type *non_nullable_left_type = left_type; + checker::Type *non_nullish_left_type = left_type; - if (left_type->IsNullableType()) { - non_nullable_left_type = left_type->Instantiate(Allocator(), Relation(), GetGlobalTypesHolder()); - non_nullable_left_type->RemoveTypeFlag(TypeFlag::NULLABLE); + if (left_type->IsNullish()) { + non_nullish_left_type = GetNonNullishType(left_type); } - // NOTE: check convertibility and use numeric promotion + // NOTE: vpukhov. check convertibility and use numeric promotion if (right_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { Relation()->SetNode(right); @@ -421,10 +448,10 @@ Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, le ThrowTypeError("Invalid right-hand side expression", pos); } right->AddBoxingUnboxingFlag(GetBoxingFlag(boxed_right_type)); - return FindLeastUpperBound(non_nullable_left_type, boxed_right_type); + return FindLeastUpperBound(non_nullish_left_type, boxed_right_type); } - return FindLeastUpperBound(non_nullable_left_type, right_type); + return FindLeastUpperBound(non_nullish_left_type, right_type); } // NOLINTNEXTLINE(readability-function-size) diff --git a/ets2panda/checker/ets/boxingConverter.cpp b/ets2panda/checker/ets/boxingConverter.cpp index 71960110b3..dc111fd1cd 100644 --- a/ets2panda/checker/ets/boxingConverter.cpp +++ b/ets2panda/checker/ets/boxingConverter.cpp @@ -21,56 +21,41 @@ namespace panda::es2panda::checker { -void BoxingConverter::ETSTypeFromSource(Type *source) +checker::ETSObjectType *BoxingConverter::ETSTypeFromSource(ETSChecker const *checker, Type const *source) { - auto type_kind = checker::ETSChecker::TypeKind(source); + auto get_signature = [](checker::TypeFlag type_kind) { + switch (type_kind) { + case checker::TypeFlag::ETS_BOOLEAN: { + return compiler::Signatures::BUILTIN_BOOLEAN_CLASS; + } + case checker::TypeFlag::BYTE: { + return compiler::Signatures::BUILTIN_BYTE_CLASS; + } + case checker::TypeFlag::SHORT: { + return compiler::Signatures::BUILTIN_SHORT_CLASS; + } + case checker::TypeFlag::CHAR: { + return compiler::Signatures::BUILTIN_CHAR_CLASS; + } + case checker::TypeFlag::INT: { + return compiler::Signatures::BUILTIN_INT_CLASS; + } + case checker::TypeFlag::LONG: { + return compiler::Signatures::BUILTIN_LONG_CLASS; + } + case checker::TypeFlag::FLOAT: { + return compiler::Signatures::BUILTIN_FLOAT_CLASS; + } + case checker::TypeFlag::DOUBLE: { + return compiler::Signatures::BUILTIN_DOUBLE_CLASS; + } + default: + UNREACHABLE(); + } + }; - auto wrap_map = Checker()->PrimitiveWrapper(); - - switch (type_kind) { - case checker::TypeFlag::ETS_BOOLEAN: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_BOOLEAN_CLASS); - SetResult(res->second.first); - break; - } - case checker::TypeFlag::BYTE: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_BYTE_CLASS); - SetResult(res->second.first); - break; - } - case checker::TypeFlag::SHORT: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_SHORT_CLASS); - SetResult(res->second.first); - break; - } - case checker::TypeFlag::CHAR: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_CHAR_CLASS); - SetResult(res->second.first); - break; - } - case checker::TypeFlag::INT: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_INT_CLASS); - SetResult(res->second.first); - break; - } - case checker::TypeFlag::LONG: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_LONG_CLASS); - SetResult(res->second.first); - break; - } - case checker::TypeFlag::FLOAT: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_FLOAT_CLASS); - SetResult(res->second.first); - break; - } - case checker::TypeFlag::DOUBLE: { - auto res = wrap_map.find(compiler::Signatures::BUILTIN_DOUBLE_CLASS); - SetResult(res->second.first); - break; - } - default: - UNREACHABLE(); - } + auto wrap_map = checker->PrimitiveWrapper(); + return wrap_map.find(get_signature(checker::ETSChecker::TypeKind(source)))->second.first; } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ets/boxingConverter.h b/ets2panda/checker/ets/boxingConverter.h index 13ccc675ed..8c142419c6 100644 --- a/ets2panda/checker/ets/boxingConverter.h +++ b/ets2panda/checker/ets/boxingConverter.h @@ -32,7 +32,7 @@ public: return; } - ETSTypeFromSource(source); + SetResult(ETSTypeFromSource(checker, source)); Relation()->Result(true); } @@ -50,12 +50,12 @@ public: return; } - ETSTypeFromSource(source); + SetResult(ETSTypeFromSource(checker, source)); Relation()->Result(relation->IsAssignableTo(Result(), target)); } - void ETSTypeFromSource(Type *source); + static checker::ETSObjectType *ETSTypeFromSource(ETSChecker const *checker, Type const *source); }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index f2fb7931da..7e6538ad77 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -1256,6 +1256,7 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio Allocator()->New(Allocator(), class_scope, ident_node, std::move(properties), ir::ClassDefinitionModifiers::DECLARATION, Language(Language::Id::ETS)); lambda->SetResolvedLambda(lambda_object); + lambda->SetTsType(functional_interface); lambda_object->SetParent(current_class_def); // if we should save 'this', then propagate this information to the lambda node, so when we are compiling it, diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index ad63b23608..b1f99ba5be 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -42,6 +42,7 @@ #include "ir/expressions/assignmentExpression.h" #include "ir/expressions/arrowFunctionExpression.h" #include "ir/expressions/literals/numberLiteral.h" +#include "ir/expressions/literals/undefinedLiteral.h" #include "ir/expressions/literals/nullLiteral.h" #include "ir/statements/labelledStatement.h" #include "ir/statements/tryStatement.h" @@ -84,6 +85,74 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) expr->SetTsType(unboxed_type); } +// NOTE: vpukhov. this entire function is isolated work-around until nullish type are not unions +Type *ETSChecker::CreateNullishType(Type *type, checker::TypeFlag nullish_flags, ArenaAllocator *allocator, + TypeRelation *relation, GlobalTypesHolder *global_types) +{ + ASSERT((nullish_flags & ~TypeFlag::NULLISH) == 0); + + auto *const nullish = type->Instantiate(allocator, relation, global_types); + + // Doesnt work for primitive array types, because instantiated type is equal to original one + + if ((nullish_flags & TypeFlag::NULL_TYPE) != 0) { + nullish->AddTypeFlag(checker::TypeFlag::NULL_TYPE); + } + if ((nullish_flags & TypeFlag::UNDEFINED) != 0) { + nullish->AddTypeFlag(checker::TypeFlag::UNDEFINED); + if (nullish->IsETSObjectType()) { + nullish->AsETSObjectType()->SetAssemblerName(GlobalETSObjectType()->AssemblerName()); + } + } + ASSERT(!nullish->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)); + return nullish; +} + +void ETSChecker::CheckNonNullishType([[maybe_unused]] Type *type, [[maybe_unused]] lexer::SourcePosition line_info) +{ + // NOTE: vpukhov. enable check when type inference is implemented + (void)type; +} + +// NOTE: vpukhov. rewrite with union types +Type *ETSChecker::GetNonNullishType(Type *type) const +{ + if (type->IsETSArrayType()) { + return type; // give up + } + + while (type->IsNullish()) { + type = type->AsETSObjectType()->GetBaseType(); + ASSERT(type != nullptr); + } + return type; +} + +// NOTE: vpukhov. rewrite with union types +const Type *ETSChecker::GetNonNullishType(const Type *type) const +{ + if (type->IsETSArrayType()) { + return type; // give up + } + + while (type->IsNullish()) { + type = type->AsETSObjectType()->GetBaseType(); + ASSERT(type != nullptr); + } + return type; +} + +Type *ETSChecker::CreateOptionalResultType(Type *type) +{ + if (type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + type = PrimitiveTypeAsETSBuiltinType(type); + ASSERT(type->IsETSObjectType()); + Relation()->GetNode()->AddBoxingUnboxingFlag(GetBoxingFlag(type)); + } + + return CreateNullishType(type, checker::TypeFlag::UNDEFINED, Allocator(), Relation(), GetGlobalTypesHolder()); +} + bool ETSChecker::IsConstantExpression(ir::Expression *expr, Type *type) { return (type->HasTypeFlag(TypeFlag::CONSTANT) && (expr->IsIdentifier() || expr->IsMemberExpression())); @@ -92,6 +161,8 @@ bool ETSChecker::IsConstantExpression(ir::Expression *expr, Type *type) Type *ETSChecker::GetNonConstantTypeFromPrimitiveType(Type *type) { if (type->IsETSStringType()) { + // NOTE: vpukhov. remove when nullish types are unions + ASSERT(!type->IsNullish()); return GlobalBuiltinETSStringType(); } @@ -99,6 +170,9 @@ Type *ETSChecker::GetNonConstantTypeFromPrimitiveType(Type *type) return type; } + // NOTE: vpukhov. remove when nullish types are unions + ASSERT(!type->IsNullish()); + if (type->HasTypeFlag(TypeFlag::LONG)) { return GlobalLongType(); } @@ -661,25 +735,19 @@ Type *ETSChecker::ApplyUnaryOperatorPromotion(Type *type, const bool create_cons return unboxed_type; } -bool ETSChecker::IsNullOrVoidExpression(const ir::Expression *expr) const +bool ETSChecker::IsNullLikeOrVoidExpression(const ir::Expression *expr) const { - return (expr->IsLiteral() && expr->AsLiteral()->IsNullLiteral()) || - (expr->IsCallExpression() && - (expr->AsCallExpression()->Signature()->ReturnType() == GlobalBuiltinVoidType())); + return expr->TsType()->IsETSNullLike() || expr->TsType()->IsETSVoidType(); } Type *ETSChecker::HandleBooleanLogicalOperatorsExtended(Type *left_type, Type *right_type, ir::BinaryExpression *expr) { ASSERT(left_type->IsConditionalExprType() && right_type->IsConditionalExprType()); - bool resolve_left = false; - bool left_value = false; - bool resolve_right = false; - bool right_value = false; - std::tie(resolve_left, left_value) = - IsNullOrVoidExpression(expr->Left()) ? std::make_tuple(true, false) : left_type->ResolveConditionExpr(); - std::tie(resolve_right, right_value) = - IsNullOrVoidExpression(expr->Right()) ? std::make_tuple(true, false) : right_type->ResolveConditionExpr(); + auto [resolve_left, left_value] = + IsNullLikeOrVoidExpression(expr->Left()) ? std::make_tuple(true, false) : left_type->ResolveConditionExpr(); + auto [resolve_right, right_value] = + IsNullLikeOrVoidExpression(expr->Right()) ? std::make_tuple(true, false) : right_type->ResolveConditionExpr(); if (!resolve_left) { // return the UNION type when it is implemented @@ -840,24 +908,32 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T annotation_type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { binding_var->SetTsType(init->TsType()); } - } else { - if (init_type->IsETSNullType()) { - auto *const nullable_object_type = GetGlobalTypesHolder()->GlobalETSObjectType()->Instantiate( - Allocator(), Relation(), GetGlobalTypesHolder()); + return binding_var->TsType(); + } - nullable_object_type->AddTypeFlag(TypeFlag::NULLABLE); + if (init_type->IsETSNullLike()) { + TypeFlag nullish_flags {0}; - init_type = nullable_object_type; + if (init_type->IsETSNullType()) { + nullish_flags = TypeFlag::NULL_TYPE; } - - if (init_type->IsETSObjectType() && init_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::ENUM) && - !init->IsMemberExpression()) { - ThrowTypeError( - {"Cannot assign type '", init_type->AsETSObjectType()->Name(), "' for variable ", var_name, "."}, - init->Start()); + if (init_type->IsETSUndefinedType()) { + nullish_flags = TypeFlag::UNDEFINED; } + init_type = CreateNullishType(GetGlobalTypesHolder()->GlobalETSObjectType(), nullish_flags, Allocator(), + Relation(), GetGlobalTypesHolder()); + } - binding_var->SetTsType(is_const ? init_type : GetNonConstantTypeFromPrimitiveType(init_type)); + if (init_type->IsETSObjectType() && init_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::ENUM) && + !init->IsMemberExpression()) { + ThrowTypeError({"Cannot assign type '", init_type->AsETSObjectType()->Name(), "' for variable ", var_name, "."}, + init->Start()); + } + + if (init_type->IsNullish() || is_const) { + binding_var->SetTsType(init_type); + } else { + binding_var->SetTsType(GetNonConstantTypeFromPrimitiveType(init_type)); } return binding_var->TsType(); @@ -1264,7 +1340,7 @@ bool ETSChecker::IsTypeBuiltinType(Type *type) bool ETSChecker::IsReferenceType(const Type *type) { - return type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || type->IsETSNullType() || + return type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || type->IsETSNullLike() || type->IsETSStringType(); } @@ -1682,6 +1758,7 @@ void ETSChecker::CheckUnboxedTypeWidenable(TypeRelation *relation, Type *target, checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx( relation, TypeRelationFlag::ONLY_CHECK_WIDENING | (relation->ApplyNarrowing() ? TypeRelationFlag::NARROWING : TypeRelationFlag::NONE)); + // NOTE: vpukhov. handle union type auto unboxed_type = ETSBuiltinTypeAsPrimitiveType(target); if (unboxed_type == nullptr) { return; @@ -1959,19 +2036,26 @@ Type *ETSChecker::GetTypeFromTypeAnnotation(ir::TypeNode *const type_annotation) { auto *type = type_annotation->GetType(this); - if (type_annotation->IsNullable()) { - if (!type->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { - ThrowTypeError("Non reference types cannot be nullable.", type_annotation->Start()); - } + if (!type_annotation->IsNullAssignable() && !type_annotation->IsUndefinedAssignable()) { + return type; + } - if (!type->IsNullableType()) { - auto *const new_type = type->Instantiate(Allocator(), Relation(), GetGlobalTypesHolder()); - new_type->AddTypeFlag(TypeFlag::NULLABLE); - type = new_type; - } + if (!type->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { + ThrowTypeError("Non reference types cannot be nullish.", type_annotation->Start()); } - return type; + if (type->IsNullish()) { + return type; + } + + TypeFlag nullish_flags {0}; + if (type_annotation->IsNullAssignable()) { + nullish_flags |= TypeFlag::NULL_TYPE; + } + if (type_annotation->IsUndefinedAssignable()) { + nullish_flags |= TypeFlag::UNDEFINED; + } + return CreateNullishType(type, nullish_flags, Allocator(), Relation(), GetGlobalTypesHolder()); } void ETSChecker::CheckValidGenericTypeParameter(Type *const arg_type, const lexer::SourcePosition &pos) @@ -2103,9 +2187,9 @@ bool ETSChecker::TypeInference(Signature *signature, const ArenaVector &arguments, - ETSChecker *checker) +void ETSChecker::AddUndefinedParamsForDefaultParams(const Signature *const signature, + ArenaVector &arguments, + ETSChecker *checker) { if (!signature->Function()->IsDefaultParamProxy() || signature->Function()->Params().size() <= arguments.size()) { return; @@ -2123,9 +2207,10 @@ void ETSChecker::AddNullParamsForDefaultParams(const Signature *const signature, arguments.push_back(checker->Allocator()->New(lexer::Number(0))); } } else { + // A proxy-function is called, so default reference parameters + // are initialized with null instead of undefined auto *const null_literal = checker->Allocator()->New(); - checker::Type *const ts_type = checker->GlobalETSNullType(); - null_literal->SetTsType(ts_type); + null_literal->SetTsType(checker->GlobalETSNullType()); arguments.push_back(null_literal); } num |= (1U << (arguments.size() - 1)); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 9732a6e266..9ae05f1775 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -184,15 +184,16 @@ ArenaVector ETSChecker::CreateTypeForTypeParameters(ir::TSTypeParameterD Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) { + auto const instantiate_supertype = [this](TypeFlag nullish_flags) { + return CreateNullishType(GlobalETSObjectType(), nullish_flags, Allocator(), Relation(), GetGlobalTypesHolder()) + ->AsETSObjectType(); + }; + ETSObjectType *param_type = CreateNewETSObjectType(param->Name()->Name(), param, GlobalETSObjectType()->ObjectFlags()); param_type->SetAssemblerName(GlobalETSObjectType()->AssemblerName()); param_type->AddTypeFlag(TypeFlag::GENERIC); param_type->AddObjectFlag(ETSObjectFlags::TYPE_PARAMETER); - // We'll decide whether to make the supertype nullable after looking at constraint - ETSObjectType *maybe_nullable_object = - GlobalETSObjectType()->Instantiate(Allocator(), Relation(), GetGlobalTypesHolder())->AsETSObjectType(); - param_type->SetSuperType(maybe_nullable_object); param_type->SetVariable(param->Variable()); if (param->Constraint() != nullptr) { @@ -224,15 +225,13 @@ Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) param_type->SetAssemblerName(constraint_obj_type->AssemblerName()); if (constraint_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::INTERFACE)) { param_type->AddInterface(constraint_obj_type); + param_type->SetSuperType(instantiate_supertype(TypeFlag(TypeFlag::NULLISH & constraint_type->TypeFlags()))); } else { param_type->SetSuperType(constraint_obj_type); } - if (constraint_obj_type->IsNullableType()) { - param_type->SuperType()->AddTypeFlag(TypeFlag::NULLABLE); - } } else { - // No constraint, so it's Object|null - param_type->SuperType()->AddTypeFlag(TypeFlag::NULLABLE); + // No constraint, so it's Object|null|undefined + param_type->SetSuperType(instantiate_supertype(TypeFlag::NULLISH)); } SetTypeParameterType(param, param_type); @@ -895,31 +894,6 @@ Type *ETSChecker::ValidateArrayIndex(ir::Expression *expr) return index_type; } -Type *ETSChecker::CheckArrayElementAccess(ir::MemberExpression *expr) -{ - Type *array_type = expr->Object()->Check(this); - - if (!array_type->IsETSArrayType() && !array_type->IsETSDynamicType()) { - ThrowTypeError("Indexed access expression can only be used in array type.", expr->Object()->Start()); - } - - ValidateArrayIndex(expr->Property()); - - if (expr->Property()->IsIdentifier()) { - expr->SetPropVar(expr->Property()->AsIdentifier()->Variable()->AsLocalVariable()); - } else if (auto var = expr->Property()->Variable(); (var != nullptr) && var->IsLocalVariable()) { - expr->SetPropVar(var->AsLocalVariable()); - } - - // NOTE: apply capture conversion on this type - if (array_type->IsETSArrayType()) { - return array_type->AsETSArrayType()->ElementType(); - } - - // Dynamic - return GlobalBuiltinDynamicType(array_type->AsETSDynamicType()->Language()); -} - ETSObjectType *ETSChecker::CheckThisOrSuperAccess(ir::Expression *node, ETSObjectType *class_type, std::string_view msg) { if ((Context().Status() & CheckerStatus::IGNORE_VISIBILITY) != 0U) { @@ -1387,11 +1361,11 @@ Type *ETSChecker::GetCommonClass(Type *source, Type *target) } if (source->IsETSObjectType() && target->IsETSObjectType()) { - if (source->IsETSNullType()) { + if (source->IsETSNullLike()) { return target; } - if (target->IsETSNullType()) { + if (target->IsETSNullLike()) { return source; } diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 454e980ac2..03be8f6bda 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -109,7 +109,10 @@ ETSArrayType *ETSChecker::CreateETSArrayType(Type *element_type) } auto *array_type = Allocator()->New(element_type); - array_types_.insert({element_type, array_type}); + auto it = array_types_.insert({element_type, array_type}); + if (it.second && !element_type->IsTypeParameter()) { + CreateBuiltinArraySignature(array_type, array_type->Rank()); + } return array_type; } @@ -123,7 +126,7 @@ Type *ETSChecker::CreateETSUnionType(ArenaVector &&constituent_types) ArenaVector new_constituent_types(Allocator()->Adapter()); for (auto *it : constituent_types) { - if (it->IsUnionType()) { + if (it->IsETSUnionType()) { for (auto *type : it->AsETSUnionType()->ConstituentTypes()) { new_constituent_types.push_back(type); } @@ -131,7 +134,8 @@ Type *ETSChecker::CreateETSUnionType(ArenaVector &&constituent_types) continue; } - new_constituent_types.push_back(it); + new_constituent_types.push_back( + it->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) ? PrimitiveTypeAsETSBuiltinType(it) : it); } if (new_constituent_types.size() == 1) { diff --git a/ets2panda/checker/ts/helpers.cpp b/ets2panda/checker/ts/helpers.cpp index 5432a39ef0..7a75d4986e 100644 --- a/ets2panda/checker/ts/helpers.cpp +++ b/ets2panda/checker/ts/helpers.cpp @@ -132,8 +132,8 @@ Type *TSChecker::ExtractDefinitelyFalsyTypes(Type *type) return GlobalZeroBigintType(); } - if (type == GlobalFalseType() || type->HasTypeFlag(TypeFlag::NULLABLE) || - type->HasTypeFlag(TypeFlag::ANY_OR_UNKNOWN) || type->HasTypeFlag(TypeFlag::VOID) || + if (type == GlobalFalseType() || type->IsNullish() || type->HasTypeFlag(TypeFlag::ANY_OR_UNKNOWN) || + type->HasTypeFlag(TypeFlag::VOID) || (type->IsStringLiteralType() && IsTypeIdenticalTo(type, GlobalEmptyStringType())) || (type->IsNumberLiteralType() && IsTypeIdenticalTo(type, GlobalZeroType())) || (type->IsBigintLiteralType() && IsTypeIdenticalTo(type, GlobalZeroBigintType()))) { diff --git a/ets2panda/checker/types/ets/etsArrayType.cpp b/ets2panda/checker/types/ets/etsArrayType.cpp index 0dd1a3f2b3..5c2bdbac39 100644 --- a/ets2panda/checker/types/ets/etsArrayType.cpp +++ b/ets2panda/checker/types/ets/etsArrayType.cpp @@ -61,7 +61,7 @@ uint32_t ETSArrayType::Rank() const void ETSArrayType::Identical(TypeRelation *relation, Type *other) { - if (IsNullableType() != other->IsNullableType()) { + if ((ContainsNull() != other->ContainsNull()) || (ContainsUndefined() != other->ContainsUndefined())) { return; } @@ -78,11 +78,15 @@ void ETSArrayType::Identical(TypeRelation *relation, Type *other) void ETSArrayType::AssignmentTarget(TypeRelation *relation, Type *source) { if (source->IsETSNullType()) { - relation->Result(IsNullableType()); + relation->Result(ContainsNull()); + return; + } + if (source->IsETSUndefinedType()) { + relation->Result(ContainsUndefined()); return; } - if (source->IsNullableType() && !IsNullableType()) { + if ((source->ContainsNull() && !ContainsNull()) || (source->ContainsUndefined() && !ContainsUndefined())) { return; } diff --git a/ets2panda/checker/types/ets/etsDynamicType.cpp b/ets2panda/checker/types/ets/etsDynamicType.cpp index cbe881350a..f279b0a4ab 100644 --- a/ets2panda/checker/types/ets/etsDynamicType.cpp +++ b/ets2panda/checker/types/ets/etsDynamicType.cpp @@ -50,7 +50,7 @@ bool ETSDynamicType::AssignmentSource(TypeRelation *relation, Type *target) return ETSObjectType::AssignmentSource(relation, target); } - if (target->HasTypeFlag(checker::TypeFlag::ETS_TYPE_TO_DYNAMIC)) { + if (target->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) || target->IsETSStringType()) { relation->Result(true); } return relation->IsTrue(); @@ -67,15 +67,15 @@ void ETSDynamicType::Cast(TypeRelation *relation, Type *target) return; } - if (IsConvertableTo(target)) { + if (IsConvertibleTo(target)) { relation->Result(true); } } -bool ETSDynamicType::IsConvertableTo(Type *target) const +bool ETSDynamicType::IsConvertibleTo(Type *target) { return target->IsETSStringType() || target->IsLambdaObject() || target->IsETSDynamicType() || - target->HasTypeFlag(checker::TypeFlag::ETS_TYPE_TO_DYNAMIC | checker::TypeFlag::ETS_BOOLEAN); + target->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC | checker::TypeFlag::ETS_BOOLEAN); } ETSFunctionType *ETSDynamicType::CreateETSFunctionType(const util::StringView &name) const diff --git a/ets2panda/checker/types/ets/etsDynamicType.h b/ets2panda/checker/types/ets/etsDynamicType.h index 3e2475ca41..62b96ee6f9 100644 --- a/ets2panda/checker/types/ets/etsDynamicType.h +++ b/ets2panda/checker/types/ets/etsDynamicType.h @@ -31,8 +31,6 @@ public: AddTypeFlag(TypeFlag::ETS_DYNAMIC_TYPE); } - static bool IsDynamicType(util::StringView assembler_name); - varbinder::LocalVariable *GetPropertyDynamic(const util::StringView &name, const ETSChecker *checker) const; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; @@ -52,9 +50,9 @@ public: void ToAssemblerType(std::stringstream &ss) const override; -private: - bool IsConvertableTo(Type *target) const; + static bool IsConvertibleTo(Type *target); +private: mutable PropertyMap properties_cache_; es2panda::Language lang_; bool has_decl_; diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 6678a6f271..7d060c93c5 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -297,9 +297,14 @@ void ETSObjectType::ToString(std::stringstream &ss) const ss << compiler::Signatures::GENERIC_END; } - if (IsNullableType() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !name_.Is("null") && + if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && !name_.Empty()) { - ss << "|null"; + if (ContainsNull()) { + ss << "|null"; + } + if (ContainsUndefined()) { + ss << "|undefined"; + } } } @@ -327,7 +332,7 @@ void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other auto const other_type_arguments = other->AsETSObjectType()->TypeArguments(); - if (HasTypeFlag(TypeFlag::GENERIC) || IsNullableType()) { + if (HasTypeFlag(TypeFlag::GENERIC) || IsNullish()) { if (!HasTypeFlag(TypeFlag::GENERIC)) { relation->Result(true); return; @@ -379,7 +384,7 @@ void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other void ETSObjectType::Identical(TypeRelation *relation, Type *other) { - if (IsNullableType() != other->IsNullableType()) { + if ((ContainsNull() != other->ContainsNull()) || (ContainsUndefined() != other->ContainsUndefined())) { return; } IdenticalUptoNullability(relation, other); @@ -400,7 +405,8 @@ bool ETSObjectType::CheckIdenticalFlags(ETSObjectFlags target) const bool ETSObjectType::AssignmentSource(TypeRelation *const relation, Type *const target) { - relation->Result(IsETSNullType() && target->IsNullableType()); + relation->Result((IsETSNullType() && target->ContainsNull()) || + (IsETSUndefinedType() && target->ContainsUndefined())); return relation->IsTrue(); } @@ -408,11 +414,15 @@ bool ETSObjectType::AssignmentSource(TypeRelation *const relation, Type *const t void ETSObjectType::AssignmentTarget(TypeRelation *const relation, Type *source) { if (source->IsETSNullType()) { - relation->Result(IsNullableType()); + relation->Result(ContainsNull()); + return; + } + if (source->IsETSUndefinedType()) { + relation->Result(ContainsUndefined()); return; } - if (source->IsNullableType() && !IsNullableType()) { + if ((source->ContainsNull() && !ContainsNull()) || (source->ContainsUndefined() && !ContainsUndefined())) { return; } @@ -429,7 +439,7 @@ void ETSObjectType::AssignmentTarget(TypeRelation *const relation, Type *source) bool ETSObjectType::CastNumericObject(TypeRelation *const relation, Type *const target) { - if (this->IsNullableType()) { + if (this->IsNullish()) { return false; } @@ -569,7 +579,7 @@ void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) return; } - if (this->HasObjectFlag(ETSObjectFlags::NULL_TYPE)) { + if (this->IsETSNullLike()) { if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { relation->GetNode()->SetTsType(target); relation->Result(true); @@ -627,10 +637,9 @@ void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) return; } - if (!IsNullableType() && source->IsNullableType()) { + if ((!ContainsNull() && source->ContainsNull()) || (!ContainsUndefined() && source->ContainsUndefined())) { return; } - // All classes and interfaces are subtypes of Object if (base == ets_checker->GlobalETSObjectType()) { relation->Result(true); @@ -733,7 +742,7 @@ Type *ETSObjectType::Instantiate(ArenaAllocator *const allocator, TypeRelation * std::lock_guard guard {*checker->Mutex()}; auto *const base = GetOriginalBaseType(); - if (!relation->TypeInstantiationPossible(base) || IsETSNullType()) { + if (!relation->TypeInstantiationPossible(base) || IsETSNullLike()) { return this; } relation->IncreaseTypeRecursionCount(base); @@ -801,15 +810,15 @@ Type *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *subs /* Any other flags we need to copy? */ /* The check this != base is a kludge to distinguish bare type parameter T - with a nullable constraint (like the default Object|null) from explicitly nullable - T|null + with a nullish constraint (like the default Object?) from explicitly nullish T? */ - if (IsNullableType() && this != base && !repl_type->IsNullableType()) { - // this type is explicitly marked as nullable + if (this != base && ((ContainsNull() && !repl_type->ContainsNull()) || + (ContainsUndefined() && !repl_type->ContainsUndefined()))) { + // this type is explicitly marked as nullish ASSERT(repl_type->IsETSObjectType() || repl_type->IsETSArrayType() || repl_type->IsETSFunctionType()); - auto *new_repl_type = - repl_type->Instantiate(checker->Allocator(), relation, checker->GetGlobalTypesHolder()); - new_repl_type->AddTypeFlag(TypeFlag::NULLABLE); + auto nullish_flags = TypeFlag(TypeFlags() & TypeFlag::NULLISH); + auto *new_repl_type = checker->CreateNullishType(repl_type, nullish_flags, checker->Allocator(), relation, + checker->GetGlobalTypesHolder()); repl_type = new_repl_type; } return repl_type; @@ -836,7 +845,7 @@ Type *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *subs return inst; } - if ((!relation->TypeInstantiationPossible(base)) || IsETSNullType()) { + if (!relation->TypeInstantiationPossible(base) || IsETSNullLike()) { return this; } relation->IncreaseTypeRecursionCount(base); diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index 2f9f726d59..a083979f86 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -47,6 +47,7 @@ enum class ETSObjectFlags : uint32_t { ASYNC_FUNC_RETURN_TYPE = 1U << 17U, TYPE_PARAMETER = 1U << 18U, CHECKED_INVOKE_LEGITIMACY = 1U << 19U, + UNDEFINED_TYPE = 1U << 20U, BUILTIN_STRING = 1U << 23U, BUILTIN_BOOLEAN = 1U << 24U, @@ -511,7 +512,7 @@ public: std::tuple ResolveConditionExpr() const override { - if (IsNullableType() || IsETSStringType()) { + if (IsNullish() || IsETSStringType()) { return {false, false}; } diff --git a/ets2panda/checker/types/ets/etsStringType.cpp b/ets2panda/checker/types/ets/etsStringType.cpp index 0528fd46ff..0cc0833e24 100644 --- a/ets2panda/checker/types/ets/etsStringType.cpp +++ b/ets2panda/checker/types/ets/etsStringType.cpp @@ -25,6 +25,12 @@ void ETSStringType::Identical(TypeRelation *relation, Type *other) } } +bool ETSStringType::AssignmentSource([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *target) +{ + relation->Result(target->IsETSStringType()); + return relation->IsTrue(); +} + void ETSStringType::AssignmentTarget([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *source) { if (source->IsETSStringType()) { diff --git a/ets2panda/checker/types/ets/etsStringType.h b/ets2panda/checker/types/ets/etsStringType.h index acf4e3e4b9..e15593ce7a 100644 --- a/ets2panda/checker/types/ets/etsStringType.h +++ b/ets2panda/checker/types/ets/etsStringType.h @@ -25,6 +25,7 @@ public: : ETSObjectType(allocator, ETSObjectFlags::CLASS | ETSObjectFlags::STRING | ETSObjectFlags::RESOLVED_SUPER) { SetSuperType(super); + SetAssemblerName(compiler::Signatures::BUILTIN_STRING); } explicit ETSStringType(ArenaAllocator *allocator, ETSObjectType *super, util::StringView value) @@ -32,11 +33,13 @@ public: value_(value) { SetSuperType(super); + SetAssemblerName(compiler::Signatures::BUILTIN_STRING); AddTypeFlag(TypeFlag::CONSTANT); variable_ = super->Variable(); } void Identical(TypeRelation *relation, Type *other) override; + bool AssignmentSource(TypeRelation *relation, Type *target) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *global_types) override; @@ -57,7 +60,7 @@ public: std::tuple ResolveConditionExpr() const override { - if (IsNullableType()) { + if (IsNullish()) { return {false, false}; } diff --git a/ets2panda/checker/types/ets/etsUnionType.cpp b/ets2panda/checker/types/ets/etsUnionType.cpp index 869bce16fe..cca516221f 100644 --- a/ets2panda/checker/types/ets/etsUnionType.cpp +++ b/ets2panda/checker/types/ets/etsUnionType.cpp @@ -86,16 +86,16 @@ bool ETSUnionType::AssignmentSource(TypeRelation *relation, Type *target) void ETSUnionType::AssignmentTarget(TypeRelation *relation, Type *source) { - // For an unsorted constituent_types_, a less suitable type may first come across than it could be - // if the entire array of constituent types was analyzed. - for (auto *it : constituent_types_) { - if (!source->IsETSObjectType() && (source->HasTypeFlag(it->TypeFlags()) || it == source)) { - relation->IsAssignableTo(source, it); - return; - } - } + auto *const ref_source = source->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) + ? relation->GetChecker()->AsETSChecker()->PrimitiveTypeAsETSBuiltinType(source) + : source; + for (auto *it : constituent_types_) { - if (relation->IsAssignableTo(source, it)) { + if (relation->IsAssignableTo(ref_source, it)) { + if (ref_source != source) { + relation->IsAssignableTo(source, it); + ASSERT(relation->IsTrue()); + } return; } } @@ -115,7 +115,9 @@ Type *ETSUnionType::Instantiate(ArenaAllocator *allocator, TypeRelation *relatio ArenaVector copied_constituents(constituent_types_.size(), allocator->Adapter()); for (auto *it : constituent_types_) { - copied_constituents.push_back(it->Instantiate(allocator, relation, global_types)); + copied_constituents.push_back(it->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) + ? relation->GetChecker()->AsETSChecker()->PrimitiveTypeAsETSBuiltinType(it) + : it->Instantiate(allocator, relation, global_types)); } if (copied_constituents.size() == 1) { @@ -130,18 +132,20 @@ Type *ETSUnionType::Instantiate(ArenaAllocator *allocator, TypeRelation *relatio void ETSUnionType::Cast(TypeRelation *relation, Type *target) { - bool is_cast_to_obj = target->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT); + auto *const ref_target = target->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) + ? relation->GetChecker()->AsETSChecker()->PrimitiveTypeAsETSBuiltinType(target) + : target; + for (auto *source : constituent_types_) { - relation->IsCastableTo(source, target); - if (relation->IsTrue()) { - if (is_cast_to_obj && source->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { - GetLeastUpperBoundType(relation->GetChecker()->AsETSChecker())->Cast(relation, target); - return; - } - if (!is_cast_to_obj) { + if (relation->IsCastableTo(source, ref_target)) { + GetLeastUpperBoundType(relation->GetChecker()->AsETSChecker())->Cast(relation, ref_target); + ASSERT(relation->IsTrue()); + if (ref_target != target) { source->Cast(relation, target); - return; + ASSERT(relation->IsTrue()); + ASSERT(relation->GetNode()->GetBoxingUnboxingFlags() != ir::BoxingUnboxingFlags::NONE); } + return; } } @@ -237,4 +241,9 @@ Type *ETSUnionType::FindTypeIsCastableToSomeType(ir::Expression *node, TypeRelat return nullptr; } +void ETSUnionType::ToAssemblerType(std::stringstream &ss) const +{ + ss << compiler::Signatures::BUILTIN_OBJECT; +} + } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsUnionType.h b/ets2panda/checker/types/ets/etsUnionType.h index 66cf14228c..728c05665b 100644 --- a/ets2panda/checker/types/ets/etsUnionType.h +++ b/ets2panda/checker/types/ets/etsUnionType.h @@ -69,6 +69,8 @@ public: Type *FindTypeIsCastableToThis(ir::Expression *node, TypeRelation *relation, Type *source) const; Type *FindTypeIsCastableToSomeType(ir::Expression *node, TypeRelation *relation, Type *target) const; + void ToAssemblerType(std::stringstream &ss) const override; + Type *GetLeastUpperBoundType(ETSChecker *checker); Type *GetLeastUpperBoundType() const diff --git a/ets2panda/checker/types/ets/intType.cpp b/ets2panda/checker/types/ets/intType.cpp index 165e197f92..a0e4670bdf 100644 --- a/ets2panda/checker/types/ets/intType.cpp +++ b/ets2panda/checker/types/ets/intType.cpp @@ -43,7 +43,7 @@ bool IntType::AssignmentSource([[maybe_unused]] TypeRelation *relation, [[maybe_ } } - if (relation->ApplyBoxing() && (target->IsETSObjectType())) { + if (relation->ApplyBoxing() && (target->IsETSObjectType() || target->IsETSUnionType())) { relation->GetChecker()->AsETSChecker()->CheckBoxedSourceTypeAssignable(relation, this, target); } diff --git a/ets2panda/checker/types/globalTypesHolder.cpp b/ets2panda/checker/types/globalTypesHolder.cpp index d7eafa0c47..50e7839a53 100644 --- a/ets2panda/checker/types/globalTypesHolder.cpp +++ b/ets2panda/checker/types/globalTypesHolder.cpp @@ -93,7 +93,13 @@ GlobalTypesHolder::GlobalTypesHolder(ArenaAllocator *allocator) : builtin_name_m auto *global_null_type = allocator->New(allocator); global_null_type->AsETSObjectType()->AddObjectFlag(ETSObjectFlags::NULL_TYPE); global_null_type->AsETSObjectType()->SetName("null"); + global_null_type->AsETSObjectType()->SetAssemblerName("null has no symbol!"); global_types_[static_cast(GlobalTypeId::ETS_NULL)] = global_null_type; + auto *global_undefined_type = allocator->New(allocator); + global_undefined_type->AsETSObjectType()->AddObjectFlag(ETSObjectFlags::UNDEFINED_TYPE); + global_undefined_type->AsETSObjectType()->SetName("undefined"); + global_undefined_type->AsETSObjectType()->SetAssemblerName("undefined has no symbol!"); + global_types_[static_cast(GlobalTypeId::ETS_UNDEFINED)] = global_undefined_type; global_types_[static_cast(GlobalTypeId::ETS_WILDCARD)] = allocator->New(); builtin_name_mappings_.emplace("Boolean", GlobalTypeId::ETS_BOOLEAN_BUILTIN); @@ -335,6 +341,11 @@ Type *GlobalTypesHolder::GlobalETSNullType() return global_types_.at(static_cast(GlobalTypeId::ETS_NULL)); } +Type *GlobalTypesHolder::GlobalETSUndefinedType() +{ + return global_types_.at(static_cast(GlobalTypeId::ETS_UNDEFINED)); +} + Type *GlobalTypesHolder::GlobalWildcardType() { return global_types_.at(static_cast(GlobalTypeId::ETS_WILDCARD)); diff --git a/ets2panda/checker/types/globalTypesHolder.h b/ets2panda/checker/types/globalTypesHolder.h index 3146102f34..e84ae6ad35 100644 --- a/ets2panda/checker/types/globalTypesHolder.h +++ b/ets2panda/checker/types/globalTypesHolder.h @@ -56,6 +56,7 @@ enum class GlobalTypeId { ETS_VOID_BUILTIN, ETS_OBJECT_BUILTIN, ETS_NULL, + ETS_UNDEFINED, ETS_WILDCARD, ETS_BOOLEAN_BUILTIN, ETS_BYTE_BUILTIN, @@ -157,6 +158,7 @@ public: Type *GlobalETSVoidType(); Type *GlobalETSObjectType(); Type *GlobalETSNullType(); + Type *GlobalETSUndefinedType(); Type *GlobalWildcardType(); Type *GlobalETSBooleanBuiltinType(); Type *GlobalByteBuiltinType(); diff --git a/ets2panda/checker/types/type.cpp b/ets2panda/checker/types/type.cpp index 3de0f71ec7..f50b36c8de 100644 --- a/ets2panda/checker/types/type.cpp +++ b/ets2panda/checker/types/type.cpp @@ -25,9 +25,35 @@ bool Type::IsETSNullType() const return IsETSObjectType() && AsETSObjectType()->HasObjectFlag(ETSObjectFlags::NULL_TYPE); } -bool Type::IsNullableType() const +bool Type::IsETSUndefinedType() const { - return HasTypeFlag(TypeFlag::NULLABLE); + return IsETSObjectType() && AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNDEFINED_TYPE); +} + +bool Type::IsETSNullLike() const +{ + // NOTE: vpukhov. should be true for 'null|undefined' + return IsETSUndefinedType() || IsETSNullType(); +} + +bool Type::IsNullish() const +{ + return HasTypeFlag(TypeFlag::NULLISH); +} + +bool Type::IsNullishOrNullLike() const +{ + return IsNullish() || IsETSNullLike(); +} + +bool Type::ContainsNull() const +{ + return HasTypeFlag(TypeFlag::NULL_TYPE); +} + +bool Type::ContainsUndefined() const +{ + return HasTypeFlag(TypeFlag::UNDEFINED); } bool Type::IsETSStringType() const diff --git a/ets2panda/checker/types/type.h b/ets2panda/checker/types/type.h index 98378f1892..83d97754ba 100644 --- a/ets2panda/checker/types/type.h +++ b/ets2panda/checker/types/type.h @@ -84,8 +84,13 @@ public: bool IsETSStringType() const; bool IsETSNullType() const; + bool IsETSUndefinedType() const; + bool IsETSNullLike() const; bool IsETSAsyncFuncReturnType() const; - bool IsNullableType() const; + bool IsNullish() const; + bool IsNullishOrNullLike() const; + bool ContainsNull() const; + bool ContainsUndefined() const; ETSStringType *AsETSStringType() { diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index bf8c29c6aa..7a26628209 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -92,7 +92,6 @@ enum class TypeFlag : uint64_t { ETS_NUMERIC = ETS_INTEGRAL | FLOAT | DOUBLE, ETS_ARRAY_OR_OBJECT = ETS_ARRAY | ETS_OBJECT, ETS_WIDE_NUMERIC = LONG | DOUBLE, - ETS_TYPE_TO_DYNAMIC = ETS_NUMERIC, VALID_SWITCH_TYPE = BYTE | SHORT | INT | CHAR | LONG | ETS_ENUM | ETS_STRING_ENUM, NARROWABLE_TO_FLOAT = DOUBLE, NARROWABLE_TO_LONG = FLOAT | NARROWABLE_TO_FLOAT, @@ -109,8 +108,8 @@ enum class TypeFlag : uint64_t { COMPUTED_NAME = COMPUTED_TYPE_LITERAL_NAME | STRING | NUMBER | ANY | SYMBOL, ANY_OR_UNKNOWN = ANY | UNKNOWN, ANY_OR_VOID = ANY | VOID, - NULLABLE = UNDEFINED | NULL_TYPE, - ANY_OR_NULLABLE = ANY | NULLABLE, + NULLISH = UNDEFINED | NULL_TYPE, + ANY_OR_NULLISH = ANY | NULLISH, LITERAL = NUMBER_LITERAL | BOOLEAN_LITERAL | STRING_LITERAL | BIGINT_LITERAL, NUMBER_LIKE = NUMBER | NUMBER_LITERAL, NUMBER_LIKE_ENUM = NUMBER_LIKE | ENUM, @@ -127,10 +126,10 @@ enum class TypeFlag : uint64_t { STRING_LITERAL | NUMBER_LITERAL | BOOLEAN_LITERAL | BIGINT_LITERAL | VOID | UNDEFINED | NULL_TYPE, POSSIBLY_FALSY = DEFINITELY_FALSY | STRING | NUMBER | BOOLEAN | BIGINT, VALID_ARITHMETIC_TYPE = ANY | NUMBER_LIKE | BIGINT_LIKE | ENUM, - UNIT = LITERAL | UNIQUE_SYMBOL | NULLABLE, + UNIT = LITERAL | UNIQUE_SYMBOL | NULLISH, GETTER_SETTER = GETTER | SETTER, CONDITION_EXPRESSION_TYPE = - NULLABLE | CONSTANT | ETS_OBJECT | BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | ETS_BOOLEAN | ETS_ARRAY + NULLISH | CONSTANT | ETS_OBJECT | BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | ETS_BOOLEAN | ETS_ARRAY }; DEFINE_BITOPS(TypeFlag) diff --git a/ets2panda/compiler/base/condition.cpp b/ets2panda/compiler/base/condition.cpp index 9f9bcb290a..0331d9342c 100644 --- a/ets2panda/compiler/base/condition.cpp +++ b/ets2panda/compiler/base/condition.cpp @@ -114,7 +114,7 @@ Condition::Result Condition::CheckConstantExpr(ETSGen *etsg, const ir::Expressio return Result::UNKNOWN; } - if (etsg->Checker()->IsNullOrVoidExpression(resulting_expression)) { + if (etsg->Checker()->IsNullLikeOrVoidExpression(resulting_expression)) { return Result::CONST_FALSE; } diff --git a/ets2panda/compiler/base/literals.h b/ets2panda/compiler/base/literals.h index 45c1cd5143..cdba7736fc 100644 --- a/ets2panda/compiler/base/literals.h +++ b/ets2panda/compiler/base/literals.h @@ -44,6 +44,7 @@ enum class LiteralTag { DOUBLE, STRING, NULL_VALUE, + UNDEFINED_VALUE, ACCESSOR, METHOD, GENERATOR_METHOD, @@ -70,6 +71,11 @@ public: return Literal(LiteralTag::NULL_VALUE); } + static Literal UndefinedLiteral() + { + return Literal(LiteralTag::UNDEFINED_VALUE); + } + static Literal AccessorLiteral() { return Literal(LiteralTag::ACCESSOR); diff --git a/ets2panda/compiler/base/lreference.cpp b/ets2panda/compiler/base/lreference.cpp index a3676f6470..eba0f7c898 100644 --- a/ets2panda/compiler/base/lreference.cpp +++ b/ets2panda/compiler/base/lreference.cpp @@ -198,8 +198,10 @@ ETSLReference::ETSLReference(CodeGen *cg, const ir::AstNode *node, ReferenceKind if (member_expr->IsComputed()) { TargetTypeContext pttctx(etsg_, member_expr->Property()->TsType()); member_expr->Property()->Compile(etsg_); + etsg_->ApplyConversion(member_expr->Property()); + ASSERT(etsg_->GetAccumulatorType()->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL)); prop_reg_ = etsg_->AllocReg(); - etsg_->ApplyConversionAndStoreAccumulator(node, prop_reg_, member_expr->Property()->TsType()); + etsg_->StoreAccumulator(node, prop_reg_); } } diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 6ad0a7f3e9..46dd096ae8 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -243,6 +243,7 @@ void ETSCompiler::Compile(const ir::ArrayExpression *expr) const void ETSCompiler::Compile(const ir::ArrowFunctionExpression *expr) const { ETSGen *etsg = GetETSGen(); + ASSERT(expr->TsType()->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::FUNCTIONAL_INTERFACE)); ASSERT(expr->ResolvedLambda() != nullptr); auto *ctor = expr->ResolvedLambda()->TsType()->AsETSObjectType()->ConstructSignatures()[0]; std::vector arguments; @@ -258,7 +259,7 @@ void ETSCompiler::Compile(const ir::ArrowFunctionExpression *expr) const } etsg->InitLambdaObject(expr, ctor, arguments); - etsg->SetAccumulatorType(expr->resolved_lambda_->TsType()); + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const @@ -446,6 +447,13 @@ void ETSCompiler::Compile(const ir::StringLiteral *expr) const (void)expr; UNREACHABLE(); } + +void ETSCompiler::Compile(const ir::UndefinedLiteral *expr) const +{ + (void)expr; + UNREACHABLE(); +} + // compile methods for MODULE-related nodes in alphabetical order void ETSCompiler::Compile(const ir::ExportAllDeclaration *st) const { diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index c2e7e93fef..30b8519653 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -15,6 +15,7 @@ #include "ETSGen.h" +#include "checker/ets/boxingConverter.h" #include "ir/base/scriptFunction.h" #include "ir/base/classDefinition.h" #include "ir/statement.h" @@ -63,6 +64,22 @@ const checker::Type *ETSGen::GetAccumulatorType() const return GetVRegType(acc_); } +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); + 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"); +} + const checker::ETSChecker *ETSGen::Checker() const noexcept { return Context()->Checker()->AsETSChecker(); @@ -243,9 +260,7 @@ void ETSGen::LoadDynamicModuleVariable(const ir::AstNode *node, varbinder::Varia auto lang = import->Language(); LoadPropertyDynamic(node, Checker()->GlobalBuiltinDynamicType(lang), obj_reg, id->Name(), lang); - if (target_type_ != nullptr) { - ApplyConversion(node, target_type_); - } + ApplyConversion(node); } void ETSGen::LoadDynamicNamespaceVariable(const ir::AstNode *node, varbinder::Variable const *const var) @@ -287,6 +302,7 @@ void ETSGen::LoadVar(const ir::AstNode *node, varbinder::Variable const *const v } case ReferenceKind::LOCAL: { LoadAccumulator(node, local->Vreg()); + SetAccumulatorType(var->TsType()); break; } default: { @@ -297,10 +313,6 @@ void ETSGen::LoadVar(const ir::AstNode *node, varbinder::Variable const *const v if (var->HasFlag(varbinder::VariableFlags::BOXED) && !node->AsIdentifier()->IsIgnoreBox()) { EmitLocalBoxGet(node, var->TsType()); } - - if (target_type_ != nullptr) { - ApplyConversion(node, target_type_); - } } void ETSGen::StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFindResult &result) @@ -323,6 +335,7 @@ void ETSGen::StoreVar(const ir::AstNode *node, const varbinder::ConstScopeFindRe EmitLocalBoxSet(node, local); } else { StoreAccumulator(node, local->Vreg()); + SetVRegType(local->Vreg(), local->TsType()); } break; } @@ -717,22 +730,85 @@ void ETSGen::ReturnAcc(const ir::AstNode *node) } } -void ETSGen::EmitIsInstance(const ir::AstNode *const node, const VReg lhs) +void ETSGen::EmitIsInstanceNonNullish([[maybe_unused]] const ir::AstNode *const node, + [[maybe_unused]] const VReg obj_reg, + [[maybe_unused]] checker::ETSObjectType const *cls_type) +{ +#ifdef PANDA_WITH_ETS + auto const obj_type = GetVRegType(obj_reg); + // undefined is implemented as Object instance, so "instanceof Object" must be treated carefully + if (!obj_type->ContainsUndefined() || cls_type != Checker()->GlobalETSObjectType()) { + LoadAccumulator(node, obj_reg); + Sa().Emit(node, cls_type->AssemblerName()); + SetAccumulatorType(Checker()->GlobalETSBooleanType()); + return; + } + + Label *lundef = AllocLabel(); + Label *lend = AllocLabel(); + + LoadAccumulator(node, obj_reg); + Sa().Emit(node); + BranchIfTrue(node, lundef); + + LoadAccumulator(node, obj_reg); + Sa().Emit(node, cls_type->AssemblerName()); + JumpTo(node, lend); + + SetLabel(node, lundef); + LoadAccumulatorBoolean(node, false); + + SetLabel(node, lend); +#else + UNREACHABLE(); +#endif // PANDA_WITH_ETS +} + +void ETSGen::EmitIsInstance([[maybe_unused]] const ir::AstNode *const node, [[maybe_unused]] const VReg obj_reg) { - if (GetAccumulatorType()->IsETSDynamicType() || GetVRegType(lhs)->IsETSDynamicType()) { - ASSERT(GetAccumulatorType()->IsETSDynamicType() && GetVRegType(lhs)->IsETSDynamicType()); - Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, lhs, MoveAccToReg(node)); +#ifdef PANDA_WITH_ETS + auto const *rhs_type = node->AsBinaryExpression()->Right()->TsType()->AsETSObjectType(); + auto const *lhs_type = GetVRegType(obj_reg); + + if (rhs_type->IsETSDynamicType() || lhs_type->IsETSDynamicType()) { + ASSERT(rhs_type->IsETSDynamicType() && lhs_type->IsETSDynamicType()); + Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, obj_reg, MoveAccToReg(node)); + SetAccumulatorType(Checker()->GlobalETSBooleanType()); + return; + } + + if (!rhs_type->IsNullishOrNullLike()) { + EmitIsInstanceNonNullish(node, obj_reg, rhs_type); + return; + } + + auto if_true = AllocLabel(); + auto end = AllocLabel(); + + LoadAccumulator(node, obj_reg); + + // Iterate union members + if (rhs_type->ContainsNull() || rhs_type->IsETSNullType()) { + BranchIfNull(node, if_true); + } + if (rhs_type->ContainsUndefined() || rhs_type->IsETSUndefinedType()) { + Sa().Emit(node); + BranchIfTrue(node, if_true); + LoadAccumulator(node, obj_reg); + } + if (rhs_type->IsETSNullLike()) { + LoadAccumulatorBoolean(node, false); } else { - SwapBinaryOpArgs(node, lhs); - if (!GetVRegType(lhs)->IsETSNullType()) { - Sa().Emit(node, GetVRegType(lhs)->AsETSObjectType()->AssemblerName()); - } else { - Label *if_false = AllocLabel(); - Ra().Emit(node, lhs, if_false); - ToBinaryResult(node, if_false); - } + EmitIsInstanceNonNullish(node, obj_reg, Checker()->GetNonNullishType(rhs_type)->AsETSObjectType()); } - SetAccumulatorType(Checker()->GlobalETSBooleanType()); + JumpTo(node, end); + + SetLabel(node, if_true); + LoadAccumulatorBoolean(node, true); + SetLabel(node, end); +#else + UNREACHABLE(); +#endif // PANDA_WITH_ETS } bool ETSGen::TryLoadConstantExpression(const ir::Expression *node) @@ -780,6 +856,7 @@ bool ETSGen::TryLoadConstantExpression(const ir::Expression *node) } case checker::TypeFlag::ETS_OBJECT: { LoadAccumulatorString(node, type->AsETSObjectType()->AsETSStringType()->GetValue()); + SetAccumulatorType(node->TsType()); break; } default: { @@ -790,6 +867,19 @@ bool ETSGen::TryLoadConstantExpression(const ir::Expression *node) return true; } +// NOTE: vpukhov. lower (union_value) as (primitive_type) to be two as-nodes +static void ApplyUnboxingUnionPrimitive(ETSGen *etsg, const ir::AstNode *node) +{ + if (node->IsExpression() && node->Parent()->IsTSAsExpression()) { + auto const *from_type = node->AsExpression()->TsType(); + auto const *to_type = node->Parent()->AsTSAsExpression()->TsType(); + if (from_type->IsETSUnionType() && to_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + etsg->EmitCheckedNarrowingReferenceConversion( + node, checker::BoxingConverter::ETSTypeFromSource(etsg->Checker(), to_type)); + } + } +} + void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *target_type) { auto ttctx = TargetTypeContext(this, target_type); @@ -804,21 +894,22 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe } if ((node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U) { + if (GetAccumulatorType()->IsNullishOrNullLike()) { // NOTE: vpukhov. should be a CTE + EmitNullishGuardian(node); + } + ApplyUnboxingUnionPrimitive(this, node); EmitUnboxingConversion(node); const auto unboxing_flags = static_cast(node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG); node->SetBoxingUnboxingFlags( static_cast(node->GetBoxingUnboxingFlags() & ~unboxing_flags)); - return; } if (target_type == nullptr) { return; } - auto type_kind = checker::ETSChecker::TypeKind(target_type); - - switch (type_kind) { + switch (checker::ETSChecker::TypeKind(target_type)) { case checker::TypeFlag::DOUBLE: { CastToDouble(node); break; @@ -1498,6 +1589,11 @@ void ETSGen::CastDynamicToObject(const ir::AstNode *node, const checker::Type *t return; } + if (target_type->IsETSDynamicType()) { + SetAccumulatorType(target_type); + return; + } + if (target_type->IsETSArrayType() || target_type->IsETSObjectType()) { auto lang = GetAccumulatorType()->AsETSDynamicType()->Language(); auto method_name = compiler::Signatures::Dynamic::GetObjectBuiltin(lang); @@ -1679,7 +1775,8 @@ void ETSGen::CastDynamicTo(const ir::AstNode *node, enum checker::TypeFlag type_ void ETSGen::EmitCheckedNarrowingReferenceConversion(const ir::AstNode *const node, const checker::Type *const target_type) { - ASSERT(target_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)); + ASSERT(target_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION) && + !target_type->IsETSNullLike()); if (target_type->IsETSObjectType()) { Sa().Emit(node, target_type->AsETSObjectType()->AssemblerName()); @@ -1699,6 +1796,7 @@ void ETSGen::ToBinaryResult(const ir::AstNode *node, Label *if_false) SetLabel(node, if_false); Sa().Emit(node, 0); SetLabel(node, end); + SetAccumulatorType(Checker()->GlobalETSBooleanType()); } void ETSGen::Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs) @@ -1816,7 +1914,7 @@ void ETSGen::Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs) } } ASSERT(node->IsAssignmentExpression() || node->IsBinaryExpression()); - ApplyConversion(node, node->AsExpression()->TsType()); + ASSERT(GetAccumulatorType() == node->AsExpression()->TsType()); } void ETSGen::Condition(const ir::AstNode *node, lexer::TokenType op, VReg lhs, Label *if_false) @@ -1857,12 +1955,167 @@ void ETSGen::Condition(const ir::AstNode *node, lexer::TokenType op, VReg lhs, L } } -void ETSGen::EmitNullPointerException(const ir::AstNode *node) +void ETSGen::BranchIfNullish([[maybe_unused]] const ir::AstNode *node, [[maybe_unused]] Label *if_nullish) +{ +#ifdef PANDA_WITH_ETS + auto *const type = GetAccumulatorType(); + + if (!type->IsNullishOrNullLike()) { + return; + } + if (type->IsETSNullLike()) { + Sa().Emit(node, if_nullish); + return; + } + if (!type->ContainsUndefined()) { + Sa().Emit(node, if_nullish); + return; + } + + Sa().Emit(node, if_nullish); + + auto tmp_obj = AllocReg(); + auto not_taken = AllocLabel(); + + Sa().Emit(node, tmp_obj); + Sa().Emit(node); + Sa().Emit(node, not_taken); + + Sa().Emit(node, tmp_obj); + Sa().Emit(node, if_nullish); + + SetLabel(node, not_taken); + Sa().Emit(node, tmp_obj); +#else + UNREACHABLE(); +#endif // PANDA_WITH_ETS +} + +void ETSGen::BranchIfNotNullish([[maybe_unused]] const ir::AstNode *node, [[maybe_unused]] Label *if_not_nullish) +{ +#ifdef PANDA_WITH_ETS + auto *const type = GetAccumulatorType(); + + if (!type->IsNullishOrNullLike()) { + Sa().Emit(node, if_not_nullish); + return; + } + if (type->IsETSNullLike()) { + return; + } + if (!type->ContainsUndefined()) { + Sa().Emit(node, if_not_nullish); + return; + } + + auto end = AllocLabel(); + auto tmp_obj = AllocReg(); + auto not_taken = AllocLabel(); + + Sa().Emit(node, end); + + Sa().Emit(node, tmp_obj); + Sa().Emit(node); + Sa().Emit(node, not_taken); + + Sa().Emit(node, tmp_obj); + Sa().Emit(node, if_not_nullish); + + SetLabel(node, not_taken); + Sa().Emit(node, tmp_obj); + SetLabel(node, end); +#else + UNREACHABLE(); +#endif // PANDA_WITH_ETS +} + +void ETSGen::ConvertToNonNullish(const ir::AstNode *node) +{ + auto const *nullish_type = GetAccumulatorType(); + auto const *target_type = Checker()->GetNonNullishType(nullish_type); + if (nullish_type->ContainsUndefined() && target_type != Checker()->GlobalETSObjectType()) { + EmitCheckedNarrowingReferenceConversion(node, target_type); + } + SetAccumulatorType(target_type); +} + +void ETSGen::EmitNullishGuardian(const ir::AstNode *node) +{ + auto const *nullish_type = GetAccumulatorType(); + ASSERT(nullish_type->IsNullish()); + + compiler::Label *if_not_nullish = AllocLabel(); + BranchIfNotNullish(node, if_not_nullish); + EmitNullishException(node); + + SetLabel(node, if_not_nullish); + SetAccumulatorType(nullish_type); + ConvertToNonNullish(node); +} + +void ETSGen::EmitNullishException(const ir::AstNode *node) { VReg exception = StoreException(node); NewObject(node, exception, Signatures::BUILTIN_NULLPOINTER_EXCEPTION); CallThisStatic0(node, exception, Signatures::BUILTIN_NULLPOINTER_EXCEPTION_CTOR); EmitThrow(node, exception); + SetAccumulatorType(nullptr); +} + +void ETSGen::BinaryEqualityRefDynamic(const ir::AstNode *node, bool test_equal, VReg lhs, VReg rhs, Label *if_false) +{ + // NOTE: vpukhov. implement + LoadAccumulator(node, lhs); + if (test_equal) { + Ra().Emit(node, rhs, if_false); + } else { + Ra().Emit(node, rhs, if_false); + } +} + +void ETSGen::BinaryEqualityRef(const ir::AstNode *node, bool test_equal, VReg lhs, VReg rhs, Label *if_false) +{ + Label *if_true = AllocLabel(); + if (GetVRegType(lhs)->IsETSDynamicType() || GetVRegType(rhs)->IsETSDynamicType()) { + BinaryEqualityRefDynamic(node, test_equal, lhs, rhs, if_false); + return; + } + + if (GetVRegType(lhs)->IsETSNullLike() || GetVRegType(rhs)->IsETSNullLike()) { + LoadAccumulator(node, GetVRegType(lhs)->IsETSNullLike() ? rhs : lhs); + test_equal ? BranchIfNotNullish(node, if_false) : BranchIfNullish(node, if_false); + } else { + Label *if_lhs_nullish = AllocLabel(); + + auto const rhs_nullish_type = GetVRegType(rhs); + + LoadAccumulator(node, lhs); + BranchIfNullish(node, if_lhs_nullish); + ConvertToNonNullish(node); + StoreAccumulator(node, lhs); + + LoadAccumulator(node, rhs); + BranchIfNullish(node, test_equal ? if_false : if_true); + ConvertToNonNullish(node); + StoreAccumulator(node, rhs); + + LoadAccumulator(node, lhs); + if (GetVRegType(lhs)->IsETSStringType()) { + CallThisStatic1(node, lhs, Signatures::BUILTIN_STRING_EQUALS, rhs); + } else { + CallThisVirtual1(node, lhs, Signatures::BUILTIN_OBJECT_EQUALS, rhs); + } + test_equal ? BranchIfFalse(node, if_false) : BranchIfTrue(node, if_false); + JumpTo(node, if_true); + + SetLabel(node, if_lhs_nullish); + LoadAccumulator(node, rhs); + SetAccumulatorType(rhs_nullish_type); + test_equal ? BranchIfNotNullish(node, if_false) : BranchIfNullish(node, if_false); + // fallthrough + } + SetLabel(node, if_true); + SetAccumulatorType(nullptr); } void ETSGen::CompileStatements(const ArenaVector &statements) @@ -2100,7 +2353,7 @@ void ETSGen::BuildString(const ir::Expression *node) AppendString(node, builder); CallThisStatic0(node, builder, Signatures::BUILTIN_STRING_BUILDER_TO_STRING); - SetAccumulatorType(Checker()->GlobalBuiltinETSStringType()); + SetAccumulatorType(node->TsType()); } void ETSGen::BuildTemplateString(const ir::TemplateLiteral *node) diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 0565afaeeb..7ee98c5619 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -42,6 +42,7 @@ public: void SetAccumulatorType(const checker::Type *type); [[nodiscard]] const checker::Type *GetAccumulatorType() const; + void CompileAndCheck(const ir::Expression *expr); [[nodiscard]] VReg StoreException(const ir::AstNode *node); void ApplyConversionAndStoreAccumulator(const ir::AstNode *node, VReg vreg, const checker::Type *target_type); @@ -92,7 +93,7 @@ public: void LoadBuiltinVoid(const ir::AstNode *node); void ReturnAcc(const ir::AstNode *node); - void EmitIsInstance(const ir::AstNode *node, VReg lhs); + void EmitIsInstance(const ir::AstNode *node, VReg obj_reg); void Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs); void Unary(const ir::AstNode *node, lexer::TokenType op); @@ -186,7 +187,7 @@ public: void ResolveConditionalResultExpression(const ir::AstNode *node, [[maybe_unused]] Label *if_false) { auto expr_node = node->AsExpression(); - if (Checker()->IsNullOrVoidExpression(expr_node)) { + if (Checker()->IsNullLikeOrVoidExpression(expr_node)) { if constexpr (USE_FALSE_LABEL) { Branch(node, if_false); } else { @@ -211,15 +212,15 @@ public: if (node->IsExpression()) { ResolveConditionalResultExpression(node, if_false); } - Label *if_nullable {nullptr}; + Label *if_nullish {nullptr}; Label *end {nullptr}; - if (type->IsNullableType()) { + if (type->IsNullishOrNullLike()) { if constexpr (USE_FALSE_LABEL) { - BranchIfNull(node, if_false); + BranchIfNullish(node, if_false); } else { - if_nullable = AllocLabel(); + if_nullish = AllocLabel(); end = AllocLabel(); - BranchIfNull(node, if_nullable); + BranchIfNullish(node, if_nullish); } } if (type->IsETSArrayType()) { @@ -231,9 +232,9 @@ public: } else { ResolveConditionalResultNumeric(node, if_false, end); } - if (if_nullable != nullptr) { + if (if_nullish != nullptr) { Branch(node, end); - SetLabel(node, if_nullable); + SetLabel(node, if_nullish); Sa().Emit(node, 0); } if (end != nullptr) { @@ -258,9 +259,9 @@ public: Sa().Emit(node, if_false); } - void BranchIfTrue(const ir::AstNode *node, Label *if_false) + void BranchIfTrue(const ir::AstNode *node, Label *if_true) { - Sa().Emit(node, if_false); + Sa().Emit(node, if_true); } void BranchIfNull(const ir::AstNode *node, Label *if_null) @@ -273,6 +274,10 @@ public: Sa().Emit(node, if_not_null); } + void BranchIfNullish(const ir::AstNode *node, Label *if_nullish); + void BranchIfNotNullish(const ir::AstNode *node, Label *if_not_nullish); + void ConvertToNonNullish(const ir::AstNode *node); + void JumpTo(const ir::AstNode *node, Label *label_to) { Sa().Emit(node, label_to); @@ -283,7 +288,44 @@ public: Ra().Emit(node, err); } - void EmitNullPointerException(const ir::AstNode *node); + void EmitNullishException(const ir::AstNode *node); + void EmitNullishGuardian(const ir::AstNode *node); + + template + void EmitMaybeOptional(const ir::Expression *node, F const &compile, bool is_optional) + { + auto *const type = GetAccumulatorType(); + + if (!type->IsNullishOrNullLike()) { + compile(); + } else if (type->IsETSNullLike()) { + if (is_optional) { + LoadAccumulatorUndefined(node); + } else { // NOTE: vpukhov. should be a CTE + EmitNullishException(node); + LoadAccumulatorUndefined(node); + } + SetAccumulatorType(node->TsType()); + } else if (!is_optional) { // NOTE: vpukhov. should be a CTE + EmitNullishGuardian(node); + compile(); + } else { + compiler::Label *if_not_nullish = AllocLabel(); + compiler::Label *end_label = AllocLabel(); + + BranchIfNotNullish(node, if_not_nullish); + LoadAccumulatorUndefined(node); + Branch(node, end_label); + + SetLabel(node, if_not_nullish); + SetAccumulatorType(type); + ConvertToNonNullish(node); + compile(); + ApplyConversion(node, node->TsType()); + SetLabel(node, end_label); + SetAccumulatorType(node->TsType()); + } + } void ThrowException(const ir::Expression *expr); bool ExtendWithFinalizer(ir::AstNode *node, const ir::AstNode *original_node, Label *prev_finnaly = nullptr); @@ -340,6 +382,16 @@ public: SetAccumulatorType(type); } + void LoadAccumulatorUndefined([[maybe_unused]] const ir::AstNode *node) + { +#ifdef PANDA_WITH_ETS + Sa().Emit(node); + SetAccumulatorType(Checker()->GlobalETSUndefinedType()); +#else + UNREACHABLE(); +#endif // PANDA_WITH_ETS + } + void LoadAccumulatorChar(const ir::AstNode *node, char16_t value) { Sa().Emit(node, value); @@ -588,6 +640,8 @@ public: private: const VReg dummy_reg_ = VReg::RegStart(); + void EmitIsInstanceNonNullish(const ir::AstNode *node, VReg obj_reg, checker::ETSObjectType const *cls_type); + void StringBuilderAppend(const ir::AstNode *node, VReg builder); void AppendString(const ir::Expression *bin_expr, VReg builder); void StringBuilder(const ir::Expression *left, const ir::Expression *right, VReg builder); @@ -652,45 +706,8 @@ private: } } - template - void ConditionalBranching(const ir::AstNode *node, Label *if_false) - { - if constexpr (std::is_same_v) { - ResolveConditionalResultIfTrue(node, if_false); - Sa().Emit(node); - Sa().Emit(node, 1); - } else { - ResolveConditionalResultIfFalse(node, if_false); - } - BranchIfFalse(node, if_false); - } - - template - void BinaryEqualityObj(const ir::AstNode *node, VReg lhs, VReg arg0, Label *if_false) - { - Label *if_null = AllocLabel(); - Label *if_true = AllocLabel(); - LoadAccumulator(node, lhs); - BranchIfNull(node, if_null); - if (GetVRegType(lhs)->IsETSStringType() && GetVRegType(arg0)->IsETSObjectType()) { - CallThisStatic1(node, lhs, Signatures::BUILTIN_STRING_EQUALS, arg0); - } else { - CallThisVirtual1(node, lhs, Signatures::BUILTIN_OBJECT_EQUALS, arg0); - } - SetAccumulatorType(Checker()->GlobalETSBooleanType()); - ConditionalBranching(node, if_false); - JumpTo(node, if_true); - - SetLabel(node, if_null); - LoadAccumulator(node, arg0); - if constexpr (std::is_same_v) { - BranchIfNull(node, if_false); - } else { - BranchIfNotNull(node, if_false); - } - - SetLabel(node, if_true); - } + void BinaryEqualityRef(const ir::AstNode *node, bool test_equal, VReg lhs, VReg rhs, Label *if_false); + void BinaryEqualityRefDynamic(const ir::AstNode *node, bool test_equal, VReg lhs, VReg rhs, Label *if_false); template void BinaryNumberComparison(const ir::AstNode *node, VReg lhs, Label *if_false) @@ -710,12 +727,7 @@ private: template void BinaryEquality(const ir::AstNode *node, VReg lhs, Label *if_false) { - if (GetAccumulatorType()->IsETSDynamicType() || GetVRegType(lhs)->IsETSDynamicType()) { - BinaryDynamicStrictEquality(node, lhs, if_false); - } else { - BinaryEqualityCondition(node, lhs, if_false); - } - + BinaryEqualityCondition(node, lhs, if_false); ToBinaryResult(node, if_false); SetAccumulatorType(Checker()->GlobalETSBooleanType()); } @@ -726,11 +738,12 @@ private: auto type_kind = checker::ETSChecker::TypeKind(target_type_); switch (type_kind) { - case checker::TypeFlag::ETS_OBJECT: { + case checker::TypeFlag::ETS_OBJECT: + case checker::TypeFlag::ETS_DYNAMIC_TYPE: { RegScope rs(this); VReg arg0 = AllocReg(); StoreAccumulator(node, arg0); - BinaryEqualityObj(node, lhs, arg0, if_false); + BinaryEqualityRef(node, !std::is_same_v, lhs, arg0, if_false); return; } case checker::TypeFlag::DOUBLE: { @@ -1135,7 +1148,7 @@ void ETSGen::LoadAccumulatorNumber(const ir::AstNode *node, T number, checker::T } } - if (target_type_ && target_type_->IsETSObjectType()) { + if (target_type_ && (target_type_->IsETSObjectType() || target_type_->IsETSUnionType())) { ApplyConversion(node, target_type_); } } diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index a65f34b43f..10a894d364 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -749,6 +749,13 @@ void JSCompiler::Compile(const ir::StringLiteral *expr) const (void)expr; UNREACHABLE(); } + +void JSCompiler::Compile(const ir::UndefinedLiteral *expr) const +{ + (void)expr; + UNREACHABLE(); +} + // Compile methods for MODULE-related nodes in alphabetical order void JSCompiler::Compile(const ir::ExportAllDeclaration *st) const { diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index 1f70fa278d..f036bdab81 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -43,7 +43,7 @@ std::string const &UnionLowering::Name() return NAME; } -ir::ClassDefinition *CreateUnionFieldClass(checker::ETSChecker *checker, varbinder::VarBinder *varbinder) +ir::ClassDefinition *GetUnionFieldClass(checker::ETSChecker *checker, varbinder::VarBinder *varbinder) { // Create the name for the synthetic class node util::UString union_field_class_name(util::StringView(panda_file::GetDummyClassName()), checker->Allocator()); @@ -71,17 +71,19 @@ ir::ClassDefinition *CreateUnionFieldClass(checker::ETSChecker *checker, varbind return class_def; } -void CreateUnionFieldClassProperty(ArenaAllocator *allocator, varbinder::VarBinder *varbinder, - ir::ClassDefinition *class_def, checker::Type *field_type, - const util::StringView &prop_name) +varbinder::LocalVariable *CreateUnionFieldClassProperty(checker::ETSChecker *checker, varbinder::VarBinder *varbinder, + checker::Type *field_type, const util::StringView &prop_name) { - auto *class_scope = class_def->Scope()->AsClassScope(); + auto *const allocator = checker->Allocator(); + auto *const dummy_class = GetUnionFieldClass(checker, varbinder); + auto *class_scope = dummy_class->Scope()->AsClassScope(); + // Enter the union filed class instance field scope auto field_ctx = varbinder::LexicalScope::Enter(varbinder, class_scope->InstanceFieldScope()); - if (class_scope->FindLocal(prop_name, varbinder::ResolveBindingOptions::VARIABLES) != nullptr) { - return; + if (auto *var = class_scope->FindLocal(prop_name, varbinder::ResolveBindingOptions::VARIABLES); var != nullptr) { + return var->AsLocalVariable(); } // Create field name for synthetic class @@ -101,27 +103,16 @@ void CreateUnionFieldClassProperty(ArenaAllocator *allocator, varbinder::VarBind ArenaVector field_decl {allocator->Adapter()}; field_decl.push_back(field); - class_def->AddProperties(std::move(field_decl)); + dummy_class->AddProperties(std::move(field_decl)); + return var->AsLocalVariable(); } -ir::Expression *HandleUnionPropertyAccess(checker::ETSChecker *checker, varbinder::VarBinder *varbinder, - ir::MemberExpression *expr) +void HandleUnionPropertyAccess(checker::ETSChecker *checker, varbinder::VarBinder *vbind, ir::MemberExpression *expr) { - auto *class_def = CreateUnionFieldClass(checker, varbinder); - CreateUnionFieldClassProperty(checker->Allocator(), varbinder, class_def, expr->PropVar()->TsType(), - expr->Property()->AsIdentifier()->Name()); - if (expr->Object()->IsIdentifier()) { - auto *new_ts_type = expr->Object()->TsType()->AsETSUnionType()->GetLeastUpperBoundType(checker); - expr->Object()->AsIdentifier()->Variable()->SetTsType(new_ts_type); - } - return expr; -} - -ir::Expression *HandleUnionFunctionParameter(checker::ETSChecker *checker, ir::ETSParameterExpression *param) -{ - auto *union_type = param->Ident()->Variable()->TsType()->AsETSUnionType(); - param->Ident()->Variable()->SetTsType(union_type->GetLeastUpperBoundType(checker)); - return param; + ASSERT(expr->PropVar() == nullptr); + expr->SetPropVar( + CreateUnionFieldClassProperty(checker, vbind, expr->TsType(), expr->Property()->AsIdentifier()->Name())); + ASSERT(expr->PropVar() != nullptr); } ir::Expression *HandleBinaryExpressionWithUnion(checker::ETSChecker *checker, ir::BinaryExpression *expr) @@ -178,13 +169,8 @@ bool UnionLowering::Perform(CompilerContext *ctx, parser::Program *program) program->Ast()->TransformChildrenRecursively([checker, ctx](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType()) { - return HandleUnionPropertyAccess(checker, ctx->VarBinder(), ast->AsMemberExpression()); - } - - if (ast->IsETSParameterExpression() && - ast->AsETSParameterExpression()->Ident()->Variable()->TsType() != nullptr && - ast->AsETSParameterExpression()->Ident()->Variable()->TsType()->IsETSUnionType()) { - return HandleUnionFunctionParameter(checker, ast->AsETSParameterExpression()); + HandleUnionPropertyAccess(checker, ctx->VarBinder(), ast->AsMemberExpression()); + return ast; } if (ast->IsBinaryExpression() && ast->AsBinaryExpression()->OperationType() != nullptr && @@ -200,13 +186,13 @@ bool UnionLowering::Perform(CompilerContext *ctx, parser::Program *program) bool UnionLowering::Postcondition(CompilerContext *ctx, const parser::Program *program) { - if (ctx->Options()->compilation_mode != CompilationMode::GEN_STD_LIB) { - return !program->Ast()->IsAnyChild([](const ir::AstNode *ast) { - return ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && - ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType() && - ast->AsMemberExpression()->Object()->IsIdentifier() && - ast->AsMemberExpression()->Object()->AsIdentifier()->Variable()->TsType()->IsETSUnionType(); - }); + bool current = !program->Ast()->IsAnyChild([](const ir::AstNode *ast) { + return ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && + ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType() && + ast->AsMemberExpression()->PropVar() == nullptr; + }); + if (!current || ctx->Options()->compilation_mode != CompilationMode::GEN_STD_LIB) { + return current; } for (auto &[_, ext_programs] : program->ExternalSources()) { @@ -217,13 +203,7 @@ bool UnionLowering::Postcondition(CompilerContext *ctx, const parser::Program *p } } } - - return !program->Ast()->IsAnyChild([](const ir::AstNode *ast) { - return ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && - ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType() && - ast->AsMemberExpression()->Object()->IsIdentifier() && - ast->AsMemberExpression()->Object()->AsIdentifier()->Variable()->TsType()->IsETSUnionType(); - }); + return true; } } // namespace panda::es2panda::compiler diff --git a/ets2panda/ir/astDump.cpp b/ets2panda/ir/astDump.cpp index 274aebeda6..c919d9ea1b 100644 --- a/ets2panda/ir/astDump.cpp +++ b/ets2panda/ir/astDump.cpp @@ -170,6 +170,10 @@ void AstDumper::SerializeConstant(Property::Constant constant) ss_ << "null"; break; } + case Property::Constant::PROP_UNDEFINED: { + ss_ << "undefined"; + break; + } case Property::Constant::EMPTY_ARRAY: { ss_ << "[]"; break; diff --git a/ets2panda/ir/astDump.h b/ets2panda/ir/astDump.h index f9954d3e99..421acb2db7 100644 --- a/ets2panda/ir/astDump.h +++ b/ets2panda/ir/astDump.h @@ -28,9 +28,9 @@ namespace panda::es2panda::ir { class AstDumper { public: - class Nullable { + class Nullish { public: - explicit Nullable(const ir::AstNode *node) : node_(node) {} + explicit Nullish(const ir::AstNode *node) : node_(node) {} const ir::AstNode *Node() const { @@ -79,12 +79,13 @@ public: enum class Constant { PROP_NULL, + PROP_UNDEFINED, EMPTY_ARRAY, }; using Val = std::variant, util::StringView, bool, char16_t, lexer::Number, const ir::AstNode *, std::vector, - Constant, Nullable, Ignore>; + Constant, Nullish, Ignore>; Property(const char *key, const char *string) : key_(key), value_(string) {} Property(const char *key, util::StringView str) : key_(key), value_(str) {} @@ -96,10 +97,10 @@ public: Property(const char *key, const ir::AstNode *node) : key_(key), value_(const_cast(node)) {} Property(const char *key, Constant constant) : key_(key), value_(constant) {} - Property(const char *key, Nullable nullable) : key_(key) + Property(const char *key, Nullish nullish) : key_(key) { - if (nullable.Node() != nullptr) { - value_ = nullable.Node(); + if (nullish.Node() != nullptr) { + value_ = nullish.Node(); } else { value_ = Property::Constant::PROP_NULL; } diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 1a5e3be8f7..950d346f6f 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -313,9 +313,14 @@ public: return (flags_ & ModifierFlags::NATIVE) != 0; } - [[nodiscard]] bool IsNullable() const noexcept + [[nodiscard]] bool IsNullAssignable() const noexcept { - return (flags_ & ModifierFlags::NULLABLE) != 0; + return (flags_ & ModifierFlags::NULL_ASSIGNABLE) != 0; + } + + [[nodiscard]] bool IsUndefinedAssignable() const noexcept + { + return (flags_ & ModifierFlags::UNDEFINED_ASSIGNABLE) != 0; } [[nodiscard]] bool IsConst() const noexcept diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index 83ed05029a..d22bc5d6e4 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -47,10 +47,11 @@ enum class ModifierFlags : uint32_t { IN = 1U << 17U, OUT = 1U << 18U, INTERNAL = 1U << 19U, - NULLABLE = 1U << 20U, - EXPORT = 1U << 21U, - SETTER = 1U << 22U, - DEFAULT_EXPORT = 1U << 23U, + NULL_ASSIGNABLE = 1U << 20U, + UNDEFINED_ASSIGNABLE = 1U << 21U, + EXPORT = 1U << 22U, + SETTER = 1U << 23U, + DEFAULT_EXPORT = 1U << 24U, ACCESS = PUBLIC | PROTECTED | PRIVATE | INTERNAL, ALL = STATIC | ASYNC | ACCESS | DECLARE | READONLY | ABSTRACT, ALLOWED_IN_CTOR_PARAMETER = ACCESS | READONLY, diff --git a/ets2panda/ir/astNodeMapping.h b/ets2panda/ir/astNodeMapping.h index 55cddab5a5..9b8099c600 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -66,6 +66,7 @@ _(NAMED_TYPE, NamedType) \ _(NEW_EXPRESSION, NewExpression) \ _(NULL_LITERAL, NullLiteral) \ + _(UNDEFINED_LITERAL, UndefinedLiteral) \ _(NUMBER_LITERAL, NumberLiteral) \ _(OMITTED_EXPRESSION, OmittedExpression) \ _(PREFIX_ASSERTION_EXPRESSION, PrefixAssertionExpression) \ diff --git a/ets2panda/ir/base/catchClause.cpp b/ets2panda/ir/base/catchClause.cpp index c4d3a8db3d..feee7e595a 100644 --- a/ets2panda/ir/base/catchClause.cpp +++ b/ets2panda/ir/base/catchClause.cpp @@ -43,7 +43,7 @@ void CatchClause::Iterate(const NodeTraverser &cb) const void CatchClause::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "CatchClause"}, {"body", body_}, {"param", AstDumper::Nullable(param_)}}); + dumper->Add({{"type", "CatchClause"}, {"body", body_}, {"param", AstDumper::Nullish(param_)}}); } bool CatchClause::IsDefaultCatchClause() const diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index d6813cbddc..12e57a0dbc 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -121,9 +121,9 @@ void ClassDefinition::Dump(ir::AstDumper *dumper) const auto prop_filter = [](AstNode *prop) -> bool { return !prop->IsClassStaticBlock() || !prop->AsClassStaticBlock()->Function()->IsHidden(); }; - dumper->Add({{"id", AstDumper::Nullable(ident_)}, + dumper->Add({{"id", AstDumper::Nullish(ident_)}, {"typeParameters", AstDumper::Optional(type_params_)}, - {"superClass", AstDumper::Nullable(super_class_)}, + {"superClass", AstDumper::Nullish(super_class_)}, {"superTypeParameters", AstDumper::Optional(super_type_params_)}, {"implements", implements_}, {"constructor", AstDumper::Optional(ctor_)}, diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index 567762c7e5..d7477e92b5 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -100,7 +100,7 @@ void ScriptFunction::Iterate(const NodeTraverser &cb) const void ScriptFunction::Dump(ir::AstDumper *dumper) const { dumper->Add({{"type", "ScriptFunction"}, - {"id", AstDumper::Nullable(id_)}, + {"id", AstDumper::Nullish(id_)}, {"generator", IsGenerator()}, {"async", IsAsyncFunc()}, {"expression", ((func_flags_ & ir::ScriptFunctionFlags::EXPRESSION) != 0)}, diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index 07935632c0..c763b3b38d 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -88,9 +88,12 @@ checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) } checker::Type *type = part_->GetType(checker); - if (IsNullable()) { - type = type->Instantiate(checker->Allocator(), checker->Relation(), checker->GetGlobalTypesHolder()); - type->AddTypeFlag(checker::TypeFlag::NULLABLE); + if (IsNullAssignable() || IsUndefinedAssignable()) { + auto nullish_flags = (IsNullAssignable() ? checker::TypeFlag::NULL_TYPE : checker::TypeFlag(0)) | + (IsUndefinedAssignable() ? checker::TypeFlag::UNDEFINED : checker::TypeFlag(0)); + + type = checker->CreateNullishType(type, nullish_flags, checker->Allocator(), checker->Relation(), + checker->GetGlobalTypesHolder()); } SetTsType(type); diff --git a/ets2panda/ir/ets/etsUnionType.cpp b/ets2panda/ir/ets/etsUnionType.cpp index 803a0598f7..3b07a4446d 100644 --- a/ets2panda/ir/ets/etsUnionType.cpp +++ b/ets2panda/ir/ets/etsUnionType.cpp @@ -66,7 +66,9 @@ checker::Type *ETSUnionType::GetType([[maybe_unused]] checker::ETSChecker *check types.push_back(it->GetType(checker)); } + checker->Relation()->SetNode(this); SetTsType(checker->CreateETSUnionType(std::move(types))); + checker->Relation()->SetNode(nullptr); return TsType(); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expression.h b/ets2panda/ir/expression.h index 814d077faf..833fa15890 100644 --- a/ets2panda/ir/expression.h +++ b/ets2panda/ir/expression.h @@ -145,6 +145,48 @@ protected: void CloneTypeAnnotation(ArenaAllocator *allocator); }; + +class MaybeOptionalExpression : public Expression { +public: + MaybeOptionalExpression() = delete; + ~MaybeOptionalExpression() override = default; + + NO_COPY_OPERATOR(MaybeOptionalExpression); + NO_MOVE_SEMANTIC(MaybeOptionalExpression); + + [[nodiscard]] bool IsOptional() const noexcept + { + return optional_; + } + + void SetOptionalType(checker::Type *optional_type) + { + optional_type_ = optional_type; + } + + [[nodiscard]] const checker::Type *OptionalType() const noexcept + { + return optional_type_ != nullptr ? optional_type_ : TsType(); + } + +protected: + explicit MaybeOptionalExpression(AstNodeType type, bool optional) : Expression(type), optional_(optional) {} + explicit MaybeOptionalExpression(AstNodeType type, ModifierFlags flags, bool optional) + : Expression(type, flags), optional_(optional) + { + } + + MaybeOptionalExpression(MaybeOptionalExpression const &other) : Expression(static_cast(other)) + { + optional_type_ = other.optional_type_; + optional_ = other.optional_; + } + +private: + checker::Type *optional_type_ {}; + bool optional_; +}; + } // namespace panda::es2panda::ir #endif /* ES2PANDA_IR_EXPRESSION_H */ diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index b1e58362d1..a6ba7d6ee0 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -290,14 +290,7 @@ checker::Type *AssignmentExpression::Check([[maybe_unused]] checker::ETSChecker right_->AsObjectExpression()->SetPreferredType(left_type); } - auto *const right_type = right_->Check(checker); - - if (left_type->IsETSDynamicType() && right_type->HasTypeFlag(checker::TypeFlag::ETS_TYPE_TO_DYNAMIC)) { - // Update the left dynamic type if it can be converted to the right type - left_->SetTsType(right_type); - } - - source_type = right_type; + source_type = right_->Check(checker); break; } default: { diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 796a424ee9..636a7e5bc2 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -42,7 +42,7 @@ void AwaitExpression::Iterate(const NodeTraverser &cb) const void AwaitExpression::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "AwaitExpression"}, {"argument", AstDumper::Nullable(argument_)}}); + dumper->Add({{"type", "AwaitExpression"}, {"argument", AstDumper::Nullish(argument_)}}); } void AwaitExpression::Compile(compiler::PandaGen *pg) const diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 8ba6863dc5..440afa17f2 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -143,17 +143,41 @@ void BinaryExpression::Compile(compiler::ETSGen *etsg) const etsg->Binary(this, operator_, lhs); } -void BinaryExpression::CompileLogical(compiler::ETSGen *etsg) const +static void CompileNullishCoalescing(BinaryExpression const *const node, compiler::ETSGen *etsg) { - auto *end_label = etsg->AllocLabel(); + auto const compile_operand = [etsg, optype = node->OperationType()](ir::Expression const *expr) { + etsg->CompileAndCheck(expr); + etsg->ApplyConversion(expr, optype); + }; + + compile_operand(node->Left()); + + if (!node->Left()->TsType()->IsNullishOrNullLike()) { + // fallthrough + } else if (node->Left()->TsType()->IsETSNullLike()) { + compile_operand(node->Right()); + } else { + auto *if_left_nullish = etsg->AllocLabel(); + auto *end_label = etsg->AllocLabel(); + + etsg->BranchIfNullish(node, if_left_nullish); + + etsg->ConvertToNonNullish(node); + etsg->ApplyConversion(node->Left(), node->OperationType()); + etsg->JumpTo(node, end_label); + + etsg->SetLabel(node, if_left_nullish); + compile_operand(node->Right()); + etsg->SetLabel(node, end_label); + } + etsg->SetAccumulatorType(node->TsType()); +} + +void BinaryExpression::CompileLogical(compiler::ETSGen *etsg) const +{ if (operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { - left_->Compile(etsg); - etsg->ApplyConversion(left_, operation_type_); - etsg->BranchIfNotNull(this, end_label); - right_->Compile(etsg); - etsg->ApplyConversion(right_, operation_type_); - etsg->SetLabel(this, end_label); + CompileNullishCoalescing(this, etsg); return; } @@ -165,6 +189,8 @@ void BinaryExpression::CompileLogical(compiler::ETSGen *etsg) const left_->Compile(etsg); etsg->ApplyConversionAndStoreAccumulator(left_, lhs, OperationType()); + auto *end_label = etsg->AllocLabel(); + auto left_false_label = etsg->AllocLabel(); if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { etsg->ResolveConditionalResultIfFalse(left_, left_false_label); @@ -189,6 +215,7 @@ void BinaryExpression::CompileLogical(compiler::ETSGen *etsg) const } etsg->SetLabel(this, end_label); + etsg->SetAccumulatorType(TsType()); } checker::Type *BinaryExpression::Check(checker::TSChecker *checker) diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 4e7595fc06..b74f16794d 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -75,7 +75,7 @@ void CallExpression::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "CallExpression"}, {"callee", callee_}, {"arguments", arguments_}, - {"optional", optional_}, + {"optional", IsOptional()}, {"typeParameters", AstDumper::Optional(type_params_)}}); } @@ -177,7 +177,7 @@ void CallExpression::Compile(compiler::PandaGen *pg) const } pg->StoreAccumulator(this, callee); - pg->OptionalChainCheck(optional_, callee); + pg->OptionalChainCheck(IsOptional(), callee); if (contains_spread || arguments_.size() >= compiler::PandaGen::MAX_RANGE_CALL_ARG) { if (this_reg.IsInvalid()) { @@ -257,7 +257,7 @@ void CallExpression::Compile(compiler::ETSGen *etsg) const compiler::VReg dyn_param2; // Helper function to avoid branching in non optional cases - auto emit_arguments = [this, etsg, is_static, is_dynamic, &callee_reg, &dyn_param2]() { + auto emit_call = [this, etsg, is_static, is_dynamic, &callee_reg, &dyn_param2]() { if (is_dynamic) { etsg->CallDynamic(this, callee_reg, dyn_param2, signature_, arguments_); } else if (is_static) { @@ -268,12 +268,7 @@ void CallExpression::Compile(compiler::ETSGen *etsg) const } else { etsg->CallThisVirtual(this, callee_reg, signature_, arguments_); } - - if (GetBoxingUnboxingFlags() != ir::BoxingUnboxingFlags::NONE) { - etsg->ApplyConversion(this, nullptr); - } else { - etsg->SetAccumulatorType(signature_->ReturnType()); - } + etsg->SetAccumulatorType(TsType()); }; if (is_dynamic) { @@ -323,7 +318,7 @@ void CallExpression::Compile(compiler::ETSGen *etsg) const etsg->StoreAccumulator(this, dyn_param2); - emit_arguments(); + emit_call(); if (signature_->ReturnType() != TsType()) { etsg->ApplyConversion(this, TsType()); @@ -333,24 +328,23 @@ void CallExpression::Compile(compiler::ETSGen *etsg) const etsg->LoadThis(this); etsg->StoreAccumulator(this, callee_reg); } - emit_arguments(); + emit_call(); } else if (!is_reference && callee_->IsMemberExpression()) { if (!is_static) { callee_->AsMemberExpression()->Object()->Compile(etsg); etsg->StoreAccumulator(this, callee_reg); } - emit_arguments(); + emit_call(); + } else if (callee_->IsSuperExpression() || callee_->IsThisExpression()) { + ASSERT(!is_reference && IsETSConstructorCall()); + callee_->Compile(etsg); // ctor is not a value! + etsg->SetVRegType(callee_reg, etsg->GetAccumulatorType()); + emit_call(); } else { - callee_->Compile(etsg); + ASSERT(is_reference); + etsg->CompileAndCheck(callee_); etsg->StoreAccumulator(this, callee_reg); - if (optional_) { - compiler::Label *end_label = etsg->AllocLabel(); - etsg->BranchIfNull(this, end_label); - emit_arguments(); - etsg->SetLabel(this, end_label); - } else { - emit_arguments(); - } + etsg->EmitMaybeOptional(this, emit_call, IsOptional()); } } @@ -419,7 +413,9 @@ checker::Type *CallExpression::Check(checker::ETSChecker *checker) // Type check the callee again for member expression callee_type = callee_->Check(checker); } - + if (!IsOptional()) { + checker->CheckNonNullishType(callee_type, callee_->Start()); + } checker::Type *return_type; if (callee_type->IsETSDynamicType() && !callee_type->AsETSDynamicType()->HasDecl()) { // Trailing lambda for js function call is not supported, check the correctness of `foo() {}` @@ -470,7 +466,7 @@ checker::Type *CallExpression::Check(checker::ETSChecker *checker) checker->CheckObjectLiteralArguments(signature, arguments_); - checker->AddNullParamsForDefaultParams(signature, arguments_, checker); + checker->AddUndefinedParamsForDefaultParams(signature, arguments_, checker); if (!functional_interface) { checker::ETSObjectType *callee_obj {}; @@ -510,6 +506,16 @@ checker::Type *CallExpression::Check(checker::ETSChecker *checker) checker->CreateBuiltinArraySignature(array_type, array_type->Rank()); } + if (signature_->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { + signature_->OwnerVar()->Declaration()->Node()->Check(checker); + return_type = signature_->ReturnType(); + } + SetOptionalType(return_type); + if (IsOptional() && callee_type->IsNullishOrNullLike()) { + checker->Relation()->SetNode(this); + return_type = checker->CreateOptionalResultType(return_type); + checker->Relation()->SetNode(nullptr); + } SetTsType(return_type); return TsType(); } diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index 1575bad333..d68ca9daca 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -27,15 +27,14 @@ class Signature; namespace panda::es2panda::ir { class TSTypeParameterInstantiation; -class CallExpression : public Expression { +class CallExpression : public MaybeOptionalExpression { public: explicit CallExpression(Expression *callee, ArenaVector &&arguments, TSTypeParameterInstantiation *type_params, bool optional, bool trailing_comma = false) - : Expression(AstNodeType::CALL_EXPRESSION), + : MaybeOptionalExpression(AstNodeType::CALL_EXPRESSION, optional), callee_(callee), arguments_(std::move(arguments)), type_params_(type_params), - optional_(optional), trailing_comma_(trailing_comma) { } @@ -140,7 +139,6 @@ protected: ArenaVector arguments_; TSTypeParameterInstantiation *type_params_; checker::Signature *signature_ {}; - bool optional_; bool trailing_comma_; // for trailing lambda feature in ets ir::BlockStatement *trailing_block_ {}; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index a45322d476..b60d48679a 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -67,6 +67,9 @@ void ConditionalExpression::Compile(compiler::ETSGen *etsg) const auto *end_label = etsg->AllocLabel(); compiler::Condition::Compile(etsg, Test(), false_label); + + auto ttctx = compiler::TargetTypeContext(etsg, TsType()); + Consequent()->Compile(etsg); etsg->ApplyConversion(Consequent()); etsg->Branch(this, end_label); @@ -74,6 +77,7 @@ void ConditionalExpression::Compile(compiler::ETSGen *etsg) const Alternate()->Compile(etsg); etsg->ApplyConversion(Alternate()); etsg->SetLabel(this, end_label); + etsg->SetAccumulatorType(TsType()); } checker::Type *ConditionalExpression::Check(checker::TSChecker *checker) diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index abe13da98b..e1f2b3cd2a 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -177,13 +177,6 @@ checker::Type *Identifier::Check(checker::ETSChecker *checker) } SetTsType(checker->ResolveIdentifier(this)); - if (TsType()->IsETSFunctionType()) { - for (auto *sig : TsType()->AsETSFunctionType()->CallSignatures()) { - if (sig->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { - sig->OwnerVar()->Declaration()->Node()->Check(checker); - } - } - } return TsType(); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index 5c86a85bbc..2c45cb252e 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -38,6 +38,7 @@ void StringLiteral::Compile(compiler::PandaGen *pg) const void StringLiteral::Compile(compiler::ETSGen *etsg) const { etsg->LoadAccumulatorString(this, str_); + etsg->SetAccumulatorType(TsType()); } checker::Type *StringLiteral::Check(checker::TSChecker *checker) diff --git a/ets2panda/ir/expressions/literals/undefinedLiteral.cpp b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp new file mode 100644 index 0000000000..2b2bc2ccc6 --- /dev/null +++ b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2021-2022 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 "undefinedLiteral.h" + +#include "compiler/core/pandagen.h" +#include "compiler/core/ETSGen.h" +#include "checker/TSchecker.h" +#include "checker/ETSchecker.h" +#include "ir/astDump.h" + +namespace panda::es2panda::ir { +void UndefinedLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} +void UndefinedLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} + +void UndefinedLiteral::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "UndefinedLiteral"}, {"value", AstDumper::Property::Constant::PROP_UNDEFINED}}); +} + +void UndefinedLiteral::Compile(compiler::PandaGen *pg) const +{ + pg->LoadConst(this, compiler::Constant::JS_UNDEFINED); +} + +void UndefinedLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->LoadAccumulatorUndefined(this); +} + +checker::Type *UndefinedLiteral::Check(checker::TSChecker *checker) +{ + return checker->GlobalUndefinedType(); +} + +checker::Type *UndefinedLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +{ + SetTsType(checker->GlobalETSUndefinedType()); + return TsType(); +} +} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/literals/undefinedLiteral.h b/ets2panda/ir/expressions/literals/undefinedLiteral.h new file mode 100644 index 0000000000..4d7f240f0a --- /dev/null +++ b/ets2panda/ir/expressions/literals/undefinedLiteral.h @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2021 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_EXPRESSION_LITERAL_UNDEFINED_LITERAL_H +#define ES2PANDA_IR_EXPRESSION_LITERAL_UNDEFINED_LITERAL_H + +#include "ir/expressions/literal.h" + +namespace panda::es2panda::ir { +class UndefinedLiteral : public Literal { +public: + explicit UndefinedLiteral() : Literal(AstNodeType::UNDEFINED_LITERAL) {} + + void TransformChildren(const NodeTransformer &cb) override; + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; +}; +} // namespace panda::es2panda::ir + +#endif diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index e0167d4363..44936411de 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -72,7 +72,7 @@ void MemberExpression::Dump(ir::AstDumper *dumper) const {"object", object_}, {"property", property_}, {"computed", computed_}, - {"optional", optional_}}); + {"optional", IsOptional()}}); } void MemberExpression::LoadRhs(compiler::PandaGen *pg) const @@ -100,7 +100,7 @@ void MemberExpression::CompileToRegs(compiler::PandaGen *pg, compiler::VReg obje object_->Compile(pg); pg->StoreAccumulator(this, object); - pg->OptionalChainCheck(optional_, object); + pg->OptionalChainCheck(IsOptional(), object); if (!computed_) { pg->LoadAccumulatorString(this, property_->AsIdentifier()->Name()); @@ -114,7 +114,7 @@ void MemberExpression::CompileToRegs(compiler::PandaGen *pg, compiler::VReg obje void MemberExpression::Compile(compiler::PandaGen *pg) const { object_->Compile(pg); - pg->OptionalChainCheck(optional_, compiler::VReg::Invalid()); + pg->OptionalChainCheck(IsOptional(), compiler::VReg::Invalid()); LoadRhs(pg); } @@ -122,54 +122,36 @@ void MemberExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg obj_r { object_->Compile(pg); pg->StoreAccumulator(this, obj_reg); - pg->OptionalChainCheck(optional_, obj_reg); + pg->OptionalChainCheck(IsOptional(), obj_reg); LoadRhs(pg); } bool MemberExpression::CompileComputed(compiler::ETSGen *etsg) const { if (computed_) { - auto ottctx = compiler::TargetTypeContext(etsg, object_->TsType()); - object_->Compile(etsg); - - if (etsg->GetAccumulatorType()->IsETSNullType()) { - if (optional_) { - return true; - } + auto *const object_type = etsg->Checker()->GetNonNullishType(object_->TsType()); - etsg->EmitNullPointerException(this); - return true; - } + auto ottctx = compiler::TargetTypeContext(etsg, object_->TsType()); + etsg->CompileAndCheck(object_); - // Helper function to avoid branching in non optional cases - auto compile_and_load_elements = [this, etsg]() { + auto const load_element = [this, etsg, object_type]() { compiler::VReg obj_reg = etsg->AllocReg(); etsg->StoreAccumulator(this, obj_reg); - auto pttctx = compiler::TargetTypeContext(etsg, property_->TsType()); - property_->Compile(etsg); - etsg->ApplyConversion(property_); - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); + etsg->CompileAndCheck(property_); + etsg->ApplyConversion(property_, property_->TsType()); - if (TsType()->IsETSDynamicType()) { - auto lang = TsType()->AsETSDynamicType()->Language(); + auto ttctx = compiler::TargetTypeContext(etsg, OptionalType()); + + if (object_type->IsETSDynamicType()) { + auto lang = object_type->AsETSDynamicType()->Language(); etsg->LoadElementDynamic(this, obj_reg, lang); } else { etsg->LoadArrayElement(this, obj_reg); } - - etsg->ApplyConversion(this); }; - if (optional_) { - compiler::Label *end_label = etsg->AllocLabel(); - etsg->BranchIfNull(this, end_label); - compile_and_load_elements(); - etsg->SetLabel(this, end_label); - } else { - compile_and_load_elements(); - } - + etsg->EmitMaybeOptional(this, load_element, IsOptional()); return true; } return false; @@ -180,111 +162,92 @@ void MemberExpression::Compile(compiler::ETSGen *etsg) const auto lambda = etsg->VarBinder()->LambdaObjects().find(this); if (lambda != etsg->VarBinder()->LambdaObjects().end()) { etsg->CreateLambdaObjectFromMemberReference(this, object_, lambda->second.first); + etsg->SetAccumulatorType(TsType()); return; } compiler::RegScope rs(etsg); + + auto *const object_type = etsg->Checker()->GetNonNullishType(object_->TsType()); + if (CompileComputed(etsg)) { return; } auto &prop_name = property_->AsIdentifier()->Name(); - auto const *const object_type = object_->TsType(); if (object_type->IsETSArrayType() && prop_name.Is("length")) { auto ottctx = compiler::TargetTypeContext(etsg, object_type); - object_->Compile(etsg); - compiler::VReg obj_reg = etsg->AllocReg(); - etsg->StoreAccumulator(this, obj_reg); + etsg->CompileAndCheck(object_); + + auto const load_length = [this, etsg]() { + compiler::VReg obj_reg = etsg->AllocReg(); + etsg->StoreAccumulator(this, obj_reg); - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); - etsg->LoadArrayLength(this, obj_reg); - etsg->ApplyConversion(this); + auto ttctx = compiler::TargetTypeContext(etsg, OptionalType()); + etsg->LoadArrayLength(this, obj_reg); + etsg->ApplyConversion(this, TsType()); + }; + + etsg->EmitMaybeOptional(this, load_length, IsOptional()); return; } if (object_type->IsETSEnumType() || object_type->IsETSStringEnumType()) { auto const *const enum_interface = [object_type, this]() -> checker::ETSEnumInterface const * { if (object_type->IsETSEnumType()) { - return TsType()->AsETSEnumType(); + return OptionalType()->AsETSEnumType(); } - return TsType()->AsETSStringEnumType(); + return OptionalType()->AsETSStringEnumType(); }(); auto ottctx = compiler::TargetTypeContext(etsg, object_type); - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); + auto ttctx = compiler::TargetTypeContext(etsg, OptionalType()); etsg->LoadAccumulatorInt(this, enum_interface->GetOrdinal()); return; } if (etsg->Checker()->IsVariableStatic(prop_var_)) { - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); + auto ttctx = compiler::TargetTypeContext(etsg, OptionalType()); if (prop_var_->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { checker::Signature *sig = prop_var_->TsType()->AsETSFunctionType()->FindGetter(); etsg->CallStatic0(this, sig->InternalName()); - etsg->SetAccumulatorType(sig->ReturnType()); + etsg->SetAccumulatorType(TsType()); return; } util::StringView full_name = etsg->FormClassPropReference(object_->TsType()->AsETSObjectType(), prop_name); - etsg->LoadStaticProperty(this, TsType(), full_name); - etsg->ApplyConversion(this); + etsg->LoadStaticProperty(this, OptionalType(), full_name); return; } auto ottctx = compiler::TargetTypeContext(etsg, object_->TsType()); - object_->Compile(etsg); - - // NOTE: rsipka. it should be CTE if object type is non nullable type - - if (etsg->GetAccumulatorType()->IsETSNullType()) { - if (optional_) { - etsg->LoadAccumulatorNull(this, etsg->Checker()->GlobalETSNullType()); - return; - } - - etsg->EmitNullPointerException(this); - etsg->LoadAccumulatorNull(this, etsg->Checker()->GlobalETSNullType()); - return; - } + etsg->CompileAndCheck(object_); - etsg->ApplyConversion(object_); - compiler::VReg obj_reg = etsg->AllocReg(); - etsg->StoreAccumulator(this, obj_reg); + auto const load_property = [this, etsg, prop_name, object_type]() { + etsg->ApplyConversion(object_); + compiler::VReg obj_reg = etsg->AllocReg(); + etsg->StoreAccumulator(this, obj_reg); - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); + auto ttctx = compiler::TargetTypeContext(etsg, OptionalType()); - auto load_property = [this, etsg, obj_reg, prop_name]() { if (prop_var_->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { checker::Signature *sig = prop_var_->TsType()->AsETSFunctionType()->FindGetter(); etsg->CallThisVirtual0(this, obj_reg, sig->InternalName()); - etsg->SetAccumulatorType(sig->ReturnType()); - } else if (object_->TsType()->IsETSDynamicType()) { - auto lang = object_->TsType()->AsETSDynamicType()->Language(); - etsg->LoadPropertyDynamic(this, TsType(), obj_reg, prop_name, lang); - } else if (object_->TsType()->IsETSUnionType()) { - etsg->LoadUnionProperty(this, TsType(), obj_reg, prop_name); + etsg->SetAccumulatorType(TsType()); + } else if (object_type->IsETSDynamicType()) { + auto lang = object_type->AsETSDynamicType()->Language(); + etsg->LoadPropertyDynamic(this, OptionalType(), obj_reg, prop_name, lang); + } else if (object_type->IsETSUnionType()) { + etsg->LoadUnionProperty(this, OptionalType(), obj_reg, prop_name); } else { - const auto full_name = etsg->FormClassPropReference(object_->TsType()->AsETSObjectType(), prop_name); - etsg->LoadProperty(this, TsType(), obj_reg, full_name); + const auto full_name = etsg->FormClassPropReference(object_type->AsETSObjectType(), prop_name); + etsg->LoadProperty(this, OptionalType(), obj_reg, full_name); } - etsg->ApplyConversion(this); }; - if (optional_) { - compiler::Label *if_not_null = etsg->AllocLabel(); - compiler::Label *end_label = etsg->AllocLabel(); - - etsg->BranchIfNotNull(this, if_not_null); - etsg->LoadAccumulatorNull(this, TsType()); - etsg->Branch(this, end_label); - etsg->SetLabel(this, if_not_null); - load_property(); - etsg->SetLabel(this, end_label); - } else { - load_property(); - } + etsg->EmitMaybeOptional(this, load_property, IsOptional()); } checker::Type *MemberExpression::Check(checker::TSChecker *checker) @@ -364,7 +327,8 @@ checker::Type *MemberExpression::Check(checker::TSChecker *checker) return nullptr; } -checker::Type *MemberExpression::CheckEnumMember(checker::ETSChecker *checker, checker::Type *type) +std::pair MemberExpression::ResolveEnumMember(checker::ETSChecker *checker, + checker::Type *type) const { auto const *const enum_interface = [type]() -> checker::ETSEnumInterface const * { if (type->IsETSEnumType()) { @@ -374,108 +338,134 @@ checker::Type *MemberExpression::CheckEnumMember(checker::ETSChecker *checker, c }(); if (parent_->Type() == ir::AstNodeType::CALL_EXPRESSION && parent_->AsCallExpression()->Callee() == this) { - auto *const enum_method_type = enum_interface->LookupMethod(checker, object_, property_->AsIdentifier()); - SetTsType(enum_method_type); - return TsType(); + return {enum_interface->LookupMethod(checker, object_, property_->AsIdentifier()), nullptr}; } - auto *const enum_literal_type = enum_interface->LookupConstant(checker, object_, property_->AsIdentifier()); - SetTsType(enum_literal_type); - SetPropVar(enum_literal_type->GetMemberVar()); - return TsType(); + auto *const literal_type = enum_interface->LookupConstant(checker, object_, property_->AsIdentifier()); + return {literal_type, literal_type->GetMemberVar()}; } -checker::Type *MemberExpression::CheckObjectMember(checker::ETSChecker *checker) +std::pair MemberExpression::ResolveObjectMember( + checker::ETSChecker *checker) const { auto resolve_res = checker->ResolveMemberReference(this, obj_type_); - ASSERT(!resolve_res.empty()); - checker::Type *type_to_set = nullptr; switch (resolve_res.size()) { - case 1: { + case 1U: { if (resolve_res[0]->Kind() == checker::ResolvedKind::PROPERTY) { - prop_var_ = resolve_res[0]->Variable()->AsLocalVariable(); - checker->ValidatePropertyAccess(prop_var_, obj_type_, property_->Start()); - type_to_set = checker->GetTypeOfVariable(prop_var_); - } else { - type_to_set = checker->GetTypeOfVariable(resolve_res[0]->Variable()); + auto var = resolve_res[0]->Variable()->AsLocalVariable(); + checker->ValidatePropertyAccess(var, obj_type_, property_->Start()); + return {checker->GetTypeOfVariable(var), var}; } - break; + return {checker->GetTypeOfVariable(resolve_res[0]->Variable()), nullptr}; } case 2U: { // ETSExtensionFuncHelperType(class_method_type, extension_method_type) - type_to_set = checker->CreateETSExtensionFuncHelperType( + auto *resolved_type = checker->CreateETSExtensionFuncHelperType( checker->GetTypeOfVariable(resolve_res[1]->Variable())->AsETSFunctionType(), checker->GetTypeOfVariable(resolve_res[0]->Variable())->AsETSFunctionType()); - break; + return {resolved_type, nullptr}; } default: { UNREACHABLE(); } } - SetTsType(type_to_set); - if (prop_var_ != nullptr && prop_var_->TsType() != nullptr && prop_var_->TsType()->IsETSFunctionType()) { - for (auto *sig : prop_var_->TsType()->AsETSFunctionType()->CallSignatures()) { - if (sig->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { - sig->OwnerVar()->Declaration()->Node()->Check(checker); - } +} + +checker::Type *MemberExpression::CheckUnionMember(checker::ETSChecker *checker, checker::Type *base_type) +{ + auto *const union_type = base_type->AsETSUnionType(); + checker::Type *common_prop_type = nullptr; + auto const add_prop_type = [this, checker, &common_prop_type](checker::Type *member_type) { + if (common_prop_type != nullptr && common_prop_type != member_type) { + checker->ThrowTypeError("Member type must be the same for all union objects.", Start()); + } + common_prop_type = member_type; + }; + for (auto *const type : union_type->ConstituentTypes()) { + if (type->IsETSObjectType()) { + SetObjectType(type->AsETSObjectType()); + add_prop_type(ResolveObjectMember(checker).first); + } else if (type->IsETSEnumType() || base_type->IsETSStringEnumType()) { + add_prop_type(ResolveEnumMember(checker, type).first); + } else { + UNREACHABLE(); } } + SetObjectType(union_type->GetLeastUpperBoundType(checker)->AsETSObjectType()); + return common_prop_type; +} + +checker::Type *MemberExpression::AdjustOptional(checker::ETSChecker *checker, checker::Type *type) +{ + SetOptionalType(type); + if (IsOptional() && Object()->TsType()->IsNullishOrNullLike()) { + checker->Relation()->SetNode(this); + type = checker->CreateOptionalResultType(type); + checker->Relation()->SetNode(nullptr); + } + SetTsType(type); return TsType(); } +checker::Type *MemberExpression::CheckComputed(checker::ETSChecker *checker, checker::Type *base_type) +{ + 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 (Property()->IsIdentifier()) { + SetPropVar(Property()->AsIdentifier()->Variable()->AsLocalVariable()); + } else if (auto var = Property()->Variable(); (var != nullptr) && var->IsLocalVariable()) { + SetPropVar(var->AsLocalVariable()); + } + + // NOTE: apply capture conversion on this type + if (base_type->IsETSArrayType()) { + return base_type->AsETSArrayType()->ElementType(); + } + + // Dynamic + return checker->GlobalBuiltinDynamicType(base_type->AsETSDynamicType()->Language()); +} + checker::Type *MemberExpression::Check(checker::ETSChecker *checker) { if (TsType() != nullptr) { return TsType(); } + auto *const left_type = object_->Check(checker); + auto *const base_type = IsOptional() ? checker->GetNonNullishType(left_type) : left_type; + if (!IsOptional()) { + checker->CheckNonNullishType(left_type, object_->Start()); + } if (computed_) { - SetTsType(checker->CheckArrayElementAccess(this)); - return TsType(); + return AdjustOptional(checker, CheckComputed(checker, base_type)); } - checker::Type *const base_type = object_->Check(checker); - - if (!base_type->IsETSObjectType()) { - if (base_type->IsETSArrayType() && property_->AsIdentifier()->Name().Is("length")) { - SetTsType(checker->GlobalIntType()); - return TsType(); - } + if (base_type->IsETSArrayType() && property_->AsIdentifier()->Name().Is("length")) { + return AdjustOptional(checker, checker->GlobalIntType()); + } - if (base_type->IsETSUnionType()) { - auto *const union_type = base_type->AsETSUnionType(); - checker::Type *member_type = nullptr; - auto check_member_type = [this, checker, &member_type]() { - if (member_type != nullptr && member_type != TsType()) { - checker->ThrowTypeError("Member type must be the same for all union objects.", Start()); - } - member_type = TsType(); - }; - for (auto *type : union_type->ConstituentTypes()) { - if (type->IsETSObjectType()) { - obj_type_ = type->AsETSObjectType(); - CheckObjectMember(checker); - check_member_type(); - } - - if (type->IsETSEnumType() || base_type->IsETSStringEnumType()) { - CheckEnumMember(checker, type); - check_member_type(); - } - } - obj_type_ = union_type->GetLeastUpperBoundType(checker)->AsETSObjectType(); - return TsType(); - } + if (base_type->IsETSObjectType()) { + SetObjectType(base_type->AsETSObjectType()); + auto [res_type, res_var] = ResolveObjectMember(checker); + SetPropVar(res_var); + return AdjustOptional(checker, res_type); + } - if (base_type->IsETSEnumType() || base_type->IsETSStringEnumType()) { - return CheckEnumMember(checker, base_type); - } + if (base_type->IsETSEnumType() || base_type->IsETSStringEnumType()) { + auto [member_type, member_var] = ResolveEnumMember(checker, base_type); + SetPropVar(member_var); + return AdjustOptional(checker, member_type); + } - checker->ThrowTypeError({"Cannot access property of non-object or non-enum type"}, object_->Start()); + if (base_type->IsETSUnionType()) { + return AdjustOptional(checker, CheckUnionMember(checker, base_type)); } - obj_type_ = base_type->AsETSObjectType(); - return CheckObjectMember(checker); + checker->ThrowTypeError({"Cannot access property of non-object or non-enum type"}, object_->Start()); } // NOLINTNEXTLINE(google-default-arguments) diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 074a218537..47c172e843 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -36,7 +36,7 @@ enum class MemberExpressionKind : uint32_t { DEFINE_BITOPS(MemberExpressionKind) -class MemberExpression : public Expression { +class MemberExpression : public MaybeOptionalExpression { private: struct Tag {}; @@ -49,12 +49,11 @@ public: explicit MemberExpression(Expression *object, Expression *property, MemberExpressionKind kind, bool computed, bool optional) - : Expression(AstNodeType::MEMBER_EXPRESSION), + : MaybeOptionalExpression(AstNodeType::MEMBER_EXPRESSION, optional), object_(object), property_(property), kind_(kind), - computed_(computed), - optional_(optional) + computed_(computed) { } @@ -95,11 +94,6 @@ public: return computed_; } - [[nodiscard]] bool IsOptional() const noexcept - { - return optional_; - } - [[nodiscard]] MemberExpressionKind Kind() const noexcept { return kind_; @@ -147,9 +141,6 @@ public: [[nodiscard]] bool IsPrivateReference() const noexcept; - checker::Type *CheckEnumMember(checker::ETSChecker *checker, checker::Type *type); - checker::Type *CheckObjectMember(checker::ETSChecker *checker); - // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; @@ -165,11 +156,10 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; protected: - MemberExpression(MemberExpression const &other) : Expression(static_cast(other)) + MemberExpression(MemberExpression const &other) : MaybeOptionalExpression(other) { kind_ = other.kind_; computed_ = other.computed_; - optional_ = other.optional_; ignore_box_ = other.ignore_box_; prop_var_ = other.prop_var_; // Note! Probably, we need to do 'Instantiate(...)' but we haven't access to 'Relation()' here... @@ -177,12 +167,19 @@ protected: } private: + std::pair ResolveEnumMember(checker::ETSChecker *checker, + checker::Type *type) const; + std::pair ResolveObjectMember(checker::ETSChecker *checker) const; + + checker::Type *AdjustOptional(checker::ETSChecker *checker, checker::Type *type); + checker::Type *CheckComputed(checker::ETSChecker *checker, checker::Type *base_type); + checker::Type *CheckUnionMember(checker::ETSChecker *checker, checker::Type *base_type); + void LoadRhs(compiler::PandaGen *pg) const; Expression *object_ = nullptr; Expression *property_ = nullptr; MemberExpressionKind kind_; bool computed_; - bool optional_; bool ignore_box_ {false}; varbinder::LocalVariable *prop_var_ {}; checker::ETSObjectType *obj_type_ {}; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index c70a15e50f..8858bffbc9 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -44,7 +44,8 @@ void SuperExpression::Compile(compiler::PandaGen *pg) const void SuperExpression::Compile(compiler::ETSGen *etsg) const { - etsg->LoadThis(this); + etsg->LoadThis(this); // remains as long as we consider super 'super' expression + etsg->SetAccumulatorType(etsg->GetAccumulatorType()->AsETSObjectType()->SuperType()); } checker::Type *SuperExpression::Check(checker::TSChecker *checker) diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index d85b7e9479..2f6ced1150 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -263,7 +263,7 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) break; } case lexer::TokenType::PUNCTUATOR_EXCLAMATION_MARK: { - if (checker->IsNullOrVoidExpression(argument_)) { + if (checker->IsNullLikeOrVoidExpression(argument_)) { auto ts_type = checker->CreateETSBooleanType(true); ts_type->AddTypeFlag(checker::TypeFlag::CONSTANT); SetTsType(ts_type); diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index 6eab97e3ee..e72ca193e8 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -71,8 +71,9 @@ void UpdateExpression::Compile(compiler::ETSGen *etsg) const static_cast(argument_->GetBoxingUnboxingFlags() & BoxingUnboxingFlags::UNBOXING_FLAG); if (prefix_) { - argument_->SetBoxingUnboxingFlags(argument_unboxing_flags); lref.GetValue(); + argument_->SetBoxingUnboxingFlags(argument_unboxing_flags); + etsg->ApplyConversion(argument_, nullptr); etsg->Update(this, operator_); argument_->SetBoxingUnboxingFlags(argument_boxing_flags); etsg->ApplyConversion(argument_, argument_->TsType()); diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index f8e8efda91..4aadc7a545 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -37,7 +37,7 @@ void YieldExpression::Iterate(const NodeTraverser &cb) const void YieldExpression::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "YieldExpression"}, {"delegate", delegate_}, {"argument", AstDumper::Nullable(argument_)}}); + dumper->Add({{"type", "YieldExpression"}, {"delegate", delegate_}, {"argument", AstDumper::Nullish(argument_)}}); } void YieldExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const diff --git a/ets2panda/ir/module/exportAllDeclaration.cpp b/ets2panda/ir/module/exportAllDeclaration.cpp index a66ed1a218..9867f99848 100644 --- a/ets2panda/ir/module/exportAllDeclaration.cpp +++ b/ets2panda/ir/module/exportAllDeclaration.cpp @@ -40,7 +40,7 @@ void ExportAllDeclaration::Iterate(const NodeTraverser &cb) const void ExportAllDeclaration::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "ExportAllDeclaration"}, {"source", source_}, {"exported", AstDumper::Nullable(exported_)}}); + dumper->Add({{"type", "ExportAllDeclaration"}, {"source", source_}, {"exported", AstDumper::Nullish(exported_)}}); } void ExportAllDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} diff --git a/ets2panda/ir/module/exportNamedDeclaration.cpp b/ets2panda/ir/module/exportNamedDeclaration.cpp index 62acbf6f71..5bbd501593 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.cpp +++ b/ets2panda/ir/module/exportNamedDeclaration.cpp @@ -65,8 +65,8 @@ void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const { dumper->Add({{"type", "ExportNamedDeclaration"}, {"decorators", AstDumper::Optional(decorators_)}, - {"declaration", AstDumper::Nullable(decl_)}, - {"source", AstDumper::Nullable(source_)}, + {"declaration", AstDumper::Nullish(decl_)}, + {"source", AstDumper::Nullish(source_)}, {"specifiers", specifiers_}}); } diff --git a/ets2panda/ir/statements/assertStatement.cpp b/ets2panda/ir/statements/assertStatement.cpp index dd5ddb3b3e..dd22e25631 100644 --- a/ets2panda/ir/statements/assertStatement.cpp +++ b/ets2panda/ir/statements/assertStatement.cpp @@ -45,7 +45,7 @@ void AssertStatement::Iterate(const NodeTraverser &cb) const void AssertStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "AssertStatement"}, {"test", test_}, {"second", AstDumper::Nullable(second_)}}); + dumper->Add({{"type", "AssertStatement"}, {"test", test_}, {"second", AstDumper::Nullish(second_)}}); } void AssertStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} @@ -81,12 +81,16 @@ void AssertStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const return; } - compiler::Label *end_label = etsg->AllocLabel(); + compiler::Label *true_label = etsg->AllocLabel(); + compiler::Label *false_label = etsg->AllocLabel(); - test_->Compile(etsg); - etsg->BranchIfTrue(this, end_label); + compiler::Condition::Compile(etsg, test_, false_label); + etsg->JumpTo(this, true_label); + + etsg->SetLabel(this, false_label); ThrowError(etsg); - etsg->SetLabel(this, end_label); + + etsg->SetLabel(this, true_label); } checker::Type *AssertStatement::Check([[maybe_unused]] checker::TSChecker *checker) diff --git a/ets2panda/ir/statements/breakStatement.cpp b/ets2panda/ir/statements/breakStatement.cpp index 43ab14c951..185f261d97 100644 --- a/ets2panda/ir/statements/breakStatement.cpp +++ b/ets2panda/ir/statements/breakStatement.cpp @@ -38,7 +38,7 @@ void BreakStatement::Iterate(const NodeTraverser &cb) const void BreakStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "BreakStatement"}, {"label", AstDumper::Nullable(ident_)}}); + dumper->Add({{"type", "BreakStatement"}, {"label", AstDumper::Nullish(ident_)}}); } template diff --git a/ets2panda/ir/statements/continueStatement.cpp b/ets2panda/ir/statements/continueStatement.cpp index 47cc3d6e75..74536dc361 100644 --- a/ets2panda/ir/statements/continueStatement.cpp +++ b/ets2panda/ir/statements/continueStatement.cpp @@ -37,7 +37,7 @@ void ContinueStatement::Iterate(const NodeTraverser &cb) const void ContinueStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "ContinueStatement"}, {"label", AstDumper::Nullable(ident_)}}); + dumper->Add({{"type", "ContinueStatement"}, {"label", AstDumper::Nullish(ident_)}}); } template diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 8921f4e5cd..378dbcf36d 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -62,9 +62,9 @@ void ForUpdateStatement::Iterate(const NodeTraverser &cb) const void ForUpdateStatement::Dump(ir::AstDumper *dumper) const { dumper->Add({{"type", "ForUpdateStatement"}, - {"init", AstDumper::Nullable(init_)}, - {"test", AstDumper::Nullable(test_)}, - {"update", AstDumper::Nullable(update_)}, + {"init", AstDumper::Nullish(init_)}, + {"test", AstDumper::Nullish(test_)}, + {"update", AstDumper::Nullish(update_)}, {"body", body_}}); } diff --git a/ets2panda/ir/statements/ifStatement.cpp b/ets2panda/ir/statements/ifStatement.cpp index 91736420b7..02d9091d06 100644 --- a/ets2panda/ir/statements/ifStatement.cpp +++ b/ets2panda/ir/statements/ifStatement.cpp @@ -48,7 +48,7 @@ void IfStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "IfStatement"}, {"test", test_}, {"consequent", consequent_}, - {"alternate", AstDumper::Nullable(alternate_)}}); + {"alternate", AstDumper::Nullish(alternate_)}}); } void IfStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const diff --git a/ets2panda/ir/statements/returnStatement.cpp b/ets2panda/ir/statements/returnStatement.cpp index 8e7f1dfc75..fed52f836b 100644 --- a/ets2panda/ir/statements/returnStatement.cpp +++ b/ets2panda/ir/statements/returnStatement.cpp @@ -37,7 +37,7 @@ void ReturnStatement::Iterate(const NodeTraverser &cb) const void ReturnStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "ReturnStatement"}, {"argument", AstDumper::Nullable(argument_)}}); + dumper->Add({{"type", "ReturnStatement"}, {"argument", AstDumper::Nullish(argument_)}}); } void ReturnStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const diff --git a/ets2panda/ir/statements/switchCaseStatement.cpp b/ets2panda/ir/statements/switchCaseStatement.cpp index d5135069d4..d3b4ab31ea 100644 --- a/ets2panda/ir/statements/switchCaseStatement.cpp +++ b/ets2panda/ir/statements/switchCaseStatement.cpp @@ -43,7 +43,7 @@ void SwitchCaseStatement::Iterate(const NodeTraverser &cb) const void SwitchCaseStatement::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullable(test_)}, {"consequent", consequent_}}); + dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullish(test_)}, {"consequent", consequent_}}); } void SwitchCaseStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} diff --git a/ets2panda/ir/statements/tryStatement.cpp b/ets2panda/ir/statements/tryStatement.cpp index 8133ee83f9..b0026edcf6 100644 --- a/ets2panda/ir/statements/tryStatement.cpp +++ b/ets2panda/ir/statements/tryStatement.cpp @@ -55,7 +55,7 @@ void TryStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TryStatement"}, {"block", block_}, {"handler", catch_clauses_}, - {"finalizer", AstDumper::Nullable(finalizer_)}}); + {"finalizer", AstDumper::Nullish(finalizer_)}}); } bool TryStatement::HasDefaultCatchClause() const diff --git a/ets2panda/ir/statements/variableDeclarator.cpp b/ets2panda/ir/statements/variableDeclarator.cpp index 07e42b9220..3303096080 100644 --- a/ets2panda/ir/statements/variableDeclarator.cpp +++ b/ets2panda/ir/statements/variableDeclarator.cpp @@ -53,7 +53,7 @@ void VariableDeclarator::Iterate(const NodeTraverser &cb) const void VariableDeclarator::Dump(ir::AstDumper *dumper) const { - dumper->Add({{"type", "VariableDeclarator"}, {"id", id_}, {"init", AstDumper::Nullable(init_)}}); + dumper->Add({{"type", "VariableDeclarator"}, {"id", id_}, {"init", AstDumper::Nullish(init_)}}); } void VariableDeclarator::Compile([[maybe_unused]] compiler::PandaGen *pg) const @@ -83,6 +83,7 @@ void VariableDeclarator::Compile(compiler::ETSGen *etsg) const if (id_->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::BOXED)) { etsg->EmitLocalBoxCtor(id_); etsg->StoreAccumulator(this, lref.Variable()->AsLocalVariable()->Vreg()); + etsg->SetAccumulatorType(lref.Variable()->TsType()); } if (init_ != nullptr) { diff --git a/ets2panda/ir/ts/tsAsExpression.cpp b/ets2panda/ir/ts/tsAsExpression.cpp index 052d2d6761..fc81c5a920 100644 --- a/ets2panda/ir/ts/tsAsExpression.cpp +++ b/ets2panda/ir/ts/tsAsExpression.cpp @@ -61,6 +61,7 @@ void TSAsExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} void TSAsExpression::Compile(compiler::ETSGen *etsg) const { + auto ttctx = compiler::TargetTypeContext(etsg, nullptr); if (!etsg->TryLoadConstantExpression(expression_)) { expression_->Compile(etsg); } @@ -72,8 +73,7 @@ void TSAsExpression::Compile(compiler::ETSGen *etsg) const target_type = target_type->AsETSUnionType()->FindTypeIsCastableToThis(expression_, etsg->Checker()->Relation(), expression_->TsType()); } - const auto target_type_kind = checker::ETSChecker::TypeKind(target_type); - switch (target_type_kind) { + switch (checker::ETSChecker::TypeKind(target_type)) { case checker::TypeFlag::ETS_BOOLEAN: { etsg->CastToBoolean(this); break; diff --git a/ets2panda/ir/ts/tsNonNullExpression.cpp b/ets2panda/ir/ts/tsNonNullExpression.cpp index 4bbd98a68f..3ce576cef4 100644 --- a/ets2panda/ir/ts/tsNonNullExpression.cpp +++ b/ets2panda/ir/ts/tsNonNullExpression.cpp @@ -43,8 +43,12 @@ void TSNonNullExpression::Compile(compiler::ETSGen *etsg) const expr_->Compile(etsg); - if (etsg->GetAccumulatorType()->IsETSNullType()) { - etsg->EmitNullPointerException(this); + if (!etsg->GetAccumulatorType()->IsNullishOrNullLike()) { + return; + } + + if (etsg->GetAccumulatorType()->IsETSNullLike()) { + etsg->EmitNullishException(this); return; } @@ -54,11 +58,12 @@ void TSNonNullExpression::Compile(compiler::ETSGen *etsg) const auto end_label = etsg->AllocLabel(); - etsg->BranchIfNotNull(this, end_label); - etsg->EmitNullPointerException(this); + etsg->BranchIfNotNullish(this, end_label); + etsg->EmitNullishException(this); etsg->SetLabel(this, end_label); etsg->LoadAccumulator(this, arg); + etsg->ConvertToNonNullish(this); } checker::Type *TSNonNullExpression::Check([[maybe_unused]] checker::TSChecker *checker) @@ -70,16 +75,12 @@ checker::Type *TSNonNullExpression::Check(checker::ETSChecker *checker) { auto expr_type = expr_->Check(checker); - if (!expr_type->IsNullableType()) { + if (!expr_type->IsNullish()) { checker->ThrowTypeError("Bad operand type, the operand of the non-null expression must be a nullable type", expr_->Start()); } - auto non_null_type = - expr_type->Instantiate(checker->Allocator(), checker->Relation(), checker->GetGlobalTypesHolder()); - non_null_type->RemoveTypeFlag(checker::TypeFlag::NULLABLE); - - SetTsType(non_null_type); + SetTsType(expr_type->IsNullish() ? checker->GetNonNullishType(expr_type) : expr_type); return TsType(); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsTypePredicate.cpp b/ets2panda/ir/ts/tsTypePredicate.cpp index c2896cd3e4..9e12cb8569 100644 --- a/ets2panda/ir/ts/tsTypePredicate.cpp +++ b/ets2panda/ir/ts/tsTypePredicate.cpp @@ -40,7 +40,7 @@ void TSTypePredicate::Dump(ir::AstDumper *dumper) const { dumper->Add({{"type", "TSTypePredicate"}, {"parameterName", parameter_name_}, - {"typeAnnotation", AstDumper::Nullable(type_annotation_)}, + {"typeAnnotation", AstDumper::Nullish(type_annotation_)}, {"asserts", asserts_}}); } diff --git a/ets2panda/lexer/scripts/keywords.yaml b/ets2panda/lexer/scripts/keywords.yaml index 7f9b7b493e..181807709f 100644 --- a/ets2panda/lexer/scripts/keywords.yaml +++ b/ets2panda/lexer/scripts/keywords.yaml @@ -456,6 +456,7 @@ keywords: - name: 'undefined' token: KEYW_UNDEFINED + keyword: [ets] keyword_like: [js, ts] - name: 'unknown' diff --git a/ets2panda/lexer/token/token.cpp b/ets2panda/lexer/token/token.cpp index ffa2340688..a6bb09dfb0 100644 --- a/ets2panda/lexer/token/token.cpp +++ b/ets2panda/lexer/token/token.cpp @@ -327,7 +327,6 @@ const char *TokenToString(TokenType type) // NOLINT(readability-function-size) case TokenType::KEYW_NEW: return "new"; case TokenType::LITERAL_NULL: - case TokenType::KEYW_NULL: return "null"; case TokenType::KEYW_NUMBER: return "number"; diff --git a/ets2panda/lexer/token/tokenType.h b/ets2panda/lexer/token/tokenType.h index cb954d26d4..7872cd90d7 100644 --- a/ets2panda/lexer/token/tokenType.h +++ b/ets2panda/lexer/token/tokenType.h @@ -144,7 +144,6 @@ enum class TokenType { KEYW_NATIVE, KEYW_NEVER, KEYW_NEW, - KEYW_NULL, KEYW_NUMBER, KEYW_OBJECT, KEYW_FINAL, diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 8b38c5e941..e86b81930b 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -61,6 +61,7 @@ #include "ir/expressions/literals/nullLiteral.h" #include "ir/expressions/literals/numberLiteral.h" #include "ir/expressions/literals/stringLiteral.h" +#include "ir/expressions/literals/undefinedLiteral.h" #include "ir/expressions/templateLiteral.h" #include "ir/expressions/objectExpression.h" #include "ir/module/importDeclaration.h" @@ -1714,6 +1715,7 @@ ir::Statement *ETSParser::ParseTypeDeclaration(bool allow_static) } case lexer::TokenType::LITERAL_NUMBER: case lexer::TokenType::LITERAL_NULL: + case lexer::TokenType::KEYW_UNDEFINED: case lexer::TokenType::LITERAL_STRING: case lexer::TokenType::LITERAL_FALSE: case lexer::TokenType::LITERAL_TRUE: @@ -2263,41 +2265,56 @@ void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition * proxy_method_def->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); } -std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *type_annotation) +std::string ETSParser::PrimitiveTypeToName(ir::PrimitiveType type) { - const std::string optional_nullable = type_annotation->IsNullable() ? "|null" : ""; + switch (type) { + case ir::PrimitiveType::BYTE: + return "byte"; + case ir::PrimitiveType::INT: + return "int"; + case ir::PrimitiveType::LONG: + return "long"; + case ir::PrimitiveType::SHORT: + return "short"; + case ir::PrimitiveType::FLOAT: + return "float"; + case ir::PrimitiveType::DOUBLE: + return "double"; + case ir::PrimitiveType::BOOLEAN: + return "boolean"; + case ir::PrimitiveType::CHAR: + return "char"; + case ir::PrimitiveType::VOID: + return "void"; + default: + UNREACHABLE(); + } +} - // NOTE(aakmaev): Support nullable types as unions - if (type_annotation->IsNullable() && type_annotation->IsETSUnionType()) { +std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *type_annotation) +{ + if ((type_annotation->IsNullAssignable() || type_annotation->IsUndefinedAssignable()) && + type_annotation->IsETSUnionType()) { type_annotation = type_annotation->AsETSUnionType()->Types().front(); } - if (type_annotation->IsETSPrimitiveType()) { - switch (type_annotation->AsETSPrimitiveType()->GetPrimitiveType()) { - case ir::PrimitiveType::BYTE: - return "byte" + optional_nullable; - case ir::PrimitiveType::INT: - return "int" + optional_nullable; - case ir::PrimitiveType::LONG: - return "long" + optional_nullable; - case ir::PrimitiveType::SHORT: - return "short" + optional_nullable; - case ir::PrimitiveType::FLOAT: - return "float" + optional_nullable; - case ir::PrimitiveType::DOUBLE: - return "double" + optional_nullable; - case ir::PrimitiveType::BOOLEAN: - return "boolean" + optional_nullable; - case ir::PrimitiveType::CHAR: - return "char" + optional_nullable; - case ir::PrimitiveType::VOID: - return "void" + optional_nullable; + const auto adjust_nullish = [type_annotation](std::string const &s) { + std::string newstr = s; + if (type_annotation->IsNullAssignable()) { + newstr += "|null"; + } + if (type_annotation->IsUndefinedAssignable()) { + newstr += "|undefined"; } + return newstr; + }; + + if (type_annotation->IsETSPrimitiveType()) { + return adjust_nullish(PrimitiveTypeToName(type_annotation->AsETSPrimitiveType()->GetPrimitiveType())); } if (type_annotation->IsETSTypeReference()) { - return type_annotation->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name().Mutf8() + - optional_nullable; + return adjust_nullish(type_annotation->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name().Mutf8()); } if (type_annotation->IsETSFunctionType()) { @@ -2313,7 +2330,7 @@ std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *type_annotation) lambda_params.pop_back(); const std::string return_type_name = GetNameForTypeNode(type_annotation->AsETSFunctionType()->ReturnType()); - return "((" + lambda_params + ") => " + return_type_name + ")" + optional_nullable; + return adjust_nullish("((" + lambda_params + ") => " + return_type_name + ")"); } if (type_annotation->IsTSArrayType()) { @@ -2494,39 +2511,39 @@ ir::TypeNode *ETSParser::ParsePrimitiveType(TypeAnnotationParsingOptions *option return type_annotation; } -ir::ETSUnionType *ETSParser::ParseUnionType(ir::Expression *type) +ir::TypeNode *ETSParser::ParseUnionType(ir::TypeNode *const first_type) { - TypeAnnotationParsingOptions options = - TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::DISALLOW_UNION; - lexer::SourcePosition start_loc = type->Start(); ArenaVector types(Allocator()->Adapter()); - ASSERT(type->IsTypeNode()); - types.push_back(type->AsTypeNode()); + types.push_back(first_type->AsTypeNode()); - bool is_nullable {false}; - while (true) { - if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_BITWISE_OR) { - break; - } + ir::ModifierFlags nullish_modifiers {}; + while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_OR) { Lexer()->NextToken(); // eat '|' if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_NULL) { - Lexer()->NextToken(); // eat 'null' - type->AddModifier(ir::ModifierFlags::NULLABLE); - is_nullable = true; - continue; + nullish_modifiers |= ir::ModifierFlags::NULL_ASSIGNABLE; + Lexer()->NextToken(); + } else if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_UNDEFINED) { + nullish_modifiers |= ir::ModifierFlags::UNDEFINED_ASSIGNABLE; + Lexer()->NextToken(); + } else { + auto options = TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::DISALLOW_UNION; + types.push_back(ParseTypeAnnotation(&options)); } - - types.push_back(ParseTypeAnnotation(&options)); } - lexer::SourcePosition end_loc = types.back()->End(); - auto *union_type = AllocNode(std::move(types)); - union_type->SetRange({start_loc, end_loc}); - if (is_nullable) { - union_type->AddModifier(ir::ModifierFlags::NULLABLE); + lexer::SourcePosition const end_loc = types.back()->End(); + + if (types.size() == 1) { // Workaround until nullability is a typeflag + first_type->AddModifier(nullish_modifiers); + first_type->SetRange({first_type->Start(), end_loc}); + return first_type; } + + auto *const union_type = AllocNode(std::move(types)); + union_type->AddModifier(nullish_modifiers); + union_type->SetRange({first_type->Start(), end_loc}); return union_type; } @@ -3064,12 +3081,12 @@ ir::Expression *ETSParser::ParseFunctionParameter() ir::ETSParameterExpression *param_expression; auto *const param_ident = GetAnnotatedExpressionFromParam(); - bool default_null = false; + bool default_undefined = false; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { if (param_ident->IsRestElement()) { ThrowSyntaxError(NO_DEFAULT_FOR_REST); } - default_null = true; + default_undefined = true; Lexer()->NextToken(); // eat '?' } @@ -3089,7 +3106,7 @@ ir::Expression *ETSParser::ParseFunctionParameter() param_ident->SetTsTypeAnnotation(type_annotation); param_ident->SetEnd(type_annotation->End()); - } else if (!is_arrow && !default_null) { + } else if (!is_arrow && !default_undefined) { ThrowSyntaxError(EXPLICIT_PARAM_TYPE); } @@ -3101,8 +3118,8 @@ ir::Expression *ETSParser::ParseFunctionParameter() auto const lexer_pos = Lexer()->Save().Iterator(); Lexer()->NextToken(); // eat '=' - if (default_null) { - ThrowSyntaxError("Not enable default value with default null"); + if (default_undefined) { + ThrowSyntaxError("Not enable default value with default undefined"); } if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS || @@ -3130,7 +3147,7 @@ ir::Expression *ETSParser::ParseFunctionParameter() return std::make_pair(nullptr, ""); } if (!type_annotation->IsETSPrimitiveType()) { - return std::make_pair(AllocNode(), "null"); + return std::make_pair(AllocNode(), "undefined"); } // NOTE(ttamas) : after nullable fix, fix this scope switch (type_annotation->AsETSPrimitiveType()->GetPrimitiveType()) { @@ -3151,14 +3168,14 @@ ir::Expression *ETSParser::ParseFunctionParameter() } }(); - if (default_null && !type_annotation->IsETSPrimitiveType()) { - type_annotation->AddModifier(ir::ModifierFlags::NULLABLE); + if (default_undefined && !type_annotation->IsETSPrimitiveType()) { + type_annotation->AddModifier(ir::ModifierFlags::UNDEFINED_ASSIGNABLE); } param_expression = AllocNode( - param_ident->AsIdentifier(), default_null ? std::get<0>(type_annotation_value) : nullptr); + param_ident->AsIdentifier(), default_undefined ? std::get<0>(type_annotation_value) : nullptr); - if (default_null) { + if (default_undefined) { param_expression->SetLexerSaved(util::UString(std::get<1>(type_annotation_value), Allocator()).View()); } @@ -3594,6 +3611,9 @@ ir::Expression *ETSParser::ParsePrimaryExpression(ExpressionParseFlags flags) case lexer::TokenType::LITERAL_NULL: { return ParseNullLiteral(); } + case lexer::TokenType::KEYW_UNDEFINED: { + return ParseUndefinedLiteral(); + } case lexer::TokenType::LITERAL_NUMBER: { return ParseNumberLiteral(); } diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 9d8892c6b6..ba8e78e359 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -110,7 +110,7 @@ private: ir::TypeNode *ParseTypeReference(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseBaseTypeReference(TypeAnnotationParsingOptions *options); ir::TypeNode *ParsePrimitiveType(TypeAnnotationParsingOptions *options, ir::PrimitiveType type); - ir::ETSUnionType *ParseUnionType(ir::Expression *type); + ir::TypeNode *ParseUnionType(ir::TypeNode *first_type); ir::TSIntersectionType *ParseIntersectionType(ir::Expression *type); ir::TypeNode *ParseWildcardType(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseFunctionType(); @@ -119,6 +119,7 @@ private: std::string CreateProxyMethodName(const ir::ScriptFunction *function, ir::MethodDefinition *method, ir::Identifier *ident_node, varbinder::ClassScope *cls_scope); void AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *ident_node = nullptr); + static std::string PrimitiveTypeToName(ir::PrimitiveType type); std::string GetNameForTypeNode(const ir::TypeNode *type_annotation); ir::TSInterfaceDeclaration *ParseInterfaceBody(ir::Identifier *name, bool is_static); bool IsArrowFunctionExpressionStart(); diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 9627a16b39..6efb0c9946 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -46,6 +46,7 @@ #include "ir/expressions/literals/regExpLiteral.h" #include "ir/expressions/literals/charLiteral.h" #include "ir/expressions/literals/stringLiteral.h" +#include "ir/expressions/literals/undefinedLiteral.h" #include "ir/expressions/memberExpression.h" #include "ir/expressions/newExpression.h" #include "ir/expressions/objectExpression.h" @@ -884,6 +885,16 @@ ir::StringLiteral *ParserImpl::ParseStringLiteral() return string_node; } +ir::UndefinedLiteral *ParserImpl::ParseUndefinedLiteral() +{ + ASSERT(lexer_->GetToken().Type() == lexer::TokenType::KEYW_UNDEFINED); + auto *undefined_node = AllocNode(); + undefined_node->SetRange(lexer_->GetToken().Loc()); + + lexer_->NextToken(); + return undefined_node; +} + ir::ThisExpression *ParserImpl::ParseThisExpression() { ASSERT(lexer_->GetToken().Type() == lexer::TokenType::KEYW_THIS); @@ -958,6 +969,9 @@ ir::Expression *ParserImpl::ParsePrimaryExpression(ExpressionParseFlags flags) case lexer::TokenType::LITERAL_NULL: { return ParseNullLiteral(); } + case lexer::TokenType::KEYW_UNDEFINED: { + return ParseUndefinedLiteral(); + } case lexer::TokenType::LITERAL_NUMBER: { return ParseNumberLiteral(); } diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 790d03d574..21c674b2e6 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -322,6 +322,7 @@ protected: ir::Literal *ParseNumberLiteral(); ir::CharLiteral *ParseCharLiteral(); ir::StringLiteral *ParseStringLiteral(); + ir::UndefinedLiteral *ParseUndefinedLiteral(); virtual ir::ThisExpression *ParseThisExpression(); ir::RegExpLiteral *ParseRegularExpression(); ir::SuperExpression *ParseSuperExpression(); diff --git a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt index ab661e0a09..e902bdbdba 100644 --- a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt +++ b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt @@ -1256,60 +1256,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 31 - }, - "end": { - "line": 29, - "column": 36 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 31 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 37 - }, - "end": { - "line": 29, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 37 - }, - "end": { - "line": 29, - "column": 39 - } - } - }, + "end": { + "line": 29, + "column": 36 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 29, @@ -1317,45 +1292,55 @@ }, "end": { "line": 29, - "column": 39 + "column": 38 } } + }, + "loc": { + "start": { + "line": 29, + "column": 37 + }, + "end": { + "line": 29, + "column": 39 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 36 + "column": 37 }, "end": { "line": 29, "column": 39 } } - }, - "loc": { - "start": { - "line": 29, - "column": 31 - }, - "end": { - "line": 29, - "column": 41 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 31 + "column": 36 }, "end": { "line": 29, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 29, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 29, @@ -2047,38 +2032,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 43 - }, - "end": { - "line": 31, - "column": 44 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 43 - }, - "end": { - "line": 31, - "column": 46 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 31, @@ -2086,11 +2046,21 @@ }, "end": { "line": 31, - "column": 46 + "column": 44 } } + }, + "loc": { + "start": { + "line": 31, + "column": 43 + }, + "end": { + "line": 31, + "column": 46 + } } - ], + }, "loc": { "start": { "line": 31, @@ -2767,60 +2737,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 45 - }, - "end": { - "line": 33, - "column": 50 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 45 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 51 - }, - "end": { - "line": 33, - "column": 52 - } - } - }, - "loc": { - "start": { - "line": 33, - "column": 51 - }, - "end": { - "line": 33, - "column": 53 - } - } - }, + "end": { + "line": 33, + "column": 50 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 33, @@ -2828,45 +2773,55 @@ }, "end": { "line": 33, - "column": 53 + "column": 52 } } + }, + "loc": { + "start": { + "line": 33, + "column": 51 + }, + "end": { + "line": 33, + "column": 53 + } } - ], + }, "loc": { "start": { "line": 33, - "column": 50 + "column": 51 }, "end": { "line": 33, "column": 53 } } - }, - "loc": { - "start": { - "line": 33, - "column": 45 - }, - "end": { - "line": 33, - "column": 55 - } } - }, + ], "loc": { "start": { "line": 33, - "column": 45 + "column": 50 }, "end": { "line": 33, - "column": 55 + "column": 53 } } + }, + "loc": { + "start": { + "line": 33, + "column": 45 + }, + "end": { + "line": 33, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 33, @@ -3155,60 +3110,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 53 - }, - "end": { - "line": 34, - "column": 58 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 53 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 59 - }, - "end": { - "line": 34, - "column": 60 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 59 - }, - "end": { - "line": 34, - "column": 61 - } - } - }, + "end": { + "line": 34, + "column": 58 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 34, @@ -3216,45 +3146,55 @@ }, "end": { "line": 34, - "column": 61 + "column": 60 } } + }, + "loc": { + "start": { + "line": 34, + "column": 59 + }, + "end": { + "line": 34, + "column": 61 + } } - ], + }, "loc": { "start": { "line": 34, - "column": 58 + "column": 59 }, "end": { "line": 34, "column": 61 } } - }, - "loc": { - "start": { - "line": 34, - "column": 53 - }, - "end": { - "line": 34, - "column": 63 - } } - }, + ], "loc": { "start": { "line": 34, - "column": 53 + "column": 58 }, "end": { "line": 34, - "column": 63 + "column": 61 } } + }, + "loc": { + "start": { + "line": 34, + "column": 53 + }, + "end": { + "line": 34, + "column": 63 + } } - ], + }, "loc": { "start": { "line": 34, @@ -3651,38 +3591,13 @@ "type": "Identifier", "name": "val", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 39, - "column": 38 - }, - "end": { - "line": 39, - "column": 39 - } - } - }, - "loc": { - "start": { - "line": 39, - "column": 38 - }, - "end": { - "line": 39, - "column": 41 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 39, @@ -3690,11 +3605,21 @@ }, "end": { "line": 39, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 39, + "column": 38 + }, + "end": { + "line": 39, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 39, @@ -11455,60 +11380,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 141, - "column": 47 - }, - "end": { - "line": 141, - "column": 52 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Listt", + "decorators": [], + "loc": { + "start": { + "line": 141, + "column": 47 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 141, - "column": 53 - }, - "end": { - "line": 141, - "column": 54 - } - } - }, - "loc": { - "start": { - "line": 141, - "column": 53 - }, - "end": { - "line": 141, - "column": 55 - } - } - }, + "end": { + "line": 141, + "column": 52 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 141, @@ -11516,45 +11416,55 @@ }, "end": { "line": 141, - "column": 55 + "column": 54 } } + }, + "loc": { + "start": { + "line": 141, + "column": 53 + }, + "end": { + "line": 141, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 141, - "column": 52 + "column": 53 }, "end": { "line": 141, "column": 55 } } - }, - "loc": { - "start": { - "line": 141, - "column": 47 - }, - "end": { - "line": 141, - "column": 57 - } } - }, + ], "loc": { "start": { "line": 141, - "column": 47 + "column": 52 }, "end": { "line": 141, - "column": 57 + "column": 55 } } + }, + "loc": { + "start": { + "line": 141, + "column": 47 + }, + "end": { + "line": 141, + "column": 57 + } } - ], + }, "loc": { "start": { "line": 141, @@ -13216,64 +13126,39 @@ "column": 57 } } - }, - "decorators": [], - "loc": { - "start": { - "line": 156, - "column": 26 - }, - "end": { - "line": 156, - "column": 57 - } - } - }, - "loc": { - "start": { - "line": 156, - "column": 26 - }, - "end": { - "line": 156, - "column": 57 - } - } - } - ], - "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 156, - "column": 59 - }, - "end": { - "line": 156, - "column": 60 - } - } - }, - "loc": { - "start": { - "line": 156, - "column": 59 - }, - "end": { - "line": 156, - "column": 62 - } + }, + "decorators": [], + "loc": { + "start": { + "line": 156, + "column": 26 + }, + "end": { + "line": 156, + "column": 57 } + } + }, + "loc": { + "start": { + "line": 156, + "column": 26 }, + "end": { + "line": 156, + "column": 57 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 156, @@ -13281,11 +13166,21 @@ }, "end": { "line": 156, - "column": 62 + "column": 60 } } + }, + "loc": { + "start": { + "line": 156, + "column": 59 + }, + "end": { + "line": 156, + "column": 62 + } } - ], + }, "loc": { "start": { "line": 156, @@ -15187,60 +15082,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "ArrayAsListt", - "decorators": [], - "loc": { - "start": { - "line": 178, - "column": 60 - }, - "end": { - "line": 178, - "column": 72 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArrayAsListt", + "decorators": [], + "loc": { + "start": { + "line": 178, + "column": 60 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 178, - "column": 73 - }, - "end": { - "line": 178, - "column": 74 - } - } - }, - "loc": { - "start": { - "line": 178, - "column": 73 - }, - "end": { - "line": 178, - "column": 75 - } - } - }, + "end": { + "line": 178, + "column": 72 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 178, @@ -15248,45 +15118,55 @@ }, "end": { "line": 178, - "column": 75 + "column": 74 } } + }, + "loc": { + "start": { + "line": 178, + "column": 73 + }, + "end": { + "line": 178, + "column": 75 + } } - ], + }, "loc": { "start": { "line": 178, - "column": 72 + "column": 73 }, "end": { "line": 178, "column": 75 } } - }, - "loc": { - "start": { - "line": 178, - "column": 60 - }, - "end": { - "line": 178, - "column": 77 - } } - }, + ], "loc": { "start": { "line": 178, - "column": 60 + "column": 72 }, "end": { "line": 178, - "column": 77 + "column": 75 } } + }, + "loc": { + "start": { + "line": 178, + "column": 60 + }, + "end": { + "line": 178, + "column": 77 + } } - ], + }, "loc": { "start": { "line": 178, @@ -16988,60 +16868,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "ArrayAsListt", - "decorators": [], - "loc": { - "start": { - "line": 198, - "column": 68 - }, - "end": { - "line": 198, - "column": 80 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "ArrayAsListt", + "decorators": [], + "loc": { + "start": { + "line": 198, + "column": 68 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 198, - "column": 81 - }, - "end": { - "line": 198, - "column": 82 - } - } - }, - "loc": { - "start": { - "line": 198, - "column": 81 - }, - "end": { - "line": 198, - "column": 83 - } - } - }, + "end": { + "line": 198, + "column": 80 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 198, @@ -17049,45 +16904,55 @@ }, "end": { "line": 198, - "column": 83 + "column": 82 } } + }, + "loc": { + "start": { + "line": 198, + "column": 81 + }, + "end": { + "line": 198, + "column": 83 + } } - ], + }, "loc": { "start": { "line": 198, - "column": 80 + "column": 81 }, "end": { "line": 198, "column": 83 } } - }, - "loc": { - "start": { - "line": 198, - "column": 68 - }, - "end": { - "line": 198, - "column": 85 - } } - }, + ], "loc": { "start": { "line": 198, - "column": 68 + "column": 80 }, "end": { "line": 198, - "column": 85 + "column": 83 } } + }, + "loc": { + "start": { + "line": 198, + "column": 68 + }, + "end": { + "line": 198, + "column": 85 + } } - ], + }, "loc": { "start": { "line": 198, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt index 02c29ecade..9378ef0aa2 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt @@ -111,60 +111,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 19 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 16 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "U", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 22 - } - } - }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], "loc": { "start": { "line": 17, @@ -172,45 +147,55 @@ }, "end": { "line": 17, - "column": 22 + "column": 21 } } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 22 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 19 + "column": 20 }, "end": { "line": 17, "column": 22 } } - }, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 24 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 16 + "column": 19 }, "end": { "line": 17, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 17, @@ -645,60 +630,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 13 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 12 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 16 - } - } - }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 25, @@ -706,45 +666,55 @@ }, "end": { "line": 25, - "column": 16 + "column": 15 } } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 25, - "column": 13 + "column": 14 }, "end": { "line": 25, "column": 16 } } - }, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 18 - } } - }, + ], "loc": { "start": { "line": 25, - "column": 12 + "column": 13 }, "end": { "line": 25, - "column": 18 + "column": 16 } } + }, + "loc": { + "start": { + "line": 25, + "column": 12 + }, + "end": { + "line": 25, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 25, @@ -879,60 +849,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 15 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Foo", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 12 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 16 - }, - "end": { - "line": 29, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 16 - }, - "end": { - "line": 29, - "column": 18 - } - } - }, + "end": { + "line": 29, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 29, @@ -940,45 +885,55 @@ }, "end": { "line": 29, - "column": 18 + "column": 17 } } + }, + "loc": { + "start": { + "line": 29, + "column": 16 + }, + "end": { + "line": 29, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 15 + "column": 16 }, "end": { "line": 29, "column": 18 } } - }, - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 20 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 12 + "column": 15 }, "end": { "line": 29, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 29, + "column": 12 + }, + "end": { + "line": 29, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 29, @@ -1522,60 +1477,35 @@ "type": "Identifier", "name": "p1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 13 - }, - "end": { - "line": 35, - "column": 16 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Foo", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 17 - }, - "end": { - "line": 35, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 35, - "column": 17 - }, - "end": { - "line": 35, - "column": 24 - } - } - }, + "end": { + "line": 35, + "column": 16 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 35, @@ -1583,45 +1513,55 @@ }, "end": { "line": 35, - "column": 24 + "column": 23 } } + }, + "loc": { + "start": { + "line": 35, + "column": 17 + }, + "end": { + "line": 35, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 35, - "column": 16 + "column": 17 }, "end": { "line": 35, "column": 24 } } - }, - "loc": { - "start": { - "line": 35, - "column": 13 - }, - "end": { - "line": 35, - "column": 26 - } } - }, + ], "loc": { "start": { "line": 35, - "column": 13 + "column": 16 }, "end": { "line": 35, - "column": 26 + "column": 24 } } + }, + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 26 + } } - ], + }, "loc": { "start": { "line": 35, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt index 5d98ea0792..4d568d9bcf 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt @@ -1199,60 +1199,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 31, - "column": 13 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 12 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 16 - } - } - }, + "end": { + "line": 31, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 31, @@ -1260,45 +1235,55 @@ }, "end": { "line": 31, - "column": 16 + "column": 15 } } + }, + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 31, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 31, - "column": 13 + "column": 14 }, "end": { "line": 31, "column": 16 } } - }, - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 31, - "column": 18 - } } - }, + ], "loc": { "start": { "line": 31, - "column": 12 + "column": 13 }, "end": { "line": 31, - "column": 18 + "column": 16 } } + }, + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 31, @@ -1683,60 +1668,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 22 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 21 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "U", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 23 - }, - "end": { - "line": 37, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 37, - "column": 23 - }, - "end": { - "line": 37, - "column": 25 - } - } - }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], "loc": { "start": { "line": 37, @@ -1744,45 +1704,55 @@ }, "end": { "line": 37, - "column": 25 + "column": 24 } } + }, + "loc": { + "start": { + "line": 37, + "column": 23 + }, + "end": { + "line": 37, + "column": 25 + } } - ], + }, "loc": { "start": { "line": 37, - "column": 22 + "column": 23 }, "end": { "line": 37, "column": 25 } } - }, - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 27 - } } - }, + ], "loc": { "start": { "line": 37, - "column": 21 + "column": 22 }, "end": { "line": 37, - "column": 27 + "column": 25 } } + }, + "loc": { + "start": { + "line": 37, + "column": 21 + }, + "end": { + "line": 37, + "column": 27 + } } - ], + }, "loc": { "start": { "line": 37, @@ -2787,60 +2757,35 @@ "type": "Identifier", "name": "p1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 13 - }, - "end": { - "line": 48, - "column": 14 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 48, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 15 - }, - "end": { - "line": 48, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 48, - "column": 15 - }, - "end": { - "line": 48, - "column": 22 - } - } - }, + "end": { + "line": 48, + "column": 14 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 48, @@ -2848,45 +2793,55 @@ }, "end": { "line": 48, - "column": 22 + "column": 21 } } + }, + "loc": { + "start": { + "line": 48, + "column": 15 + }, + "end": { + "line": 48, + "column": 22 + } } - ], + }, "loc": { "start": { "line": 48, - "column": 14 + "column": 15 }, "end": { "line": 48, "column": 22 } } - }, - "loc": { - "start": { - "line": 48, - "column": 13 - }, - "end": { - "line": 48, - "column": 24 - } } - }, + ], "loc": { "start": { "line": 48, - "column": 13 + "column": 14 }, "end": { "line": 48, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 48, + "column": 13 + }, + "end": { + "line": 48, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 48, @@ -4473,60 +4428,35 @@ "type": "Identifier", "name": "p3", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 54, - "column": 13 - }, - "end": { - "line": 54, - "column": 14 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 54, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], - "loc": { - "start": { - "line": 54, - "column": 15 - }, - "end": { - "line": 54, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 54, - "column": 15 - }, - "end": { - "line": 54, - "column": 22 - } - } - }, + "end": { + "line": 54, + "column": 14 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], "loc": { "start": { "line": 54, @@ -4534,45 +4464,55 @@ }, "end": { "line": 54, - "column": 22 + "column": 21 } } + }, + "loc": { + "start": { + "line": 54, + "column": 15 + }, + "end": { + "line": 54, + "column": 22 + } } - ], + }, "loc": { "start": { "line": 54, - "column": 14 + "column": 15 }, "end": { "line": 54, "column": 22 } } - }, - "loc": { - "start": { - "line": 54, - "column": 13 - }, - "end": { - "line": 54, - "column": 24 - } } - }, + ], "loc": { "start": { "line": 54, - "column": 13 + "column": 14 }, "end": { "line": 54, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 54, + "column": 13 + }, + "end": { + "line": 54, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 54, diff --git a/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt b/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt index 9d48d62f27..4a7b683949 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt @@ -449,22 +449,7 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 21 - } - } - } - ], + "type": "ETSPrimitiveType", "loc": { "start": { "line": 21, @@ -501,38 +486,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 32 - }, - "end": { - "line": 21, - "column": 35 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 32 - }, - "end": { - "line": 21, - "column": 37 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 21, @@ -540,11 +500,21 @@ }, "end": { "line": 21, - "column": 37 + "column": 35 } } + }, + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 37 + } } - ], + }, "loc": { "start": { "line": 21, @@ -669,4 +639,4 @@ } } } -TypeError: Non reference types cannot be nullable. [n_nullableTypeInArgNotRef.ets:21:18] +TypeError: Non reference types cannot be nullish. [n_nullableTypeInArgNotRef.ets:21:18] diff --git a/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt b/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt index f66aa37242..0bf5ccb540 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt @@ -429,22 +429,7 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 22 - } - } - } - ], + "type": "ETSPrimitiveType", "loc": { "start": { "line": 21, @@ -568,4 +553,4 @@ } } } -TypeError: Non reference types cannot be nullable. [n_nullableTypeInReturnNotRef.ets:21:18] +TypeError: Non reference types cannot be nullish. [n_nullableTypeInReturnNotRef.ets:21:18] diff --git a/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt b/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt index 5dedc88c9c..c7344bfab7 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt @@ -214,22 +214,7 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 17, - "column": 14 - } - } - } - ], + "type": "ETSPrimitiveType", "loc": { "start": { "line": 17, @@ -360,4 +345,4 @@ } } } -TypeError: Non reference types cannot be nullable. [n_nullableTypeNotRef.ets:17:11] +TypeError: Non reference types cannot be nullish. [n_nullableTypeNotRef.ets:17:11] diff --git a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt index f070ebd4cf..ca7577b0c3 100644 --- a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt +++ b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt @@ -234,8 +234,8 @@ } }, "initializer": { - "type": "NullLiteral", - "value": null, + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, @@ -432,41 +432,16 @@ "type": "Identifier", "name": "exec", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSFunctionType", - "params": [], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "void", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], "loc": { "start": { "line": 1, @@ -488,8 +463,18 @@ "column": 3 } } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } - ], + }, "loc": { "start": { "line": 1, @@ -735,8 +720,8 @@ } }, "right": { - "type": "NullLiteral", - "value": null, + "type": "UndefinedLiteral", + "value": undefined, "loc": { "start": { "line": 1, diff --git a/ets2panda/test/compiler/ets/parenthesizedType-expected.txt b/ets2panda/test/compiler/ets/parenthesizedType-expected.txt index 4b076a8743..66ec32d137 100644 --- a/ets2panda/test/compiler/ets/parenthesizedType-expected.txt +++ b/ets2panda/test/compiler/ets/parenthesizedType-expected.txt @@ -358,38 +358,13 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 20 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 19, @@ -397,11 +372,21 @@ }, "end": { "line": 19, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 19, diff --git a/ets2panda/test/compiler/ets/union_types_4-expected.txt b/ets2panda/test/compiler/ets/union_types_4-expected.txt index c34e9be246..f69abcff99 100644 --- a/ets2panda/test/compiler/ets/union_types_4-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_4-expected.txt @@ -726,8 +726,34 @@ } }, "init": { - "type": "NumberLiteral", - "value": 5, + "type": "TSAsExpression", + "expression": { + "type": "NumberLiteral", + "value": 5, + "loc": { + "start": { + "line": 24, + "column": 34 + }, + "end": { + "line": 24, + "column": 35 + } + } + }, + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 24, + "column": 44 + } + } + }, "loc": { "start": { "line": 24, @@ -759,7 +785,7 @@ }, "end": { "line": 24, - "column": 36 + "column": 45 } } }, @@ -797,7 +823,7 @@ }, "end": { "line": 25, - "column": 21 + "column": 23 } } }, @@ -808,7 +834,7 @@ }, "end": { "line": 25, - "column": 22 + "column": 24 } } }, @@ -818,11 +844,11 @@ "loc": { "start": { "line": 25, - "column": 25 + "column": 27 }, "end": { "line": 25, - "column": 26 + "column": 28 } } }, @@ -833,7 +859,7 @@ }, "end": { "line": 25, - "column": 26 + "column": 28 } } }, @@ -843,11 +869,11 @@ "loc": { "start": { "line": 25, - "column": 30 + "column": 32 }, "end": { "line": 25, - "column": 32 + "column": 34 } } }, @@ -858,7 +884,7 @@ }, "end": { "line": 25, - "column": 32 + "column": 34 } } }, @@ -868,11 +894,11 @@ "loc": { "start": { "line": 25, - "column": 34 + "column": 36 }, "end": { "line": 25, - "column": 53 + "column": 55 } } }, @@ -883,7 +909,7 @@ }, "end": { "line": 25, - "column": 54 + "column": 56 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_4.ets b/ets2panda/test/compiler/ets/union_types_4.ets index fdc49e067f..224458ff6c 100644 --- a/ets2panda/test/compiler/ets/union_types_4.ets +++ b/ets2panda/test/compiler/ets/union_types_4.ets @@ -21,8 +21,8 @@ class A { class B {} function main() { - let x : String | short | A = 5; - assert (x as int) * 2 == 10: "Error! Must be 10"; + let x : String | short | A = 5 as short; + assert (x as short) * 2 == 10: "Error! Must be 10"; x = "STRSTR"; assert (x as String).equals("STRSTR"): "Error! Must be `STRSTR`"; x = new A(); diff --git a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt index 9e4d3701c8..df13087967 100644 --- a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt +++ b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt @@ -46,38 +46,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 25 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 27 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 17, @@ -85,11 +60,21 @@ }, "end": { "line": 17, - "column": 27 + "column": 25 } } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 27 + } } - ], + }, "loc": { "start": { "line": 17, @@ -138,38 +123,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 18, @@ -177,11 +137,21 @@ }, "end": { "line": 18, - "column": 28 + "column": 26 } } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 28 + } } - ], + }, "loc": { "start": { "line": 18, @@ -306,38 +276,13 @@ "type": "Identifier", "name": "left", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 21 - }, - "end": { - "line": 21, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 21 - }, - "end": { - "line": 21, - "column": 31 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 21, @@ -345,11 +290,21 @@ }, "end": { "line": 21, - "column": 31 + "column": 29 } } + }, + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 31 + } } - ], + }, "loc": { "start": { "line": 21, @@ -390,38 +345,13 @@ "type": "Identifier", "name": "right", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 45 - }, - "end": { - "line": 21, - "column": 53 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 45 - }, - "end": { - "line": 21, - "column": 55 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TreeNode", + "decorators": [], "loc": { "start": { "line": 21, @@ -429,11 +359,21 @@ }, "end": { "line": 21, - "column": 55 + "column": 53 } } + }, + "loc": { + "start": { + "line": 21, + "column": 45 + }, + "end": { + "line": 21, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt index 564772a80e..dabdff4623 100644 --- a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt @@ -309,35 +309,20 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 16, - "column": 8 - }, - "end": { - "line": 16, - "column": 11 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 8 }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 16, - "column": 15 - } + "end": { + "line": 16, + "column": 11 } } - ], + }, "loc": { "start": { "line": 16, @@ -386,35 +371,20 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 8 - }, - "end": { - "line": 17, - "column": 14 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 8 }, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 18 - } + "end": { + "line": 17, + "column": 14 } } - ], + }, "loc": { "start": { "line": 17, @@ -463,40 +433,15 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 8 - }, - "end": { - "line": 18, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 8 - }, - "end": { - "line": 18, - "column": 15 - } - } - }, + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], "loc": { "start": { "line": 18, @@ -504,22 +449,32 @@ }, "end": { "line": 18, - "column": 15 + "column": 14 } } }, "loc": { "start": { "line": 18, - "column": 17 + "column": 8 }, "end": { "line": 18, - "column": 18 + "column": 15 } } + }, + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 18, @@ -642,35 +597,20 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 19 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 14 }, - "loc": { - "start": { - "line": 21, - "column": 22 - }, - "end": { - "line": 21, - "column": 23 - } + "end": { + "line": 21, + "column": 19 } } - ], + }, "loc": { "start": { "line": 21, @@ -741,35 +681,20 @@ "type": "Identifier", "name": "d", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 22, - "column": 12 - }, - "end": { - "line": 22, - "column": 16 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 12 }, - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 20 - } + "end": { + "line": 22, + "column": 16 } } - ], + }, "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/async_function-expected.txt b/ets2panda/test/parser/ets/async_function-expected.txt index e98df896b9..f9b41ad629 100644 --- a/ets2panda/test/parser/ets/async_function-expected.txt +++ b/ets2panda/test/parser/ets/async_function-expected.txt @@ -68,60 +68,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 32 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 25 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 33 - }, - "end": { - "line": 17, - "column": 39 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 33 - }, - "end": { - "line": 17, - "column": 40 - } - } - }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -129,45 +104,55 @@ }, "end": { "line": 17, - "column": 40 + "column": 39 } } + }, + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 40 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 32 + "column": 33 }, "end": { "line": 17, "column": 40 } } - }, - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 42 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 25 + "column": 32 }, "end": { "line": 17, - "column": 42 + "column": 40 } } + }, + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 42 + } } - ], + }, "loc": { "start": { "line": 17, @@ -533,60 +518,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 23 - }, - "end": { - "line": 20, - "column": 30 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 23 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 31 - }, - "end": { - "line": 20, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 31 - }, - "end": { - "line": 20, - "column": 38 - } - } - }, + "end": { + "line": 20, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 20, @@ -594,45 +554,55 @@ }, "end": { "line": 20, - "column": 38 + "column": 37 } } + }, + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 38 + } } - ], + }, "loc": { "start": { "line": 20, - "column": 30 + "column": 31 }, "end": { "line": 20, "column": 38 } } - }, - "loc": { - "start": { - "line": 20, - "column": 23 - }, - "end": { - "line": 20, - "column": 40 - } } - }, + ], "loc": { "start": { "line": 20, - "column": 23 + "column": 30 }, "end": { "line": 20, - "column": 40 + "column": 38 } } + }, + "loc": { + "start": { + "line": 20, + "column": 23 + }, + "end": { + "line": 20, + "column": 40 + } } - ], + }, "loc": { "start": { "line": 20, @@ -748,60 +718,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 54 - }, - "end": { - "line": 22, - "column": 61 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 54 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 62 - }, - "end": { - "line": 22, - "column": 68 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 62 - }, - "end": { - "line": 22, - "column": 69 - } - } - }, + "end": { + "line": 22, + "column": 61 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -809,45 +754,55 @@ }, "end": { "line": 22, - "column": 69 + "column": 68 } } + }, + "loc": { + "start": { + "line": 22, + "column": 62 + }, + "end": { + "line": 22, + "column": 69 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 61 + "column": 62 }, "end": { "line": 22, "column": 69 } } - }, - "loc": { - "start": { - "line": 22, - "column": 54 - }, - "end": { - "line": 22, - "column": 71 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 54 + "column": 61 }, "end": { "line": 22, - "column": 71 + "column": 69 } } + }, + "loc": { + "start": { + "line": 22, + "column": 54 + }, + "end": { + "line": 22, + "column": 71 + } } - ], + }, "loc": { "start": { "line": 22, @@ -933,60 +888,35 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 26 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 19 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 27 - }, - "end": { - "line": 22, - "column": 33 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 27 - }, - "end": { - "line": 22, - "column": 34 - } - } - }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -994,45 +924,55 @@ }, "end": { "line": 22, - "column": 34 + "column": 33 } } + }, + "loc": { + "start": { + "line": 22, + "column": 27 + }, + "end": { + "line": 22, + "column": 34 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 26 + "column": 27 }, "end": { "line": 22, "column": 34 } } - }, - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 36 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 19 + "column": 26 }, "end": { "line": 22, - "column": 36 + "column": 34 } } + }, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 36 + } } - ], + }, "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/async_overload-expected.txt b/ets2panda/test/parser/ets/async_overload-expected.txt index e8b4419b7f..5e10309846 100644 --- a/ets2panda/test/parser/ets/async_overload-expected.txt +++ b/ets2panda/test/parser/ets/async_overload-expected.txt @@ -110,60 +110,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 24 - }, - "end": { - "line": 17, - "column": 31 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 32 - }, - "end": { - "line": 17, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 32 - }, - "end": { - "line": 17, - "column": 39 - } - } - }, + "end": { + "line": 17, + "column": 31 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -171,45 +146,55 @@ }, "end": { "line": 17, - "column": 39 + "column": 38 } } + }, + "loc": { + "start": { + "line": 17, + "column": 32 + }, + "end": { + "line": 17, + "column": 39 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 31 + "column": 32 }, "end": { "line": 17, "column": 39 } } - }, - "loc": { - "start": { - "line": 17, - "column": 24 - }, - "end": { - "line": 17, - "column": 41 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 24 + "column": 31 }, "end": { "line": 17, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 17, @@ -337,38 +322,13 @@ "type": "Identifier", "name": "o", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 26 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 21, @@ -376,11 +336,21 @@ }, "end": { "line": 21, - "column": 26 + "column": 24 } } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 26 + } } - ], + }, "loc": { "start": { "line": 21, @@ -458,60 +428,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 42 - }, - "end": { - "line": 21, - "column": 49 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 42 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 50 - }, - "end": { - "line": 21, - "column": 56 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 50 - }, - "end": { - "line": 21, - "column": 57 - } - } - }, + "end": { + "line": 21, + "column": 49 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 21, @@ -519,45 +464,55 @@ }, "end": { "line": 21, - "column": 57 + "column": 56 } } + }, + "loc": { + "start": { + "line": 21, + "column": 50 + }, + "end": { + "line": 21, + "column": 57 + } } - ], + }, "loc": { "start": { "line": 21, - "column": 49 + "column": 50 }, "end": { "line": 21, "column": 57 } } - }, - "loc": { - "start": { - "line": 21, - "column": 42 - }, - "end": { - "line": 21, - "column": 59 - } } - }, + ], "loc": { "start": { "line": 21, - "column": 42 + "column": 49 }, "end": { "line": 21, - "column": 59 + "column": 57 } } + }, + "loc": { + "start": { + "line": 21, + "column": 42 + }, + "end": { + "line": 21, + "column": 59 + } } - ], + }, "loc": { "start": { "line": 21, @@ -950,60 +905,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 29 - }, - "end": { - "line": 25, - "column": 36 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 29 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 37 - }, - "end": { - "line": 25, - "column": 43 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 37 - }, - "end": { - "line": 25, - "column": 44 - } - } - }, + "end": { + "line": 25, + "column": 36 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 25, @@ -1011,45 +941,55 @@ }, "end": { "line": 25, - "column": 44 + "column": 43 } } + }, + "loc": { + "start": { + "line": 25, + "column": 37 + }, + "end": { + "line": 25, + "column": 44 + } } - ], + }, "loc": { "start": { "line": 25, - "column": 36 + "column": 37 }, "end": { "line": 25, "column": 44 } } - }, - "loc": { - "start": { - "line": 25, - "column": 29 - }, - "end": { - "line": 25, - "column": 46 - } } - }, + ], "loc": { "start": { "line": 25, - "column": 29 + "column": 36 }, "end": { "line": 25, - "column": 46 + "column": 44 } } + }, + "loc": { + "start": { + "line": 25, + "column": 29 + }, + "end": { + "line": 25, + "column": 46 + } } - ], + }, "loc": { "start": { "line": 25, @@ -1177,38 +1117,13 @@ "type": "Identifier", "name": "o", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 23 - }, - "end": { - "line": 29, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 23 - }, - "end": { - "line": 29, - "column": 31 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 29, @@ -1216,11 +1131,21 @@ }, "end": { "line": 29, - "column": 31 + "column": 29 } } + }, + "loc": { + "start": { + "line": 29, + "column": 23 + }, + "end": { + "line": 29, + "column": 31 + } } - ], + }, "loc": { "start": { "line": 29, @@ -1298,60 +1223,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 47 - }, - "end": { - "line": 29, - "column": 54 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 47 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 55 - }, - "end": { - "line": 29, - "column": 61 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 55 - }, - "end": { - "line": 29, - "column": 62 - } - } - }, + "end": { + "line": 29, + "column": 54 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 29, @@ -1359,45 +1259,55 @@ }, "end": { "line": 29, - "column": 62 + "column": 61 } } + }, + "loc": { + "start": { + "line": 29, + "column": 55 + }, + "end": { + "line": 29, + "column": 62 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 54 + "column": 55 }, "end": { "line": 29, "column": 62 } } - }, - "loc": { - "start": { - "line": 29, - "column": 47 - }, - "end": { - "line": 29, - "column": 64 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 47 + "column": 54 }, "end": { "line": 29, - "column": 64 + "column": 62 } } + }, + "loc": { + "start": { + "line": 29, + "column": 47 + }, + "end": { + "line": 29, + "column": 64 + } } - ], + }, "loc": { "start": { "line": 29, diff --git a/ets2panda/test/parser/ets/async_with_lambda-expected.txt b/ets2panda/test/parser/ets/async_with_lambda-expected.txt index 74c87c2499..2007b8a7be 100644 --- a/ets2panda/test/parser/ets/async_with_lambda-expected.txt +++ b/ets2panda/test/parser/ets/async_with_lambda-expected.txt @@ -253,60 +253,35 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 34 - }, - "end": { - "line": 18, - "column": 41 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 34 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 42 - }, - "end": { - "line": 18, - "column": 48 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 42 - }, - "end": { - "line": 18, - "column": 49 - } - } - }, + "end": { + "line": 18, + "column": 41 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], "loc": { "start": { "line": 18, @@ -314,45 +289,55 @@ }, "end": { "line": 18, - "column": 49 + "column": 48 } } + }, + "loc": { + "start": { + "line": 18, + "column": 42 + }, + "end": { + "line": 18, + "column": 49 + } } - ], + }, "loc": { "start": { "line": 18, - "column": 41 + "column": 42 }, "end": { "line": 18, "column": 49 } } - }, - "loc": { - "start": { - "line": 18, - "column": 34 - }, - "end": { - "line": 18, - "column": 51 - } } - }, + ], "loc": { "start": { "line": 18, - "column": 34 + "column": 41 }, "end": { "line": 18, - "column": 51 + "column": 49 } } + }, + "loc": { + "start": { + "line": 18, + "column": 34 + }, + "end": { + "line": 18, + "column": 51 + } } - ], + }, "loc": { "start": { "line": 18, @@ -765,60 +750,35 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 29 - }, - "end": { - "line": 26, - "column": 36 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 29 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 37 - }, - "end": { - "line": 26, - "column": 43 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 37 - }, - "end": { - "line": 26, - "column": 44 - } - } - }, + "end": { + "line": 26, + "column": 36 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 26, @@ -826,45 +786,55 @@ }, "end": { "line": 26, - "column": 44 + "column": 43 } } + }, + "loc": { + "start": { + "line": 26, + "column": 37 + }, + "end": { + "line": 26, + "column": 44 + } } - ], + }, "loc": { "start": { "line": 26, - "column": 36 + "column": 37 }, "end": { "line": 26, "column": 44 } } - }, - "loc": { - "start": { - "line": 26, - "column": 29 - }, - "end": { - "line": 26, - "column": 46 - } } - }, + ], "loc": { "start": { "line": 26, - "column": 29 + "column": 36 }, "end": { "line": 26, - "column": 46 + "column": 44 } } + }, + "loc": { + "start": { + "line": 26, + "column": 29 + }, + "end": { + "line": 26, + "column": 46 + } } - ], + }, "loc": { "start": { "line": 26, @@ -909,60 +879,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 64 - }, - "end": { - "line": 26, - "column": 71 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 64 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 72 - }, - "end": { - "line": 26, - "column": 78 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 72 - }, - "end": { - "line": 26, - "column": 79 - } - } - }, + "end": { + "line": 26, + "column": 71 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 26, @@ -970,45 +915,55 @@ }, "end": { "line": 26, - "column": 79 + "column": 78 } } + }, + "loc": { + "start": { + "line": 26, + "column": 72 + }, + "end": { + "line": 26, + "column": 79 + } } - ], + }, "loc": { "start": { "line": 26, - "column": 71 + "column": 72 }, "end": { "line": 26, "column": 79 } } - }, - "loc": { - "start": { - "line": 26, - "column": 64 - }, - "end": { - "line": 26, - "column": 81 - } } - }, + ], "loc": { "start": { "line": 26, - "column": 64 + "column": 71 }, "end": { "line": 26, - "column": 81 + "column": 79 } } + }, + "loc": { + "start": { + "line": 26, + "column": 64 + }, + "end": { + "line": 26, + "column": 81 + } } - ], + }, "loc": { "start": { "line": 26, diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 4db57e694b..9adc24bf50 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -289,60 +289,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 28 - }, - "end": { - "line": 16, - "column": 35 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 36 - }, - "end": { - "line": 16, - "column": 42 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 36 - }, - "end": { - "line": 16, - "column": 43 - } - } - }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 16, @@ -350,45 +325,55 @@ }, "end": { "line": 16, - "column": 43 + "column": 42 } } + }, + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 16, + "column": 43 + } } - ], + }, "loc": { "start": { "line": 16, - "column": 35 + "column": 36 }, "end": { "line": 16, "column": 43 } } - }, - "loc": { - "start": { - "line": 16, - "column": 28 - }, - "end": { - "line": 16, - "column": 45 - } } - }, + ], "loc": { "start": { "line": 16, - "column": 28 + "column": 35 }, "end": { "line": 16, - "column": 45 + "column": 43 } } + }, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 45 + } } - ], + }, "loc": { "start": { "line": 16, @@ -412,60 +397,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 18 - }, - "end": { - "line": 17, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 26 - }, - "end": { - "line": 17, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 26 - }, - "end": { - "line": 17, - "column": 33 - } - } - }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -473,45 +433,55 @@ }, "end": { "line": 17, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 17, + "column": 26 + }, + "end": { + "line": 17, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 25 + "column": 26 }, "end": { "line": 17, "column": 33 } } - }, - "loc": { - "start": { - "line": 17, - "column": 18 - }, - "end": { - "line": 17, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 18 + "column": 25 }, "end": { "line": 17, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 17, @@ -788,60 +758,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 59 - }, - "end": { - "line": 22, - "column": 66 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 59 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 67 - }, - "end": { - "line": 22, - "column": 73 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 67 - }, - "end": { - "line": 22, - "column": 74 - } - } - }, + "end": { + "line": 22, + "column": 66 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -849,45 +794,55 @@ }, "end": { "line": 22, - "column": 74 + "column": 73 } } + }, + "loc": { + "start": { + "line": 22, + "column": 67 + }, + "end": { + "line": 22, + "column": 74 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 66 + "column": 67 }, "end": { "line": 22, "column": 74 } } - }, - "loc": { - "start": { - "line": 22, - "column": 59 - }, - "end": { - "line": 22, - "column": 76 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 59 + "column": 66 }, "end": { "line": 22, - "column": 76 + "column": 74 } } + }, + "loc": { + "start": { + "line": 22, + "column": 59 + }, + "end": { + "line": 22, + "column": 76 + } } - ], + }, "loc": { "start": { "line": 22, @@ -911,60 +866,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 18 - }, - "end": { - "line": 23, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 26 - }, - "end": { - "line": 23, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 26 - }, - "end": { - "line": 23, - "column": 33 - } - } - }, + "end": { + "line": 23, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 23, @@ -972,45 +902,55 @@ }, "end": { "line": 23, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 23, - "column": 25 + "column": 26 }, "end": { "line": 23, "column": 33 } } - }, - "loc": { - "start": { - "line": 23, - "column": 18 - }, - "end": { - "line": 23, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 23, - "column": 18 + "column": 25 }, "end": { "line": 23, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 23, @@ -1257,60 +1197,35 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 31 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 24 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 32 - }, - "end": { - "line": 22, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 32 - }, - "end": { - "line": 22, - "column": 39 - } - } - }, + "end": { + "line": 22, + "column": 31 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -1318,45 +1233,55 @@ }, "end": { "line": 22, - "column": 39 + "column": 38 } } + }, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 39 + } } - ], + }, "loc": { "start": { "line": 22, - "column": 31 + "column": 32 }, "end": { "line": 22, "column": 39 } } - }, - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 41 - } } - }, + ], "loc": { "start": { "line": 22, - "column": 24 + "column": 31 }, "end": { "line": 22, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 22, + "column": 24 + }, + "end": { + "line": 22, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 22, @@ -1490,60 +1415,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 26 - }, - "end": { - "line": 29, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 29, - "column": 26 - }, - "end": { - "line": 29, - "column": 33 - } - } - }, + "end": { + "line": 29, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 29, @@ -1551,45 +1451,55 @@ }, "end": { "line": 29, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 25 + "column": 26 }, "end": { "line": 29, "column": 33 } } - }, - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 18 + "column": 25 }, "end": { "line": 29, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 29, + "column": 18 + }, + "end": { + "line": 29, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 29, @@ -1890,60 +1800,35 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 25 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 18 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 33 - } - } - }, + "end": { + "line": 34, + "column": 25 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 34, @@ -1951,45 +1836,55 @@ }, "end": { "line": 34, - "column": 33 + "column": 32 } } + }, + "loc": { + "start": { + "line": 34, + "column": 26 + }, + "end": { + "line": 34, + "column": 33 + } } - ], + }, "loc": { "start": { "line": 34, - "column": 25 + "column": 26 }, "end": { "line": 34, "column": 33 } } - }, - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 35 - } } - }, + ], "loc": { "start": { "line": 34, - "column": 18 + "column": 25 }, "end": { "line": 34, - "column": 35 + "column": 33 } } + }, + "loc": { + "start": { + "line": 34, + "column": 18 + }, + "end": { + "line": 34, + "column": 35 + } } - ], + }, "loc": { "start": { "line": 34, @@ -2296,60 +2191,35 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 14 - }, - "end": { - "line": 38, - "column": 21 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 14 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 22 - }, - "end": { - "line": 38, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 38, - "column": 22 - }, - "end": { - "line": 38, - "column": 29 - } - } - }, + "end": { + "line": 38, + "column": 21 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 38, @@ -2357,45 +2227,55 @@ }, "end": { "line": 38, - "column": 29 + "column": 28 } } + }, + "loc": { + "start": { + "line": 38, + "column": 22 + }, + "end": { + "line": 38, + "column": 29 + } } - ], + }, "loc": { "start": { "line": 38, - "column": 21 + "column": 22 }, "end": { "line": 38, "column": 29 } } - }, - "loc": { - "start": { - "line": 38, - "column": 14 - }, - "end": { - "line": 38, - "column": 31 - } } - }, + ], "loc": { "start": { "line": 38, - "column": 14 + "column": 21 }, "end": { "line": 38, - "column": 31 + "column": 29 } } + }, + "loc": { + "start": { + "line": 38, + "column": 14 + }, + "end": { + "line": 38, + "column": 31 + } } - ], + }, "loc": { "start": { "line": 38, diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index dc41d3cfc8..4be4d2ea48 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -5325,38 +5325,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 9 - }, - "end": { - "line": 22, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 9 - }, - "end": { - "line": 22, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 22, @@ -5364,11 +5339,21 @@ }, "end": { "line": 22, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 22, diff --git a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt index dba2770439..cf852cc4c9 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt @@ -299,38 +299,13 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 18, @@ -338,11 +313,21 @@ }, "end": { "line": 18, - "column": 21 + "column": 19 } } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 18, diff --git a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt index e485881d1f..2f57863379 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt @@ -68,38 +68,13 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 17, @@ -107,11 +82,21 @@ }, "end": { "line": 17, - "column": 16 + "column": 14 } } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 17, @@ -570,38 +555,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 14 - }, - "end": { - "line": 23, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 14 - }, - "end": { - "line": 23, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 23, @@ -609,11 +569,21 @@ }, "end": { "line": 23, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 23, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt index 0fcb60e313..c8a3c89c36 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt @@ -437,38 +437,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 20, @@ -476,11 +451,21 @@ }, "end": { "line": 20, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt index d37fa6d813..9b424caf23 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt @@ -450,40 +450,15 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 16 - } - } - }, + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 20, @@ -491,22 +466,32 @@ }, "end": { "line": 20, - "column": 16 + "column": 15 } } }, "loc": { "start": { "line": 20, - "column": 18 + "column": 14 }, "end": { "line": 20, - "column": 19 + "column": 16 } } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 20, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt index 50334b8aef..2ac81c66dd 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt @@ -156,38 +156,13 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 14 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 18, @@ -195,11 +170,21 @@ }, "end": { "line": 18, - "column": 14 + "column": 12 } } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 14 + } } - ], + }, "loc": { "start": { "line": 18, diff --git a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt index 82e7920ea1..5dffc7d900 100644 --- a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt @@ -556,38 +556,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 21, @@ -595,11 +570,21 @@ }, "end": { "line": 21, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt index 205d6300be..1aed437dc3 100644 --- a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt @@ -847,38 +847,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "I", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], "loc": { "start": { "line": 25, @@ -886,11 +861,21 @@ }, "end": { "line": 25, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 25, + "column": 14 + }, + "end": { + "line": 25, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 25, diff --git a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt index cd6fc79aa5..66b6147871 100644 --- a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt @@ -556,38 +556,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 21, @@ -595,11 +570,21 @@ }, "end": { "line": 21, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 21, diff --git a/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt b/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt index d0923f2e15..32fb21e40b 100644 --- a/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_overrideWithNullable-expected.txt @@ -1141,38 +1141,13 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 27 - }, - "end": { - "line": 31, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 27 - }, - "end": { - "line": 31, - "column": 30 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 31, @@ -1180,11 +1155,21 @@ }, "end": { "line": 31, - "column": 30 + "column": 28 } } + }, + "loc": { + "start": { + "line": 31, + "column": 27 + }, + "end": { + "line": 31, + "column": 30 + } } - ], + }, "loc": { "start": { "line": 31, @@ -1361,38 +1346,13 @@ "type": "Identifier", "name": "t", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 40 - }, - "end": { - "line": 35, - "column": 41 - } - } - }, - "loc": { - "start": { - "line": 35, - "column": 40 - }, - "end": { - "line": 35, - "column": 43 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 35, @@ -1400,11 +1360,21 @@ }, "end": { "line": 35, - "column": 43 + "column": 41 } } + }, + "loc": { + "start": { + "line": 35, + "column": 40 + }, + "end": { + "line": 35, + "column": 43 + } } - ], + }, "loc": { "start": { "line": 35, diff --git a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt index 7b845a4755..7a4275b332 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt @@ -351,38 +351,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 14 - }, - "end": { - "line": 19, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 14 - }, - "end": { - "line": 19, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 19, @@ -390,11 +365,21 @@ }, "end": { "line": 19, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 19, diff --git a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt index 28f7594bba..df711d1502 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt @@ -120,38 +120,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 18, @@ -159,11 +134,21 @@ }, "end": { "line": 18, - "column": 21 + "column": 19 } } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 18, diff --git a/ets2panda/test/parser/ets/null-expected.txt b/ets2panda/test/parser/ets/null-expected.txt index 62948820bc..fe48855d56 100644 --- a/ets2panda/test/parser/ets/null-expected.txt +++ b/ets2panda/test/parser/ets/null-expected.txt @@ -218,11 +218,11 @@ "decorators": [], "loc": { "start": { - "line": 19, + "line": 18, "column": 5 }, "end": { - "line": 19, + "line": 18, "column": 6 } } @@ -232,11 +232,11 @@ "value": null, "loc": { "start": { - "line": 19, + "line": 18, "column": 22 }, "end": { - "line": 19, + "line": 18, "column": 26 } } @@ -274,11 +274,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 5 }, "end": { - "line": 20, + "line": 19, "column": 6 } } @@ -295,33 +295,33 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 19 }, "end": { - "line": 20, + "line": 19, "column": 22 } } }, "loc": { "start": { - "line": 20, + "line": 19, "column": 19 }, "end": { - "line": 20, + "line": 19, "column": 23 } } }, "loc": { "start": { - "line": 20, + "line": 19, "column": 19 }, "end": { - "line": 20, + "line": 19, "column": 23 } } @@ -329,11 +329,11 @@ "arguments": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 15 }, "end": { - "line": 20, + "line": 19, "column": 25 } } @@ -411,7 +411,7 @@ "type": "ClassProperty", "key": { "type": "Identifier", - "name": "a", + "name": "b", "decorators": [], "loc": { "start": { @@ -456,7 +456,7 @@ }, "end": { "line": 18, - "column": 13 + "column": 14 } } }, @@ -467,98 +467,6 @@ }, "end": { "line": 18, - "column": 13 - } - } - }, - "definite": false, - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "ClassProperty", - "key": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 5 - }, - "end": { - "line": 19, - "column": 6 - } - } - }, - "accessibility": "public", - "static": true, - "readonly": false, - "declare": false, - "optional": false, - "computed": false, - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 9 - }, - "end": { - "line": 19, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 9 - }, - "end": { - "line": 19, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 9 - }, - "end": { - "line": 19, - "column": 14 - } - } - } - ], - "loc": { - "start": { - "line": 19, - "column": 9 - }, - "end": { - "line": 19, "column": 14 } } @@ -584,11 +492,11 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 5 }, "end": { - "line": 20, + "line": 19, "column": 6 } } @@ -609,33 +517,33 @@ "decorators": [], "loc": { "start": { - "line": 20, + "line": 19, "column": 9 }, "end": { - "line": 20, + "line": 19, "column": 12 } } }, "loc": { "start": { - "line": 20, + "line": 19, "column": 9 }, "end": { - "line": 20, + "line": 19, "column": 14 } } }, "loc": { "start": { - "line": 20, + "line": 19, "column": 9 }, "end": { - "line": 20, + "line": 19, "column": 14 } } @@ -661,11 +569,11 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 10 }, "end": { - "line": 22, + "line": 21, "column": 13 } } @@ -685,11 +593,11 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 10 }, "end": { - "line": 22, + "line": 21, "column": 13 } } @@ -704,57 +612,42 @@ "type": "Identifier", "name": "arg", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 19 - }, - "end": { - "line": 22, - "column": 24 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 19 }, "end": { - "line": 22, - "column": 24 + "line": 21, + "column": 22 } } + }, + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 24 + } } - ], + }, "loc": { "start": { - "line": 22, + "line": 21, "column": 19 }, "end": { - "line": 22, + "line": 21, "column": 24 } } @@ -762,22 +655,22 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 14 }, "end": { - "line": 22, + "line": 21, "column": 24 } } }, "loc": { "start": { - "line": 22, + "line": 21, "column": 14 }, "end": { - "line": 22, + "line": 21, "column": 24 } } @@ -793,33 +686,33 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 33 }, "end": { - "line": 22, + "line": 21, "column": 37 } } }, "loc": { "start": { - "line": 22, + "line": 21, "column": 33 }, "end": { - "line": 22, + "line": 21, "column": 39 } } }, "loc": { "start": { - "line": 22, + "line": 21, "column": 33 }, "end": { - "line": 22, + "line": 21, "column": 39 } } @@ -829,33 +722,33 @@ "statements": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 38 }, "end": { - "line": 23, + "line": 22, "column": 2 } } }, "loc": { "start": { - "line": 22, + "line": 21, "column": 13 }, "end": { - "line": 23, + "line": 22, "column": 2 } } }, "loc": { "start": { - "line": 22, + "line": 21, "column": 13 }, "end": { - "line": 23, + "line": 22, "column": 2 } } @@ -864,11 +757,11 @@ "decorators": [], "loc": { "start": { - "line": 22, + "line": 21, "column": 1 }, "end": { - "line": 23, + "line": 22, "column": 2 } } @@ -881,11 +774,11 @@ "decorators": [], "loc": { "start": { - "line": 25, + "line": 24, "column": 10 }, "end": { - "line": 25, + "line": 24, "column": 14 } } @@ -905,11 +798,11 @@ "decorators": [], "loc": { "start": { - "line": 25, + "line": 24, "column": 10 }, "end": { - "line": 25, + "line": 24, "column": 14 } } @@ -928,33 +821,33 @@ "decorators": [], "loc": { "start": { - "line": 25, + "line": 24, "column": 18 }, "end": { - "line": 25, + "line": 24, "column": 22 } } }, "loc": { "start": { - "line": 25, + "line": 24, "column": 18 }, "end": { - "line": 25, + "line": 24, "column": 24 } } }, "loc": { "start": { - "line": 25, + "line": 24, "column": 18 }, "end": { - "line": 25, + "line": 24, "column": 24 } } @@ -972,70 +865,11 @@ "decorators": [], "loc": { "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 26, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 9 - }, - "end": { - "line": 26, - "column": 10 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 26, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 5 - }, - "end": { - "line": 26, - "column": 12 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 27, + "line": 25, "column": 5 }, "end": { - "line": 27, + "line": 25, "column": 8 } } @@ -1047,11 +881,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 25, "column": 9 }, "end": { - "line": 27, + "line": 25, "column": 10 } } @@ -1060,22 +894,22 @@ "optional": false, "loc": { "start": { - "line": 27, + "line": 25, "column": 5 }, "end": { - "line": 27, + "line": 25, "column": 11 } } }, "loc": { "start": { - "line": 27, + "line": 25, "column": 5 }, "end": { - "line": 27, + "line": 25, "column": 12 } } @@ -1090,11 +924,11 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 26, "column": 5 }, "end": { - "line": 28, + "line": 26, "column": 8 } } @@ -1106,11 +940,11 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 26, "column": 9 }, "end": { - "line": 28, + "line": 26, "column": 10 } } @@ -1119,22 +953,22 @@ "optional": false, "loc": { "start": { - "line": 28, + "line": 26, "column": 5 }, "end": { - "line": 28, + "line": 26, "column": 11 } } }, "loc": { "start": { - "line": 28, + "line": 26, "column": 5 }, "end": { - "line": 28, + "line": 26, "column": 12 } } @@ -1146,7 +980,7 @@ "type": "VariableDeclarator", "id": { "type": "Identifier", - "name": "d", + "name": "e", "typeAnnotation": { "type": "ETSTypeReference", "part": { @@ -1157,58 +991,71 @@ "decorators": [], "loc": { "start": { - "line": 30, + "line": 28, "column": 13 }, "end": { - "line": 30, + "line": 28, "column": 16 } } }, "loc": { "start": { - "line": 30, + "line": 28, "column": 13 }, "end": { - "line": 30, - "column": 17 + "line": 28, + "column": 18 } } }, "loc": { "start": { - "line": 30, + "line": 28, "column": 13 }, "end": { - "line": 30, - "column": 17 + "line": 28, + "column": 18 } } }, "decorators": [], "loc": { "start": { - "line": 30, + "line": 28, "column": 9 }, "end": { - "line": 30, + "line": 28, "column": 10 } } }, - "init": null, + "init": { + "type": "NullLiteral", + "value": null, + "loc": { + "start": { + "line": 28, + "column": 26 + }, + "end": { + "line": 28, + "column": 30 + } + } + }, "loc": { "start": { - "line": 30, + "line": 28, "column": 9 }, "end": { - "line": 30, - "column": 10 + "line": 28, + "column": 30 } } } @@ -1216,12 +1063,12 @@ "kind": "let", "loc": { "start": { - "line": 30, + "line": 28, "column": 5 }, "end": { - "line": 30, - "column": 17 + "line": 28, + "column": 31 } } }, @@ -1232,121 +1079,7 @@ "type": "VariableDeclarator", "id": { "type": "Identifier", - "name": "e", - "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 13 - }, - "end": { - "line": 31, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 13 - }, - "end": { - "line": 31, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 13 - }, - "end": { - "line": 31, - "column": 18 - } - } - } - ], - "loc": { - "start": { - "line": 31, - "column": 13 - }, - "end": { - "line": 31, - "column": 18 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 9 - }, - "end": { - "line": 31, - "column": 10 - } - } - }, - "init": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 31, - "column": 26 - }, - "end": { - "line": 31, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 9 - }, - "end": { - "line": 31, - "column": 30 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 31, - "column": 5 - }, - "end": { - "line": 31, - "column": 31 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "f", + "name": "f", "typeAnnotation": { "type": "ETSTypeReference", "part": { @@ -1357,33 +1090,33 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 29, "column": 13 }, "end": { - "line": 32, + "line": 29, "column": 16 } } }, "loc": { "start": { - "line": 32, + "line": 29, "column": 13 }, "end": { - "line": 32, + "line": 29, "column": 18 } } }, "loc": { "start": { - "line": 32, + "line": 29, "column": 13 }, "end": { - "line": 32, + "line": 29, "column": 18 } } @@ -1391,11 +1124,11 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 29, "column": 9 }, "end": { - "line": 32, + "line": 29, "column": 10 } } @@ -1412,33 +1145,33 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 29, "column": 23 }, "end": { - "line": 32, + "line": 29, "column": 26 } } }, "loc": { "start": { - "line": 32, + "line": 29, "column": 23 }, "end": { - "line": 32, + "line": 29, "column": 27 } } }, "loc": { "start": { - "line": 32, + "line": 29, "column": 23 }, "end": { - "line": 32, + "line": 29, "column": 27 } } @@ -1446,22 +1179,22 @@ "arguments": [], "loc": { "start": { - "line": 32, + "line": 29, "column": 19 }, "end": { - "line": 32, + "line": 29, "column": 29 } } }, "loc": { "start": { - "line": 32, + "line": 29, "column": 9 }, "end": { - "line": 32, + "line": 29, "column": 29 } } @@ -1470,11 +1203,11 @@ "kind": "let", "loc": { "start": { - "line": 32, + "line": 29, "column": 5 }, "end": { - "line": 32, + "line": 29, "column": 29 } } @@ -1489,70 +1222,11 @@ "decorators": [], "loc": { "start": { - "line": 34, - "column": 5 - }, - "end": { - "line": 34, - "column": 8 - } - } - }, - "arguments": [ - { - "type": "Identifier", - "name": "d", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 9 - }, - "end": { - "line": 34, - "column": 10 - } - } - } - ], - "optional": false, - "loc": { - "start": { - "line": 34, - "column": 5 - }, - "end": { - "line": 34, - "column": 11 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 5 - }, - "end": { - "line": 34, - "column": 12 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "foo", - "decorators": [], - "loc": { - "start": { - "line": 35, + "line": 31, "column": 5 }, "end": { - "line": 35, + "line": 31, "column": 8 } } @@ -1564,11 +1238,11 @@ "decorators": [], "loc": { "start": { - "line": 35, + "line": 31, "column": 9 }, "end": { - "line": 35, + "line": 31, "column": 10 } } @@ -1577,22 +1251,22 @@ "optional": false, "loc": { "start": { - "line": 35, + "line": 31, "column": 5 }, "end": { - "line": 35, + "line": 31, "column": 11 } } }, "loc": { "start": { - "line": 35, + "line": 31, "column": 5 }, "end": { - "line": 35, + "line": 31, "column": 12 } } @@ -1607,11 +1281,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 32, "column": 5 }, "end": { - "line": 36, + "line": 32, "column": 8 } } @@ -1623,11 +1297,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 32, "column": 9 }, "end": { - "line": 36, + "line": 32, "column": 10 } } @@ -1636,22 +1310,22 @@ "optional": false, "loc": { "start": { - "line": 36, + "line": 32, "column": 5 }, "end": { - "line": 36, + "line": 32, "column": 11 } } }, "loc": { "start": { - "line": 36, + "line": 32, "column": 5 }, "end": { - "line": 36, + "line": 32, "column": 12 } } @@ -1666,11 +1340,11 @@ "decorators": [], "loc": { "start": { - "line": 38, + "line": 34, "column": 5 }, "end": { - "line": 38, + "line": 34, "column": 8 } } @@ -1681,11 +1355,11 @@ "value": null, "loc": { "start": { - "line": 38, + "line": 34, "column": 9 }, "end": { - "line": 38, + "line": 34, "column": 13 } } @@ -1694,22 +1368,22 @@ "optional": false, "loc": { "start": { - "line": 38, + "line": 34, "column": 5 }, "end": { - "line": 38, + "line": 34, "column": 14 } } }, "loc": { "start": { - "line": 38, + "line": 34, "column": 5 }, "end": { - "line": 38, + "line": 34, "column": 15 } } @@ -1724,11 +1398,11 @@ "decorators": [], "loc": { "start": { - "line": 39, + "line": 35, "column": 5 }, "end": { - "line": 39, + "line": 35, "column": 8 } } @@ -1746,33 +1420,33 @@ "decorators": [], "loc": { "start": { - "line": 39, + "line": 35, "column": 13 }, "end": { - "line": 39, + "line": 35, "column": 16 } } }, "loc": { "start": { - "line": 39, + "line": 35, "column": 13 }, "end": { - "line": 39, + "line": 35, "column": 17 } } }, "loc": { "start": { - "line": 39, + "line": 35, "column": 13 }, "end": { - "line": 39, + "line": 35, "column": 17 } } @@ -1780,11 +1454,11 @@ "arguments": [], "loc": { "start": { - "line": 39, + "line": 35, "column": 9 }, "end": { - "line": 39, + "line": 35, "column": 19 } } @@ -1793,22 +1467,22 @@ "optional": false, "loc": { "start": { - "line": 39, + "line": 35, "column": 5 }, "end": { - "line": 39, + "line": 35, "column": 19 } } }, "loc": { "start": { - "line": 39, + "line": 35, "column": 5 }, "end": { - "line": 39, + "line": 35, "column": 20 } } @@ -1819,102 +1493,45 @@ "type": "LogicalExpression", "operator": "&&", "left": { - "type": "LogicalExpression", - "operator": "&&", + "type": "BinaryExpression", + "operator": "==", "left": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 41, - "column": 13 - }, - "end": { - "line": 41, - "column": 14 - } - } - }, - "right": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 41, - "column": 18 - }, - "end": { - "line": 41, - "column": 22 - } - } - }, + "type": "Identifier", + "name": "b", + "decorators": [], "loc": { "start": { - "line": 41, + "line": 37, "column": 13 }, "end": { - "line": 41, - "column": 22 + "line": 37, + "column": 14 } } }, "right": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 41, - "column": 26 - }, - "end": { - "line": 41, - "column": 27 - } - } - }, - "right": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 41, - "column": 31 - }, - "end": { - "line": 41, - "column": 35 - } - } - }, + "type": "NullLiteral", + "value": null, "loc": { "start": { - "line": 41, - "column": 26 + "line": 37, + "column": 18 }, "end": { - "line": 41, - "column": 35 + "line": 37, + "column": 22 } } }, "loc": { "start": { - "line": 41, + "line": 37, "column": 13 }, "end": { - "line": 41, - "column": 35 + "line": 37, + "column": 22 } } }, @@ -1927,12 +1544,12 @@ "decorators": [], "loc": { "start": { - "line": 41, - "column": 39 + "line": 37, + "column": 26 }, "end": { - "line": 41, - "column": 40 + "line": 37, + "column": 27 } } }, @@ -1941,160 +1558,103 @@ "value": null, "loc": { "start": { - "line": 41, - "column": 44 + "line": 37, + "column": 31 }, "end": { - "line": 41, - "column": 48 + "line": 37, + "column": 35 } } }, "loc": { "start": { - "line": 41, - "column": 39 + "line": 37, + "column": 26 }, "end": { - "line": 41, - "column": 48 + "line": 37, + "column": 35 } } }, "loc": { "start": { - "line": 41, + "line": 37, "column": 12 }, "end": { - "line": 41, - "column": 49 + "line": 37, + "column": 36 } } }, "second": null, "loc": { "start": { - "line": 41, + "line": 37, "column": 5 }, "end": { - "line": 41, - "column": 49 + "line": 37, + "column": 36 } } }, { "type": "AssertStatement", "test": { - "type": "LogicalExpression", - "operator": "&&", + "type": "BinaryExpression", + "operator": "!=", "left": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 42, - "column": 13 - }, - "end": { - "line": 42, - "column": 17 - } - } - }, - "right": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 22 - } - } - }, + "type": "NullLiteral", + "value": null, "loc": { "start": { - "line": 42, + "line": 38, "column": 13 }, "end": { - "line": 42, - "column": 22 + "line": 38, + "column": 17 } } }, "right": { - "type": "BinaryExpression", - "operator": "!=", - "left": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 42, - "column": 26 - }, - "end": { - "line": 42, - "column": 30 - } - } - }, - "right": { - "type": "Identifier", - "name": "c", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 34 - }, - "end": { - "line": 42, - "column": 35 - } - } - }, + "type": "Identifier", + "name": "c", + "decorators": [], "loc": { "start": { - "line": 42, - "column": 26 + "line": 38, + "column": 21 }, "end": { - "line": 42, - "column": 35 + "line": 38, + "column": 22 } } }, "loc": { "start": { - "line": 42, + "line": 38, "column": 12 }, "end": { - "line": 42, - "column": 36 + "line": 38, + "column": 23 } } }, "second": null, "loc": { "start": { - "line": 42, + "line": 38, "column": 5 }, "end": { - "line": 42, - "column": 36 + "line": 38, + "column": 23 } } }, @@ -2104,102 +1664,45 @@ "type": "LogicalExpression", "operator": "&&", "left": { - "type": "LogicalExpression", - "operator": "&&", + "type": "BinaryExpression", + "operator": "==", "left": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "d", - "decorators": [], - "loc": { - "start": { - "line": 43, - "column": 13 - }, - "end": { - "line": 43, - "column": 14 - } - } - }, - "right": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 43, - "column": 18 - }, - "end": { - "line": 43, - "column": 22 - } - } - }, + "type": "Identifier", + "name": "e", + "decorators": [], "loc": { "start": { - "line": 43, + "line": 39, "column": 13 }, "end": { - "line": 43, - "column": 22 + "line": 39, + "column": 14 } } }, "right": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "e", - "decorators": [], - "loc": { - "start": { - "line": 43, - "column": 26 - }, - "end": { - "line": 43, - "column": 27 - } - } - }, - "right": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 43, - "column": 31 - }, - "end": { - "line": 43, - "column": 35 - } - } - }, + "type": "NullLiteral", + "value": null, "loc": { "start": { - "line": 43, - "column": 26 + "line": 39, + "column": 18 }, "end": { - "line": 43, - "column": 35 + "line": 39, + "column": 22 } } }, "loc": { "start": { - "line": 43, + "line": 39, "column": 13 }, "end": { - "line": 43, - "column": 35 + "line": 39, + "column": 22 } } }, @@ -2212,12 +1715,12 @@ "decorators": [], "loc": { "start": { - "line": 43, - "column": 39 + "line": 39, + "column": 26 }, "end": { - "line": 43, - "column": 40 + "line": 39, + "column": 27 } } }, @@ -2226,220 +1729,104 @@ "value": null, "loc": { "start": { - "line": 43, - "column": 44 + "line": 39, + "column": 31 }, "end": { - "line": 43, - "column": 48 + "line": 39, + "column": 35 } } }, "loc": { "start": { - "line": 43, - "column": 39 + "line": 39, + "column": 26 }, "end": { - "line": 43, - "column": 48 + "line": 39, + "column": 35 } } }, "loc": { "start": { - "line": 43, + "line": 39, "column": 12 }, "end": { - "line": 43, - "column": 49 + "line": 39, + "column": 36 } } }, "second": null, "loc": { "start": { - "line": 43, + "line": 39, "column": 5 }, "end": { - "line": 43, - "column": 49 + "line": 39, + "column": 36 } } }, { "type": "AssertStatement", "test": { - "type": "LogicalExpression", - "operator": "&&", + "type": "BinaryExpression", + "operator": "==", "left": { - "type": "LogicalExpression", - "operator": "&&", - "left": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "a", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 13 - }, - "end": { - "line": 44, - "column": 14 - } - } - }, - "right": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 18 - }, - "end": { - "line": 44, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 44, - "column": 13 - }, - "end": { - "line": 44, - "column": 19 - } - } - }, - "right": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "b", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 23 - }, - "end": { - "line": 44, - "column": 24 - } - } - }, - "right": { - "type": "Identifier", - "name": "d", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 28 - }, - "end": { - "line": 44, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 44, - "column": 23 - }, - "end": { - "line": 44, - "column": 29 - } - } - }, + "type": "Identifier", + "name": "b", + "decorators": [], "loc": { "start": { - "line": 44, + "line": 40, "column": 13 }, "end": { - "line": 44, - "column": 29 + "line": 40, + "column": 14 } } }, "right": { - "type": "BinaryExpression", - "operator": "==", - "left": { - "type": "Identifier", - "name": "d", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 33 - }, - "end": { - "line": 44, - "column": 34 - } - } - }, - "right": { - "type": "Identifier", - "name": "e", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 38 - }, - "end": { - "line": 44, - "column": 39 - } - } - }, + "type": "Identifier", + "name": "e", + "decorators": [], "loc": { "start": { - "line": 44, - "column": 33 + "line": 40, + "column": 18 }, "end": { - "line": 44, - "column": 39 + "line": 40, + "column": 19 } } }, "loc": { "start": { - "line": 44, + "line": 40, "column": 12 }, "end": { - "line": 44, - "column": 40 + "line": 40, + "column": 20 } } }, "second": null, "loc": { "start": { - "line": 44, + "line": 40, "column": 5 }, "end": { - "line": 44, - "column": 40 + "line": 40, + "column": 20 } } }, @@ -2453,11 +1840,11 @@ "value": null, "loc": { "start": { - "line": 45, + "line": 41, "column": 13 }, "end": { - "line": 45, + "line": 41, "column": 17 } } @@ -2467,22 +1854,22 @@ "value": null, "loc": { "start": { - "line": 45, + "line": 41, "column": 21 }, "end": { - "line": 45, + "line": 41, "column": 25 } } }, "loc": { "start": { - "line": 45, + "line": 41, "column": 12 }, "end": { - "line": 45, + "line": 41, "column": 26 } } @@ -2490,11 +1877,11 @@ "second": null, "loc": { "start": { - "line": 45, + "line": 41, "column": 5 }, "end": { - "line": 45, + "line": 41, "column": 26 } } @@ -2504,11 +1891,11 @@ "argument": null, "loc": { "start": { - "line": 47, + "line": 43, "column": 5 }, "end": { - "line": 47, + "line": 43, "column": 12 } } @@ -2516,33 +1903,33 @@ ], "loc": { "start": { - "line": 25, + "line": 24, "column": 23 }, "end": { - "line": 48, + "line": 44, "column": 2 } } }, "loc": { "start": { - "line": 25, + "line": 24, "column": 14 }, "end": { - "line": 48, + "line": 44, "column": 2 } } }, "loc": { "start": { - "line": 25, + "line": 24, "column": 14 }, "end": { - "line": 48, + "line": 44, "column": 2 } } @@ -2551,11 +1938,11 @@ "decorators": [], "loc": { "start": { - "line": 25, + "line": 24, "column": 1 }, "end": { - "line": 48, + "line": 44, "column": 2 } } @@ -2590,7 +1977,7 @@ "column": 1 }, "end": { - "line": 49, + "line": 45, "column": 1 } } diff --git a/ets2panda/test/parser/ets/null.ets b/ets2panda/test/parser/ets/null.ets index f74a5af99c..011717a1bd 100644 --- a/ets2panda/test/parser/ets/null.ets +++ b/ets2panda/test/parser/ets/null.ets @@ -15,7 +15,6 @@ class cls {} -let a : cls; let b : cls | null = null; let c : cls = new cls(); @@ -23,25 +22,22 @@ function foo(arg: cls | null) : void { } function main(): void { - foo(a); foo(b); foo(c); - let d : cls; let e : cls | null = null; let f : cls = new cls(); - foo(d); foo(e); foo(f); foo(null); foo(new cls()); - assert (a == null && b == null && c != null) - assert (null == a && null != c) - assert (d == null && e == null && f != null) - assert (a == b && b == d && d == e) + assert (b == null && c != null) + assert (null != c) + assert (e == null && f != null) + assert (b == e) assert (null == null) return; diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index 5167140afe..78a7b9c1a8 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -248,38 +248,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 9 - }, - "end": { - "line": 17, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 9 - }, - "end": { - "line": 17, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 17, @@ -287,11 +262,21 @@ }, "end": { "line": 17, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 17, diff --git a/ets2panda/test/parser/ets/nullableType-expected.txt b/ets2panda/test/parser/ets/nullableType-expected.txt index 6f873f8e0e..4ffaa76dd6 100644 --- a/ets2panda/test/parser/ets/nullableType-expected.txt +++ b/ets2panda/test/parser/ets/nullableType-expected.txt @@ -513,65 +513,35 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 13 - }, - "end": { - "line": 19, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 13 - }, - "end": { - "line": 19, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 13 - }, - "end": { - "line": 19, - "column": 16 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 19, - "column": 12 + "column": 13 }, "end": { "line": 19, - "column": 16 + "column": 14 } } + }, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 19, @@ -612,38 +582,13 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 13 - }, - "end": { - "line": 20, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 20, @@ -651,11 +596,21 @@ }, "end": { "line": 20, - "column": 16 + "column": 14 } } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 16 + } } - ], + }, "loc": { "start": { "line": 20, @@ -765,65 +720,35 @@ } }, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A_alias", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 34 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 34 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A_alias", + "decorators": [], "loc": { "start": { "line": 22, - "column": 24 + "column": 25 }, "end": { "line": 22, - "column": 34 + "column": 32 } } + }, + "loc": { + "start": { + "line": 22, + "column": 25 + }, + "end": { + "line": 22, + "column": 34 + } } - ], + }, "loc": { "start": { "line": 22, @@ -989,38 +914,13 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 132, - "column": 15 - }, - "end": { - "line": 132, - "column": 16 - } - } - }, - "loc": { - "start": { - "line": 132, - "column": 15 - }, - "end": { - "line": 132, - "column": 18 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 132, @@ -1028,11 +928,21 @@ }, "end": { "line": 132, - "column": 18 + "column": 16 } } + }, + "loc": { + "start": { + "line": 132, + "column": 15 + }, + "end": { + "line": 132, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 132, @@ -1108,38 +1018,13 @@ "type": "Identifier", "name": "t", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 133, - "column": 18 - }, - "end": { - "line": 133, - "column": 19 - } - } - }, - "loc": { - "start": { - "line": 133, - "column": 18 - }, - "end": { - "line": 133, - "column": 21 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 133, @@ -1147,11 +1032,21 @@ }, "end": { "line": 133, - "column": 21 + "column": 19 } } + }, + "loc": { + "start": { + "line": 133, + "column": 18 + }, + "end": { + "line": 133, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 133, @@ -1188,38 +1083,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 133, - "column": 30 - }, - "end": { - "line": 133, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 133, - "column": 30 - }, - "end": { - "line": 133, - "column": 33 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 133, @@ -1227,13 +1097,23 @@ }, "end": { "line": 133, - "column": 33 + "column": 31 } } - } - ], - "loc": { - "start": { + }, + "loc": { + "start": { + "line": 133, + "column": 30 + }, + "end": { + "line": 133, + "column": 33 + } + } + }, + "loc": { + "start": { "line": 133, "column": 30 }, @@ -2028,38 +1908,13 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 11 - }, - "end": { - "line": 31, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 31, - "column": 11 - }, - "end": { - "line": 31, - "column": 19 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 31, @@ -2067,11 +1922,21 @@ }, "end": { "line": 31, - "column": 19 + "column": 17 } } + }, + "loc": { + "start": { + "line": 31, + "column": 11 + }, + "end": { + "line": 31, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 31, @@ -2142,38 +2007,13 @@ "type": "Identifier", "name": "b", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 32, - "column": 11 - }, - "end": { - "line": 32, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 32, - "column": 11 - }, - "end": { - "line": 32, - "column": 19 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 32, @@ -2181,11 +2021,21 @@ }, "end": { "line": 32, - "column": 19 + "column": 17 } } + }, + "loc": { + "start": { + "line": 32, + "column": 11 + }, + "end": { + "line": 32, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 32, @@ -2297,38 +2147,13 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 11 - }, - "end": { - "line": 33, - "column": 17 - } - } - }, - "loc": { - "start": { - "line": 33, - "column": 11 - }, - "end": { - "line": 33, - "column": 19 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 33, @@ -2336,11 +2161,21 @@ }, "end": { "line": 33, - "column": 19 + "column": 17 } } + }, + "loc": { + "start": { + "line": 33, + "column": 11 + }, + "end": { + "line": 33, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 33, @@ -2412,80 +2247,35 @@ "type": "Identifier", "name": "d", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 14 - }, - "end": { - "line": 34, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 14 - }, - "end": { - "line": 34, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 34, - "column": 13 - }, - "end": { - "line": 34, - "column": 21 - } - } - } - ], - "loc": { - "start": { - "line": 34, - "column": 12 - }, - "end": { - "line": 34, - "column": 21 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 34, - "column": 11 + "column": 14 }, "end": { "line": 34, - "column": 21 + "column": 20 } } + }, + "loc": { + "start": { + "line": 34, + "column": 14 + }, + "end": { + "line": 34, + "column": 21 + } } - ], + }, "loc": { "start": { "line": 34, @@ -2572,38 +2362,13 @@ "type": "Identifier", "name": "f", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 11 - }, - "end": { - "line": 35, - "column": 12 - } - } - }, - "loc": { - "start": { - "line": 35, - "column": 11 - }, - "end": { - "line": 35, - "column": 14 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 35, @@ -2611,11 +2376,21 @@ }, "end": { "line": 35, - "column": 14 + "column": 12 } } + }, + "loc": { + "start": { + "line": 35, + "column": 11 + }, + "end": { + "line": 35, + "column": 14 + } } - ], + }, "loc": { "start": { "line": 35, @@ -2686,38 +2461,13 @@ "type": "Identifier", "name": "g", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "tmp", - "decorators": [], - "loc": { - "start": { - "line": 36, - "column": 11 - }, - "end": { - "line": 36, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 36, - "column": 11 - }, - "end": { - "line": 36, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "tmp", + "decorators": [], "loc": { "start": { "line": 36, @@ -2725,17 +2475,27 @@ }, "end": { "line": 36, - "column": 16 + "column": 14 } } - } - ], - "loc": { - "start": { - "line": 36, - "column": 11 }, - "end": { + "loc": { + "start": { + "line": 36, + "column": 11 + }, + "end": { + "line": 36, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 11 + }, + "end": { "line": 36, "column": 16 } @@ -3111,75 +2871,35 @@ "type": "Identifier", "name": "generic", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 17 - }, - "end": { - "line": 42, - "column": 20 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 17 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 21 - }, - "end": { - "line": 42, - "column": 24 - } - } - } - ], + "end": { + "line": 42, + "column": 20 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 42, @@ -3187,45 +2907,55 @@ }, "end": { "line": 42, - "column": 24 + "column": 22 } } + }, + "loc": { + "start": { + "line": 42, + "column": 21 + }, + "end": { + "line": 42, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 42, - "column": 20 + "column": 21 }, "end": { "line": 42, - "column": 30 + "column": 24 } } - }, - "loc": { - "start": { - "line": 42, - "column": 17 - }, - "end": { - "line": 42, - "column": 32 - } } - }, + ], "loc": { "start": { "line": 42, - "column": 17 + "column": 20 }, "end": { "line": 42, - "column": 32 + "column": 30 } } + }, + "loc": { + "start": { + "line": 42, + "column": 17 + }, + "end": { + "line": 42, + "column": 32 + } } - ], + }, "loc": { "start": { "line": 42, @@ -3274,38 +3004,13 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 42, - "column": 48 - }, - "end": { - "line": 42, - "column": 49 - } - } - }, - "loc": { - "start": { - "line": 42, - "column": 48 - }, - "end": { - "line": 42, - "column": 51 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 42, @@ -3313,11 +3018,21 @@ }, "end": { "line": 42, - "column": 51 + "column": 49 } } + }, + "loc": { + "start": { + "line": 42, + "column": 48 + }, + "end": { + "line": 42, + "column": 51 + } } - ], + }, "loc": { "start": { "line": 42, @@ -3408,38 +3123,13 @@ "type": "Identifier", "name": "h", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Char", - "decorators": [], - "loc": { - "start": { - "line": 44, - "column": 11 - }, - "end": { - "line": 44, - "column": 15 - } - } - }, - "loc": { - "start": { - "line": 44, - "column": 11 - }, - "end": { - "line": 44, - "column": 17 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], "loc": { "start": { "line": 44, @@ -3447,11 +3137,21 @@ }, "end": { "line": 44, - "column": 17 + "column": 15 } } + }, + "loc": { + "start": { + "line": 44, + "column": 11 + }, + "end": { + "line": 44, + "column": 17 + } } - ], + }, "loc": { "start": { "line": 44, @@ -3625,75 +3325,35 @@ "type": "Identifier", "name": "gt1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 13 - }, - "end": { - "line": 47, - "column": 16 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 47, + "column": 13 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 47, - "column": 17 - }, - "end": { - "line": 47, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 17 - }, - "end": { - "line": 47, - "column": 20 - } - } - }, - "loc": { - "start": { - "line": 47, - "column": 17 - }, - "end": { - "line": 47, - "column": 20 - } - } - } - ], + "end": { + "line": 47, + "column": 16 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 47, @@ -3701,45 +3361,55 @@ }, "end": { "line": 47, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 47, + "column": 17 + }, + "end": { + "line": 47, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 47, - "column": 16 + "column": 17 }, "end": { "line": 47, - "column": 26 + "column": 20 } } - }, - "loc": { - "start": { - "line": 47, - "column": 13 - }, - "end": { - "line": 47, - "column": 28 - } } - }, + ], "loc": { "start": { "line": 47, - "column": 13 + "column": 16 }, "end": { "line": 47, - "column": 28 + "column": 26 } } + }, + "loc": { + "start": { + "line": 47, + "column": 13 + }, + "end": { + "line": 47, + "column": 28 + } } - ], + }, "loc": { "start": { "line": 47, @@ -4578,35 +4248,20 @@ "type": "Identifier", "name": "narr", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 61, - "column": 14 - }, - "end": { - "line": 61, - "column": 17 - } - } + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 61, + "column": 14 }, - "loc": { - "start": { - "line": 61, - "column": 20 - }, - "end": { - "line": 61, - "column": 21 - } + "end": { + "line": 61, + "column": 17 } } - ], + }, "loc": { "start": { "line": 61, @@ -4870,78 +4525,48 @@ "type": "Identifier", "name": "arron", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "TSArrayType", - "elementType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 66, - "column": 16 - }, - "end": { - "line": 66, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 66, - "column": 16 - }, - "end": { - "line": 66, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 66, - "column": 16 - }, - "end": { - "line": 66, - "column": 24 - } - } - } - ], + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 66, - "column": 15 + "column": 16 }, "end": { "line": 66, - "column": 24 + "column": 22 } } }, "loc": { "start": { "line": 66, - "column": 33 + "column": 16 }, "end": { "line": 66, - "column": 34 + "column": 24 } } + }, + "loc": { + "start": { + "line": 66, + "column": 15 + }, + "end": { + "line": 66, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 66, @@ -5721,38 +5346,13 @@ "type": "Identifier", "name": "on", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 77, - "column": 12 - }, - "end": { - "line": 77, - "column": 18 - } - } - }, - "loc": { - "start": { - "line": 77, - "column": 12 - }, - "end": { - "line": 77, - "column": 20 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 77, @@ -5760,11 +5360,21 @@ }, "end": { "line": 77, - "column": 20 + "column": 18 } } + }, + "loc": { + "start": { + "line": 77, + "column": 12 + }, + "end": { + "line": 77, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 77, @@ -6420,38 +6030,13 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 86, - "column": 12 - }, - "end": { - "line": 86, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 86, - "column": 12 - }, - "end": { - "line": 86, - "column": 15 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 86, @@ -6459,11 +6044,21 @@ }, "end": { "line": 86, - "column": 15 + "column": 13 } } + }, + "loc": { + "start": { + "line": 86, + "column": 12 + }, + "end": { + "line": 86, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 86, @@ -7666,38 +7261,13 @@ "type": "Identifier", "name": "bn", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], - "loc": { - "start": { - "line": 103, - "column": 12 - }, - "end": { - "line": 103, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 103, - "column": 12 - }, - "end": { - "line": 103, - "column": 15 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], "loc": { "start": { "line": 103, @@ -7705,11 +7275,21 @@ }, "end": { "line": 103, - "column": 15 + "column": 13 } } + }, + "loc": { + "start": { + "line": 103, + "column": 12 + }, + "end": { + "line": 103, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 103, @@ -8175,38 +7755,13 @@ "expression": false, "params": [], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 112, - "column": 33 - }, - "end": { - "line": 112, - "column": 39 - } - } - }, - "loc": { - "start": { - "line": 112, - "column": 33 - }, - "end": { - "line": 112, - "column": 41 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], "loc": { "start": { "line": 112, @@ -8214,11 +7769,21 @@ }, "end": { "line": 112, - "column": 41 + "column": 39 } } + }, + "loc": { + "start": { + "line": 112, + "column": 33 + }, + "end": { + "line": 112, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 112, @@ -8313,38 +7878,13 @@ "type": "Identifier", "name": "x", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 114, - "column": 10 - }, - "end": { - "line": 114, - "column": 13 - } - } - }, - "loc": { - "start": { - "line": 114, - "column": 10 - }, - "end": { - "line": 114, - "column": 15 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 114, @@ -8352,11 +7892,21 @@ }, "end": { "line": 114, - "column": 15 + "column": 13 } } + }, + "loc": { + "start": { + "line": 114, + "column": 10 + }, + "end": { + "line": 114, + "column": 15 + } } - ], + }, "loc": { "start": { "line": 114, @@ -8513,38 +8063,13 @@ "type": "Identifier", "name": "y", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Long", - "decorators": [], - "loc": { - "start": { - "line": 117, - "column": 10 - }, - "end": { - "line": 117, - "column": 14 - } - } - }, - "loc": { - "start": { - "line": 117, - "column": 10 - }, - "end": { - "line": 117, - "column": 16 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Long", + "decorators": [], "loc": { "start": { "line": 117, @@ -8552,13 +8077,23 @@ }, "end": { "line": 117, - "column": 16 + "column": 14 } } - } - ], - "loc": { - "start": { + }, + "loc": { + "start": { + "line": 117, + "column": 10 + }, + "end": { + "line": 117, + "column": 16 + } + } + }, + "loc": { + "start": { "line": 117, "column": 10 }, @@ -8800,38 +8335,13 @@ "type": "Identifier", "name": "arg1", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 123, - "column": 39 - }, - "end": { - "line": 123, - "column": 42 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 39 - }, - "end": { - "line": 123, - "column": 44 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 123, @@ -8839,11 +8349,21 @@ }, "end": { "line": 123, - "column": 44 + "column": 42 } } + }, + "loc": { + "start": { + "line": 123, + "column": 39 + }, + "end": { + "line": 123, + "column": 44 + } } - ], + }, "loc": { "start": { "line": 123, @@ -8884,65 +8404,35 @@ "type": "Identifier", "name": "args2", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "tmp", - "decorators": [], - "loc": { - "start": { - "line": 123, - "column": 67 - }, - "end": { - "line": 123, - "column": 70 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 67 - }, - "end": { - "line": 123, - "column": 72 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 67 - }, - "end": { - "line": 123, - "column": 72 - } - } - } - ], + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "tmp", + "decorators": [], "loc": { "start": { "line": 123, - "column": 66 + "column": 67 }, "end": { "line": 123, - "column": 72 + "column": 70 } } + }, + "loc": { + "start": { + "line": 123, + "column": 67 + }, + "end": { + "line": 123, + "column": 72 + } } - ], + }, "loc": { "start": { "line": 123, @@ -8979,38 +8469,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Char", - "decorators": [], - "loc": { - "start": { - "line": 123, - "column": 89 - }, - "end": { - "line": 123, - "column": 93 - } - } - }, - "loc": { - "start": { - "line": 123, - "column": 89 - }, - "end": { - "line": 123, - "column": 95 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], "loc": { "start": { "line": 123, @@ -9018,11 +8483,21 @@ }, "end": { "line": 123, - "column": 95 + "column": 93 } } + }, + "loc": { + "start": { + "line": 123, + "column": 89 + }, + "end": { + "line": 123, + "column": 95 + } } - ], + }, "loc": { "start": { "line": 123, @@ -9162,75 +8637,35 @@ "type": "Identifier", "name": "arg", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 41 - }, - "end": { - "line": 127, - "column": 44 - } - } + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 127, + "column": 41 }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 45 - }, - "end": { - "line": 127, - "column": 46 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 45 - }, - "end": { - "line": 127, - "column": 48 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 45 - }, - "end": { - "line": 127, - "column": 48 - } - } - } - ], + "end": { + "line": 127, + "column": 44 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 127, @@ -9238,45 +8673,55 @@ }, "end": { "line": 127, - "column": 48 + "column": 46 } } + }, + "loc": { + "start": { + "line": 127, + "column": 45 + }, + "end": { + "line": 127, + "column": 48 + } } - ], + }, "loc": { "start": { "line": 127, - "column": 44 + "column": 45 }, "end": { "line": 127, - "column": 54 + "column": 48 } } - }, - "loc": { - "start": { - "line": 127, - "column": 41 - }, - "end": { - "line": 127, - "column": 55 - } } - }, + ], "loc": { "start": { "line": 127, - "column": 40 + "column": 44 }, "end": { "line": 127, - "column": 55 + "column": 54 } } + }, + "loc": { + "start": { + "line": 127, + "column": 41 + }, + "end": { + "line": 127, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 127, @@ -9297,91 +8742,51 @@ "end": { "line": 127, "column": 55 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 34 - }, - "end": { - "line": 127, - "column": 55 - } - } - } - ], - "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Gen", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 66 - }, - "end": { - "line": 127, - "column": 69 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "tmp", - "decorators": [], - "loc": { - "start": { - "line": 127, - "column": 70 - }, - "end": { - "line": 127, - "column": 73 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 70 - }, - "end": { - "line": 127, - "column": 75 - } - } - }, - "loc": { - "start": { - "line": 127, - "column": 70 - }, - "end": { - "line": 127, - "column": 75 - } - } - } - ], + } + } + }, + "loc": { + "start": { + "line": 127, + "column": 34 + }, + "end": { + "line": 127, + "column": 55 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Gen", + "decorators": [], + "loc": { + "start": { + "line": 127, + "column": 66 + }, + "end": { + "line": 127, + "column": 69 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "tmp", + "decorators": [], "loc": { "start": { "line": 127, @@ -9389,45 +8794,55 @@ }, "end": { "line": 127, - "column": 75 + "column": 73 } } + }, + "loc": { + "start": { + "line": 127, + "column": 70 + }, + "end": { + "line": 127, + "column": 75 + } } - ], + }, "loc": { "start": { "line": 127, - "column": 69 + "column": 70 }, "end": { "line": 127, - "column": 81 + "column": 75 } } - }, - "loc": { - "start": { - "line": 127, - "column": 66 - }, - "end": { - "line": 127, - "column": 83 - } } - }, + ], "loc": { "start": { "line": 127, - "column": 66 + "column": 69 }, "end": { "line": 127, - "column": 83 + "column": 81 } } + }, + "loc": { + "start": { + "line": 127, + "column": 66 + }, + "end": { + "line": 127, + "column": 83 + } } - ], + }, "loc": { "start": { "line": 127, @@ -9568,38 +8983,13 @@ "type": "Identifier", "name": "arg", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 140, - "column": 37 - }, - "end": { - "line": 140, - "column": 38 - } - } - }, - "loc": { - "start": { - "line": 140, - "column": 37 - }, - "end": { - "line": 140, - "column": 40 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 140, @@ -9607,11 +8997,21 @@ }, "end": { "line": 140, - "column": 40 + "column": 38 } } + }, + "loc": { + "start": { + "line": 140, + "column": 37 + }, + "end": { + "line": 140, + "column": 40 + } } - ], + }, "loc": { "start": { "line": 140, @@ -9648,38 +9048,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], - "loc": { - "start": { - "line": 140, - "column": 49 - }, - "end": { - "line": 140, - "column": 50 - } - } - }, - "loc": { - "start": { - "line": 140, - "column": 49 - }, - "end": { - "line": 140, - "column": 52 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], "loc": { "start": { "line": 140, @@ -9687,11 +9062,21 @@ }, "end": { "line": 140, - "column": 52 + "column": 50 } } + }, + "loc": { + "start": { + "line": 140, + "column": 49 + }, + "end": { + "line": 140, + "column": 52 + } } - ], + }, "loc": { "start": { "line": 140, @@ -10079,38 +9464,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 146, - "column": 23 - }, - "end": { - "line": 146, - "column": 26 - } - } - }, - "loc": { - "start": { - "line": 146, - "column": 23 - }, - "end": { - "line": 146, - "column": 28 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 146, @@ -10118,11 +9478,21 @@ }, "end": { "line": 146, - "column": 28 + "column": 26 } } + }, + "loc": { + "start": { + "line": 146, + "column": 23 + }, + "end": { + "line": 146, + "column": 28 + } } - ], + }, "loc": { "start": { "line": 146, @@ -10209,38 +9579,13 @@ } ], "returnType": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 146, - "column": 47 - }, - "end": { - "line": 146, - "column": 50 - } - } - }, - "loc": { - "start": { - "line": 146, - "column": 47 - }, - "end": { - "line": 146, - "column": 52 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], "loc": { "start": { "line": 146, @@ -10248,11 +9593,21 @@ }, "end": { "line": 146, - "column": 52 + "column": 50 } } + }, + "loc": { + "start": { + "line": 146, + "column": 47 + }, + "end": { + "line": 146, + "column": 52 + } } - ], + }, "loc": { "start": { "line": 146, @@ -10702,38 +10057,13 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSUnionType", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 154, - "column": 27 - }, - "end": { - "line": 154, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 154, - "column": 27 - }, - "end": { - "line": 154, - "column": 30 - } - } - }, + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], "loc": { "start": { "line": 154, @@ -10741,11 +10071,21 @@ }, "end": { "line": 154, - "column": 30 + "column": 28 } } + }, + "loc": { + "start": { + "line": 154, + "column": 27 + }, + "end": { + "line": 154, + "column": 30 + } } - ], + }, "loc": { "start": { "line": 154, diff --git a/ets2panda/test/runtime/ets/DefaultParam_2.ets b/ets2panda/test/runtime/ets/DefaultParam_2.ets index 5c25eb66d0..d00f90d198 100644 --- a/ets2panda/test/runtime/ets/DefaultParam_2.ets +++ b/ets2panda/test/runtime/ets/DefaultParam_2.ets @@ -25,9 +25,9 @@ function main():void{ assert foo5(new Int(5),new Int(10)) == 45; - assert foo6() == null; - assert foo7() == null; - assert foo8() == null; + assert foo6() == undefined; + assert foo7() == undefined; + assert foo8() == undefined; assert foo9() == 0; assert foo9(new Int(5)) == -1; @@ -76,23 +76,23 @@ function foo5(a : Int = 10, b : Int = 20, c : Int = 30) : Int { return a + b + c; } -function foo6(a? : Int) : Int|null { +function foo6(a? : Int) : Int|undefined { return a; } -function foo7(a? : string) : string|null { +function foo7(a? : string) : string|undefined { return a; } -function foo8(a? : Boolean) : Boolean|null { +function foo8(a? : Boolean) : Boolean|undefined { return a; } function foo9(a? : Int, b? : Int) : Int { - if(a == null && b == null){ + if(a == undefined && b == undefined){ return 0; } - if(b == null){ + if(b == undefined){ return -1; } return a! + b!; @@ -100,10 +100,10 @@ function foo9(a? : Int, b? : Int) : Int { function foo10(a? : Int, b? : Int, c? : Int) : Int { assert a! == 5; - if(b == null && c == null){ + if(b == undefined && c == undefined){ return 0; } - if(c == null){ + if(c == undefined){ return -1; } @@ -111,7 +111,7 @@ function foo10(a? : Int, b? : Int, c? : Int) : Int { } function foo11(a : Int = 5, b? : Int) : Int { - if(b == null){ + if(b == undefined){ return 0; } return a + b!; @@ -120,7 +120,7 @@ function foo11(a : Int = 5, b? : Int) : Int { function foo12(a? : Int, b : Int = 5, c? : Int) : Int { assert b == 5; - if(a == null && c == null){ + if(a == undefined && c == undefined){ return 0; } diff --git a/ets2panda/test/runtime/ets/DefaultParam_4.ets b/ets2panda/test/runtime/ets/DefaultParam_4.ets index bc7106d7aa..696647a3b7 100644 --- a/ets2panda/test/runtime/ets/DefaultParam_4.ets +++ b/ets2panda/test/runtime/ets/DefaultParam_4.ets @@ -27,9 +27,9 @@ function main():void{ assert boo.foo5(new Int(5),new Int(10)) == 45; - assert boo.foo6() == null; - assert boo.foo7() == null; - assert boo.foo8() == null; + assert boo.foo6() == undefined; + assert boo.foo7() == undefined; + assert boo.foo8() == undefined; assert boo.foo9() == 0; assert boo.foo9(new Int(5)) == -1; @@ -79,23 +79,23 @@ class bar { return a + b + c; } - foo6(a? : Int) : Int|null { + foo6(a? : Int) : Int|undefined { return a; } - foo7(a? : string) : string|null { + foo7(a? : string) : string|undefined { return a; } - foo8(a? : Boolean) : Boolean|null { + foo8(a? : Boolean) : Boolean|undefined { return a; } foo9(a? : Int, b? : Int) : Int { - if(a == null && b == null){ + if(a == undefined && b == undefined){ return 0; } - if(b == null){ + if(b == undefined){ return -1; } return a! + b!; @@ -103,10 +103,10 @@ class bar { foo10(a? : Int, b? : Int, c? : Int) : Int { assert a! == 5; - if(b == null && c == null){ + if(b == undefined && c == undefined){ return 0; } - if(c == null){ + if(c == undefined){ return -1; } @@ -114,7 +114,7 @@ class bar { } foo11(a : Int = 5, b? : Int) : Int { - if(b == null){ + if(b == undefined){ return 0; } return a + b!; @@ -123,7 +123,7 @@ class bar { foo12(a? : Int, b : Int = 5, c? : Int) : Int { assert b == 5; - if(a == null && c == null){ + if(a == undefined && c == undefined){ return 0; } diff --git a/ets2panda/test/runtime/ets/NullishComparison.ets b/ets2panda/test/runtime/ets/NullishComparison.ets new file mode 100644 index 0000000000..11530a2a41 --- /dev/null +++ b/ets2panda/test/runtime/ets/NullishComparison.ets @@ -0,0 +1,46 @@ +/* + * 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. + */ + +const vnull = ((): Object | null | undefined => { return null })(); +const vundefined = ((): Object | null | undefined => { return undefined })(); +const vobject = ((): Object | null | undefined => { return new Object() })(); + +function main() { + assert(null === null); + assert(null !== undefined); + assert(null !== vobject); + assert(undefined === undefined); + assert(undefined !== vobject); + assert(vobject === vobject); + + assert(vnull === vnull); + assert(vnull !== vundefined); + assert(vnull !== vobject); + assert(vundefined === vundefined); + assert(vundefined !== vobject); + + assert(null == null); + assert(null == undefined); + assert(null != vobject); + assert(undefined == undefined); + assert(undefined != vobject); + assert(vobject == vobject); + + assert(vnull == vnull); + assert(vnull == vundefined); + assert(vnull != vobject); + assert(vundefined == vundefined); + assert(vundefined != vobject); +} diff --git a/ets2panda/test/runtime/ets/NullishConditionals.ets b/ets2panda/test/runtime/ets/NullishConditionals.ets new file mode 100644 index 0000000000..cc54383e4f --- /dev/null +++ b/ets2panda/test/runtime/ets/NullishConditionals.ets @@ -0,0 +1,34 @@ +/* + * 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 test_n(v: Object | null) { return v ? true : false } +function test_u(v: Object | undefined) { return v ? true : false } +function test_nu(v: Object | null | undefined) { return v ? true : false } + +function main() { + assert(test_n({})); + assert(test_u({})); + assert(test_nu({})); + + assert(!null); + if (null) { assert(false) } + assert(!test_n(null)); + assert(!test_nu(null)); + + assert(!undefined); + if (undefined) { assert(false) } + assert(!test_u(undefined)); + assert(!test_nu(undefined)); +} diff --git a/ets2panda/test/runtime/ets/NullishInstanceof.ets b/ets2panda/test/runtime/ets/NullishInstanceof.ets new file mode 100644 index 0000000000..076c3a182e --- /dev/null +++ b/ets2panda/test/runtime/ets/NullishInstanceof.ets @@ -0,0 +1,85 @@ +/* + * 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 is_null(v: Object | null | undefined) { + return v instanceof null; +} + +function is_undef(v: Object | null | undefined) { + return v instanceof undefined; +} + +function is_obj(v: Object | null | undefined) { + return v instanceof Object; +} + +class Foo { }; + +type nullish_obj = Object | null | undefined; +type nullish_int = Int | null | undefined; +type nullish_foo = Foo | null | undefined; + +function is_nullish_obj(v: nullish_obj) { + return v instanceof nullish_obj; +} + +function is_nullish_int(v: nullish_int) { + return v instanceof nullish_int; +} + +function is_nullish_foo(v: nullish_foo) { + return v instanceof nullish_foo; +} + +function is_nullish_foo_erased(v: nullish_obj) { + return v instanceof nullish_foo; +} + +function main() { + const obj = new Object(); + const foo = new Foo(); + const boxint = new Int(3); + + assert(is_null(null) == true); + assert(is_null(undefined) == false); + assert(is_null(obj) == false); + + assert(is_undef(null) == false); + assert(is_undef(undefined) == true); + assert(is_undef(obj) == false); + + assert(is_obj(null) == false); + assert(is_obj(undefined) == false); + assert(is_obj(obj) == true); + + assert(is_nullish_obj(null) == true); + assert(is_nullish_obj(undefined) == true); + assert(is_nullish_obj(obj) == true); + assert(is_nullish_obj(foo) == true); + + assert(is_nullish_int(null) == true); + assert(is_nullish_int(undefined) == true); + assert(is_nullish_int(boxint) == true); + + assert(is_nullish_foo(null) == true); + assert(is_nullish_foo(undefined) == true); + assert(is_nullish_foo(foo) == true); + + assert(is_nullish_foo_erased(null) == true); + assert(is_nullish_foo_erased(undefined) == true); + assert(is_nullish_foo_erased(obj) == false); + assert(is_nullish_foo_erased(boxint) == false); + assert(is_nullish_foo_erased(foo) == true); +} diff --git a/ets2panda/test/runtime/ets/OptionalCall.ets b/ets2panda/test/runtime/ets/OptionalCall.ets new file mode 100644 index 0000000000..8953a0a35c --- /dev/null +++ b/ets2panda/test/runtime/ets/OptionalCall.ets @@ -0,0 +1,43 @@ + +/* + * 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 Bar { + cb: (() => int) | undefined = () => { return 3 }; +} + +function foo(a: Int | null): (() => Int) | undefined { + let cb: () => Int = () => { return a!; }; + return a != null ? cb : undefined; +} + +function main(): void { + let a = new Int(3); + // assert foo(a)?.() == 3; // bug + assert foo(a)?.() == a; + + assert foo(null)?.() == null; + assert null == foo(null)?.(); + + assert foo(null)?.() == undefined; + assert undefined == foo(null)?.(); + + assert new Int(3) != foo(null)?.(); + + let b = new Bar(); + assert b.cb?.() == 3; + b.cb = undefined; + assert b.cb?.() == undefined; +} diff --git a/ets2panda/test/runtime/ets/class-init.ets b/ets2panda/test/runtime/ets/class-init.ets index 1c59312523..fe93bb4226 100644 --- a/ets2panda/test/runtime/ets/class-init.ets +++ b/ets2panda/test/runtime/ets/class-init.ets @@ -24,7 +24,7 @@ class cls { } class cls2 { - member_cls: cls; + member_cls: cls | null = null; member_int: int; } diff --git a/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets b/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets index bd9f12ccc2..af36ee6e0e 100644 --- a/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets +++ b/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets @@ -17,7 +17,7 @@ function main(): void { let x: int = 0; let potentiallyNullObj: Int[] | null = null; - let number = potentiallyNullObj?.[x++] ?? 2; + let number: Int | undefined = potentiallyNullObj?.[x++] ?? 2; assert(number == 2); assert(x == 0); // 0 as x was not incremented diff --git a/ets2panda/test/runtime/ets/struct-init.ets b/ets2panda/test/runtime/ets/struct-init.ets index 8b6afe3adc..49daf75500 100644 --- a/ets2panda/test/runtime/ets/struct-init.ets +++ b/ets2panda/test/runtime/ets/struct-init.ets @@ -24,7 +24,7 @@ struct cls { } struct cls2 { - member_cls: cls; + member_cls: cls | null = null; member_int: int; } diff --git a/ets2panda/test/union_types_4-expected.txt b/ets2panda/test/union_types_4-expected.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ets2panda/util/declgenEts2Ts.cpp b/ets2panda/util/declgenEts2Ts.cpp index 0f6a124c13..a1f2c4d90e 100644 --- a/ets2panda/util/declgenEts2Ts.cpp +++ b/ets2panda/util/declgenEts2Ts.cpp @@ -101,6 +101,20 @@ std::string TSDeclGen::GetKeyName(const ir::Expression *key) } void TSDeclGen::GenType(const checker::Type *checker_type) +{ + // NOTE: vpukhov. rewrite when nullish type is implemented with union + GenTypeNonNullish(checker_type); + if (checker_type->IsNullish()) { + if (checker_type->ContainsNull()) { + Out(" | null"); + } + if (checker_type->ContainsUndefined()) { + Out(" | undefined"); + } + } +} + +void TSDeclGen::GenTypeNonNullish(const checker::Type *checker_type) { ASSERT(checker_type != nullptr); DebugPrint(" GenType: "); @@ -209,8 +223,7 @@ void TSDeclGen::GenFunctionType(const checker::ETSFunctionType *ets_function_typ Out(param->Name()); const auto *param_type = param->TsType(); - if (param->HasFlag(varbinder::VariableFlags::OPTIONAL) || - param_type->HasTypeFlag(checker::TypeFlag::NULLABLE)) { + if (param->HasFlag(varbinder::VariableFlags::OPTIONAL) || param_type->IsNullish()) { Out("?"); } @@ -517,13 +530,8 @@ void TSDeclGen::GenPropDeclaration(const ir::ClassProperty *class_prop) GenModifier(class_prop); Out(prop_name); - const auto *prop_type = class_prop->TsType(); - if (prop_type->HasTypeFlag(checker::TypeFlag::NULLABLE)) { - Out("?"); - } - Out(": "); - GenType(prop_type); + GenType(class_prop->TsType()); Out(";"); OutEndl(); } diff --git a/ets2panda/util/declgenEts2Ts.h b/ets2panda/util/declgenEts2Ts.h index 7256080d30..0bed55d827 100644 --- a/ets2panda/util/declgenEts2Ts.h +++ b/ets2panda/util/declgenEts2Ts.h @@ -47,6 +47,7 @@ private: std::string GetKeyName(const ir::Expression *key); void GenType(const checker::Type *checker_type); + void GenTypeNonNullish(const checker::Type *checker_type); void GenFunctionType(const checker::ETSFunctionType *function_type, const ir::MethodDefinition *method_def = nullptr); void GenObjectType(const checker::ETSObjectType *object_type); diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index 4805f7324c..f0195c7dbc 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -73,6 +73,9 @@ util::StringView Helpers::LiteralToPropName(const ir::Expression *lit) case ir::AstNodeType::NULL_LITERAL: { return "null"; } + case ir::AstNodeType::UNDEFINED_LITERAL: { + return "undefined"; + } default: { UNREACHABLE(); } @@ -397,6 +400,9 @@ compiler::Literal Helpers::ToConstantLiteral(const ir::Expression *expr) case ir::AstNodeType::NULL_LITERAL: { return compiler::Literal::NullLiteral(); } + case ir::AstNodeType::UNDEFINED_LITERAL: { + return compiler::Literal::UndefinedLiteral(); + } default: break; } -- Gitee