diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index ad1b41851cc0af2da4a55f1360cd575c55a08a76..c30d3e9796e039d331c6b187f261c5ab8f190296 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -71,6 +71,8 @@ libes2panda_sources = [ "checker/types/ets/etsEnumType.cpp", "checker/types/ets/etsExtensionFuncHelperType.cpp", "checker/types/ets/etsFunctionType.cpp", + "checker/types/ets/etsNonNullishType.cpp", + "checker/types/ets/etsNullishTypes.cpp", "checker/types/ets/etsObjectType.cpp", "checker/types/ets/etsStringType.cpp", "checker/types/ets/etsTupleType.cpp", @@ -162,6 +164,7 @@ libes2panda_sources = [ "compiler/lowering/ets/lambdaLowering.cpp", "compiler/lowering/ets/objectIndexAccess.cpp", "compiler/lowering/ets/opAssignment.cpp", + "compiler/lowering/ets/optionalLowering.cpp", "compiler/lowering/ets/promiseVoid.cpp", "compiler/lowering/ets/structLowering.cpp", "compiler/lowering/ets/tupleLowering.cpp", @@ -200,6 +203,7 @@ libes2panda_sources = [ "ir/ets/etsNewArrayInstanceExpression.cpp", "ir/ets/etsNewClassInstanceExpression.cpp", "ir/ets/etsNewMultiDimArrayInstanceExpression.cpp", + "ir/ets/etsNullishTypes.cpp", "ir/ets/etsPackageDeclaration.cpp", "ir/ets/etsParameterExpression.cpp", "ir/ets/etsPrimitiveType.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 6a662e36a53ab20d753d63248b583dbee691beb2..d7a65786543796287794b8ba63a2063574b5214f 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -157,6 +157,7 @@ set(ES2PANDA_LIB_SRC compiler/lowering/ets/opAssignment.cpp compiler/lowering/ets/tupleLowering.cpp compiler/lowering/ets/unionLowering.cpp + compiler/lowering/ets/optionalLowering.cpp compiler/lowering/ets/expandBrackets.cpp compiler/lowering/ets/promiseVoid.cpp compiler/lowering/ets/structLowering.cpp @@ -264,6 +265,7 @@ set(ES2PANDA_LIB_SRC ir/ets/etsPackageDeclaration.cpp ir/ets/etsParameterExpression.cpp ir/ets/etsPrimitiveType.cpp + ir/ets/etsNullishTypes.cpp ir/ets/etsScript.cpp ir/ets/etsTuple.cpp ir/ets/etsTypeReference.cpp @@ -394,6 +396,8 @@ set(ES2PANDA_LIB_SRC checker/types/ets/etsEnumType.cpp checker/types/ets/etsExtensionFuncHelperType.cpp checker/types/ets/etsFunctionType.cpp + checker/types/ets/etsNonNullishType.cpp + checker/types/ets/etsNullishTypes.cpp checker/types/ets/etsObjectType.cpp checker/types/ets/etsStringType.cpp checker/types/ets/etsBigIntType.cpp diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 810934b8e53e9efea986fc479d2259ee75030a99..6a67ef00cbddce8b9ca3d3b77838bbea8932a557 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -168,7 +168,7 @@ static void CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, check static void CheckExtensionMethod(checker::ETSChecker *checker, ir::ScriptFunction *extensionFunc, ir::MethodDefinition *node) { - auto *const classType = ETSChecker::GetApparentType(extensionFunc->Signature()->Params()[0]->TsType()); + auto *const classType = checker->GetApparentType(extensionFunc->Signature()->Params()[0]->TsType()); if (!classType->IsETSObjectType() || (!classType->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::CLASS) && !classType->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::INTERFACE))) { @@ -194,8 +194,9 @@ void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::Scr } if (scriptFunc->IsAsyncFunc()) { - auto *retType = static_cast(scriptFunc->Signature()->ReturnType()); - if (retType->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { + auto *retType = scriptFunc->Signature()->ReturnType(); + if (!retType->IsETSObjectType() || + retType->AsETSObjectType()->GetOriginalBaseType() != checker->GlobalBuiltinPromiseType()) { checker->ThrowTypeError("Return type of async function must be 'Promise'.", scriptFunc->Start()); } } else if (scriptFunc->HasBody() && !scriptFunc->IsExternal()) { @@ -259,11 +260,16 @@ void CheckGetterSetterTypeConstrains(ETSChecker *checker, ir::ScriptFunction *sc checker::Type *ETSAnalyzer::Check(ir::MethodDefinition *node) const { ETSChecker *checker = GetETSChecker(); + auto *scriptFunc = node->Function(); if (scriptFunc->IsProxy()) { return nullptr; } + if (node->Id()->Variable() == nullptr) { + node->Id()->SetVariable(scriptFunc->Id()->Variable()); + } + // NOTE: aszilagyi. make it correctly check for open function not have body if (!scriptFunc->HasBody() && !(node->IsAbstract() || node->IsNative() || node->IsDeclare() || checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { @@ -411,57 +417,49 @@ checker::Type *ETSAnalyzer::Check(ir::ETSClassLiteral *expr) const checker::Type *ETSAnalyzer::Check(ir::ETSFunctionType *node) const { ETSChecker *checker = GetETSChecker(); - checker->CreateFunctionalInterfaceForFunctionType(node); - auto *interfaceType = - checker->CreateETSObjectType(node->FunctionalInterface()->Id()->Name(), node->FunctionalInterface(), - checker::ETSObjectFlags::FUNCTIONAL_INTERFACE); - interfaceType->SetSuperType(checker->GlobalETSObjectType()); - - auto *invokeFunc = node->FunctionalInterface()->Body()->Body()[0]->AsMethodDefinition()->Function(); - auto *signatureInfo = checker->Allocator()->New(checker->Allocator()); + auto *genericInterfaceType = checker->GlobalBuiltinFunctionType(node->Params().size()); + node->SetFunctionalInterface(genericInterfaceType->GetDeclNode()->AsTSInterfaceDeclaration()); - for (auto *it : invokeFunc->Params()) { - auto *const param = it->AsETSParameterExpression(); - if (param->IsRestParameter()) { - auto *restIdent = param->Ident(); - - ASSERT(restIdent->Variable()); - signatureInfo->restVar = restIdent->Variable()->AsLocalVariable(); + auto *tsType = checker->GetCachedFunctionlInterface(node); + node->SetTsType(tsType); + if (tsType != nullptr) { + return tsType; + } - ASSERT(param->TypeAnnotation()); - signatureInfo->restVar->SetTsType(checker->GetTypeFromTypeAnnotation(param->TypeAnnotation())); + auto *substitution = checker->NewSubstitution(); - auto arrayType = signatureInfo->restVar->TsType()->AsETSArrayType(); - checker->CreateBuiltinArraySignature(arrayType, arrayType->Rank()); - } else { - auto *paramIdent = param->Ident(); + auto maxParamsNum = checker->GlobalBuiltinFunctionTypeVariadicThreshold(); - ASSERT(paramIdent->Variable()); - varbinder::Variable *paramVar = paramIdent->Variable(); + auto const ¶ms = node->Params(); + size_t i = 0; + if (params.size() < maxParamsNum) { + for (; i < params.size(); i++) { + auto *paramType = params[i]->AsETSParameterExpression()->TypeAnnotation()->GetType(checker); + if (paramType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + checker->Relation()->SetNode(params[i]); + auto *const boxedTypeArg = checker->PrimitiveTypeAsETSBuiltinType(paramType); + ASSERT(boxedTypeArg); + paramType = boxedTypeArg->Instantiate(checker->Allocator(), checker->Relation(), + checker->GetGlobalTypesHolder()); + } - ASSERT(param->TypeAnnotation()); - paramVar->SetTsType(checker->GetTypeFromTypeAnnotation(param->TypeAnnotation())); - signatureInfo->params.push_back(paramVar->AsLocalVariable()); - ++signatureInfo->minArgCount; + checker::ETSChecker::EmplaceSubstituted( + substitution, genericInterfaceType->TypeArguments()[i]->AsETSTypeParameter()->GetOriginal(), paramType); } } - invokeFunc->ReturnTypeAnnotation()->Check(checker); - auto *signature = - checker->Allocator()->New(signatureInfo, node->ReturnType()->GetType(checker), invokeFunc); - signature->SetOwnerVar(invokeFunc->Id()->Variable()->AsLocalVariable()); - signature->AddSignatureFlag(checker::SignatureFlags::FUNCTIONAL_INTERFACE_SIGNATURE); - signature->SetOwner(interfaceType); + auto *returnType = node->ReturnType()->GetType(checker); + if (returnType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + checker->Relation()->SetNode(node->ReturnType()); + auto *const boxedTypeRet = checker->PrimitiveTypeAsETSBuiltinType(returnType); + returnType = + boxedTypeRet->Instantiate(checker->Allocator(), checker->Relation(), checker->GetGlobalTypesHolder()); + } - auto *funcType = checker->CreateETSFunctionType(signature); - invokeFunc->SetSignature(signature); - invokeFunc->Id()->Variable()->SetTsType(funcType); - interfaceType->AddProperty(invokeFunc->Id()->Variable()->AsLocalVariable()); - node->FunctionalInterface()->SetTsType(interfaceType); + checker::ETSChecker::EmplaceSubstituted( + substitution, genericInterfaceType->TypeArguments()[i]->AsETSTypeParameter()->GetOriginal(), returnType); - auto *thisVar = invokeFunc->Scope()->ParamScope()->Params().front(); - thisVar->SetTsType(interfaceType); - checker->BuildFunctionalInterfaceName(node); + auto *interfaceType = genericInterfaceType->Substitute(checker->Relation(), substitution)->AsETSObjectType(); node->SetTsType(interfaceType); return interfaceType; @@ -502,20 +500,18 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewArrayInstanceExpression *expr) const { ETSChecker *checker = GetETSChecker(); - auto *elementType = expr->typeReference_->GetType(checker); - checker->ValidateArrayIndex(expr->dimension_, true); + auto *elementType = expr->TypeReference()->GetType(checker); + checker->ValidateArrayIndex(expr->Dimension(), true); - if (!elementType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && !elementType->IsNullish() && - elementType->ToAssemblerName().str() != "Ball") { + if (!elementType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && elementType->ToAssemblerName().str() != "Ball") { // Ball is workaround for koala ui lib if (elementType->IsETSObjectType()) { auto *calleeObj = elementType->AsETSObjectType(); if (!calleeObj->HasObjectFlag(checker::ETSObjectFlags::ABSTRACT)) { // A workaround check for new Interface[...] in test cases - expr->defaultConstructorSignature_ = - checker->CollectParameterlessConstructor(calleeObj->ConstructSignatures(), expr->Start()); - checker->ValidateSignatureAccessibility(calleeObj, nullptr, expr->defaultConstructorSignature_, - expr->Start()); + expr->SetSignature( + checker->CollectParameterlessConstructor(calleeObj->ConstructSignatures(), expr->Start())); + checker->ValidateSignatureAccessibility(calleeObj, nullptr, expr->Signature(), expr->Start()); } } } @@ -564,7 +560,7 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewClassInstanceExpression *expr) const auto *signature = checker->ResolveConstructExpression(calleeObj, expr->GetArguments(), expr->Start()); checker->CheckObjectLiteralArguments(signature, expr->GetArguments()); - checker->AddUndefinedParamsForDefaultParams(signature, expr->arguments_, checker); + checker->AddUndefinedParamsForDefaultParams(signature, expr, expr->arguments_, checker); checker->ValidateSignatureAccessibility(calleeObj, nullptr, signature, expr->Start()); @@ -591,15 +587,15 @@ checker::Type *ETSAnalyzer::Check(ir::ETSNewClassInstanceExpression *expr) const checker::Type *ETSAnalyzer::Check(ir::ETSNewMultiDimArrayInstanceExpression *expr) const { ETSChecker *checker = GetETSChecker(); - auto *elementType = expr->typeReference_->GetType(checker); + auto *elementType = expr->TypeReference()->GetType(checker); - for (auto *dim : expr->dimensions_) { - checker->ValidateArrayIndex(dim); + for (auto *dim : expr->Dimensions()) { + checker->ValidateArrayIndex(dim, true); elementType = checker->CreateETSArrayType(elementType); } expr->SetTsType(elementType); - expr->signature_ = checker->CreateBuiltinArraySignature(elementType->AsETSArrayType(), expr->dimensions_.size()); + expr->SetSignature(checker->CreateBuiltinArraySignature(elementType->AsETSArrayType(), expr->Dimensions().size())); return expr->TsType(); } @@ -659,6 +655,16 @@ checker::Type *ETSAnalyzer::Check(ir::ETSTypeReferencePart *node) const return node->GetType(checker); } +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSNullType *node) const +{ + return nullptr; +} + +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ETSUndefinedType *node) const +{ + return nullptr; +} + checker::Type *ETSAnalyzer::Check(ir::ETSUnionType *node) const { (void)node; @@ -759,8 +765,9 @@ checker::Type *ETSAnalyzer::Check(ir::ArrowFunctionExpression *expr) const auto *funcType = checker->BuildFunctionSignature(expr->Function(), false); if (expr->Function()->IsAsyncFunc()) { - auto *retType = static_cast(expr->Function()->Signature()->ReturnType()); - if (retType->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { + auto *retType = expr->Function()->Signature()->ReturnType(); + if (!retType->IsETSObjectType() || + retType->AsETSObjectType()->GetOriginalBaseType() != checker->GlobalBuiltinPromiseType()) { checker->ThrowTypeError("Return type of async lambda must be 'Promise'", expr->Function()->Start()); } } @@ -821,8 +828,13 @@ checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const checker->ThrowTypeError("Setting the length of an array is not permitted", expr->Left()->Start()); } - expr->target_ = expr->Left()->IsIdentifier() ? expr->Left()->AsIdentifier()->Variable() - : expr->Left()->AsMemberExpression()->PropVar(); + if (expr->Left()->IsIdentifier()) { + expr->target_ = expr->Left()->AsIdentifier()->Variable(); + } else if (expr->Left()->IsMemberExpression()) { + expr->target_ = expr->Left()->AsMemberExpression()->PropVar(); + } else { + checker->ThrowTypeError("Invalid left-hand side of assignment expression", expr->Left()->Start()); + } if (expr->target_ != nullptr) { checker->ValidateUnaryOperatorOperand(expr->target_); @@ -895,10 +907,10 @@ checker::Type *ETSAnalyzer::Check(ir::AwaitExpression *expr) const return expr->TsType(); } - checker::Type *argType = ETSChecker::GetApparentType(expr->argument_->Check(checker)); + checker::Type *argType = checker->GetApparentType(expr->argument_->Check(checker)); // Check the argument type of await expression if (!argType->IsETSObjectType() || - (argType->AsETSObjectType()->AssemblerName() != compiler::Signatures::BUILTIN_PROMISE)) { + (argType->AsETSObjectType()->GetOriginalBaseType() != checker->GlobalBuiltinPromiseType())) { checker->ThrowTypeError("'await' expressions require Promise object as argument.", expr->Argument()->Start()); } @@ -923,10 +935,19 @@ static checker::Type *InitAnonymousLambdaCallee(checker::ETSChecker *checker, ir checker::Type *calleeType) { auto *const arrowFunc = callee->AsArrowFunctionExpression()->Function(); - auto origParams = arrowFunc->Params(); - auto signature = ir::FunctionSignature(nullptr, std::move(origParams), arrowFunc->ReturnTypeAnnotation()); - auto *funcType = - checker->Allocator()->New(std::move(signature), ir::ScriptFunctionFlags::NONE); + + ArenaVector params {checker->Allocator()->Adapter()}; + checker->CopyParams(arrowFunc->Params(), params); + + auto *typeAnnotation = arrowFunc->ReturnTypeAnnotation(); + if (typeAnnotation != nullptr) { + typeAnnotation = typeAnnotation->Clone(checker->Allocator(), nullptr); + typeAnnotation->SetTsType(arrowFunc->ReturnTypeAnnotation()->TsType()); + } + + auto signature = ir::FunctionSignature(nullptr, std::move(params), typeAnnotation); + auto *funcType = checker->AllocNode(std::move(signature), ir::ScriptFunctionFlags::NONE); + funcType->SetScope(arrowFunc->Scope()->AsFunctionScope()->ParamScope()); auto *const funcIface = funcType->Check(checker); checker->Relation()->SetNode(callee); @@ -1016,7 +1037,7 @@ ArenaVector &ChooseSignatures(ETSChecker *checker, checker } if (isFunctionalInterface) { return calleeType->AsETSObjectType() - ->GetOwnProperty("invoke") + ->GetOwnProperty(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME) ->TsType() ->AsETSFunctionType() ->CallSignatures(); @@ -1087,7 +1108,7 @@ checker::Type *ETSAnalyzer::GetReturnType(ir::CallExpression *expr, checker::Typ ResolveSignature(checker, expr, calleeType, isFunctionalInterface, isUnionTypeWithFunctionalInterface); checker->CheckObjectLiteralArguments(signature, expr->Arguments()); - checker->AddUndefinedParamsForDefaultParams(signature, expr->Arguments(), checker); + checker->AddUndefinedParamsForDefaultParams(signature, expr, expr->Arguments(), checker); if (!isFunctionalInterface) { checker::ETSObjectType *calleeObj = ChooseCalleeObj(checker, expr, calleeType, isConstructorCall); @@ -1123,16 +1144,15 @@ checker::Type *ETSAnalyzer::Check(ir::CallExpression *expr) const if (expr->TsType() != nullptr) { return expr->TsType(); } + ASSERT(!expr->IsOptional()); auto *oldCallee = expr->Callee(); - checker::Type *calleeType = ETSChecker::GetApparentType(expr->Callee()->Check(checker)); + checker::Type *calleeType = checker->GetApparentType(expr->Callee()->Check(checker)); if (expr->Callee() != oldCallee) { // If it is a static invoke, the callee will be transformed from an identifier to a member expression // Type check the callee again for member expression - calleeType = expr->Callee()->Check(checker); - } - if (!expr->IsOptional()) { - checker->CheckNonNullishType(calleeType, expr->Callee()->Start()); + calleeType = checker->GetApparentType(expr->Callee()->Check(checker)); } + checker->CheckNonNullish(expr->Callee()); checker::Type *returnType; if (calleeType->IsETSDynamicType() && !calleeType->AsETSDynamicType()->HasDecl()) { // Trailing lambda for js function call is not supported, check the correctness of `foo() {}` @@ -1156,20 +1176,17 @@ checker::Type *ETSAnalyzer::Check(ir::CallExpression *expr) const returnType = expr->Signature()->ReturnType(); // NOTE(vpukhov): #14902 substituted signature is not updated } - expr->SetOptionalType(returnType); - if (expr->IsOptional() && checker->MayHaveNulllikeValue(expr->Callee()->Check(checker))) { - checker->Relation()->SetNode(expr); - returnType = checker->CreateOptionalResultType(returnType); - checker->Relation()->SetNode(nullptr); - } expr->SetTsType(returnType); expr->SetUncheckedType(checker->GuaranteedTypeForUncheckedCallReturn(expr->Signature())); + if (expr->UncheckedType() != nullptr) { + checker->ComputeApparentType(returnType); + } return expr->TsType(); } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ChainExpression *expr) const { - UNREACHABLE(); + UNREACHABLE(); // eliminated in OptionalLowering } checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ClassExpression *expr) const @@ -1185,54 +1202,20 @@ checker::Type *ETSAnalyzer::Check(ir::ConditionalExpression *expr) const } checker->CheckTruthinessOfType(expr->Test()); + auto *const consequent = expr->consequent_; + auto *const alternate = expr->alternate_; + auto *const consequentType = consequent->Check(checker); + auto *const alternateType = alternate->Check(checker); - checker::Type *consequentType = expr->consequent_->Check(checker); - checker::Type *alternateType = expr->alternate_->Check(checker); - - auto *primitiveConsequentType = checker->ETSBuiltinTypeAsPrimitiveType(consequentType); - auto *primitiveAlterType = checker->ETSBuiltinTypeAsPrimitiveType(alternateType); - - if (primitiveConsequentType != nullptr && primitiveAlterType != nullptr) { - if (checker->IsTypeIdenticalTo(consequentType, alternateType)) { - expr->SetTsType(checker->GetNonConstantTypeFromPrimitiveType(consequentType)); - } else if (checker->IsTypeIdenticalTo(primitiveConsequentType, primitiveAlterType)) { - checker->FlagExpressionWithUnboxing(expr->consequent_->TsType(), primitiveConsequentType, - expr->consequent_); - checker->FlagExpressionWithUnboxing(expr->alternate_->TsType(), primitiveAlterType, expr->alternate_); - - expr->SetTsType(primitiveConsequentType); - } else if (primitiveConsequentType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) && - primitiveAlterType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { - checker->FlagExpressionWithUnboxing(expr->consequent_->TsType(), primitiveConsequentType, - expr->consequent_); - checker->FlagExpressionWithUnboxing(expr->alternate_->TsType(), primitiveAlterType, expr->alternate_); - - expr->SetTsType( - checker->ApplyConditionalOperatorPromotion(checker, primitiveConsequentType, primitiveAlterType)); - } else { - checker->ThrowTypeError("Type error", expr->Range().start); - } + if (checker->IsTypeIdenticalTo(consequentType, alternateType)) { + expr->SetTsType(checker->GetNonConstantTypeFromPrimitiveType(consequentType)); } else { - if (!(consequentType->IsETSArrayType() || alternateType->IsETSArrayType()) && - !(checker->IsReferenceType(consequentType) && checker->IsReferenceType(alternateType))) { - checker->ThrowTypeError("Type error", expr->Range().start); - } else { - checker->Relation()->SetNode(expr->consequent_); - auto builtinConseqType = checker->PrimitiveTypeAsETSBuiltinType(consequentType); - auto builtinAlternateType = checker->PrimitiveTypeAsETSBuiltinType(alternateType); - - if (builtinConseqType == nullptr) { - builtinConseqType = consequentType; - } - - if (builtinAlternateType == nullptr) { - builtinAlternateType = alternateType; - } - - expr->SetTsType(checker->CreateETSUnionType(builtinConseqType, builtinAlternateType)); + expr->SetTsType(checker->CreateETSUnionType({consequentType, alternateType})); + if (expr->TsType()->IsETSReferenceType()) { + checker->MaybeBoxExpression(consequent); + checker->MaybeBoxExpression(alternate); } } - return expr->TsType(); } @@ -1277,25 +1260,10 @@ checker::Type *ETSAnalyzer::Check(ir::MemberExpression *expr) const if (expr->TsType() != nullptr) { return expr->TsType(); } + ASSERT(!expr->IsOptional()); - auto *const leftType = checker->GetApparentType(expr->Object()->Check(checker)); - - if (expr->Kind() == ir::MemberExpressionKind::ELEMENT_ACCESS) { - if (expr->IsOptional() && !leftType->IsNullish()) { - checker->ThrowTypeError("The type of the object reference must be a nullish array or Record type", - expr->Object()->Start()); - } - - if (!expr->IsOptional() && leftType->IsNullish()) { - checker->ThrowTypeError("The type of the object reference must be a non-nullish array or Record type", - expr->Object()->Start()); - } - } - - auto *const baseType = expr->IsOptional() ? checker->GetNonNullishType(leftType) : leftType; - if (!expr->IsOptional()) { - checker->CheckNonNullishType(leftType, expr->Object()->Start()); - } + auto *const baseType = checker->GetApparentType(expr->Object()->Check(checker)); + checker->CheckNonNullish(expr->Object()); if (expr->IsComputed()) { return expr->AdjustType(checker, expr->CheckComputed(checker, baseType)); @@ -1450,7 +1418,7 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::OmittedExpression *expr) checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::OpaqueTypeNode *expr) const { - UNREACHABLE(); + return expr->TsType(); } checker::Type *ETSAnalyzer::Check(ir::SequenceExpression *expr) const @@ -2160,22 +2128,35 @@ void CheckArgumentVoidType(checker::Type *&funcReturnType, ETSChecker *checker, } void CheckReturnType(ETSChecker *checker, checker::Type *funcReturnType, checker::Type *argumentType, - ir::Expression *stArgument) + ir::Expression *stArgument, bool isAsync) { if (funcReturnType->IsETSVoidType() || funcReturnType == checker->GlobalBuiltinVoidType()) { if (argumentType != checker->GlobalVoidType() && argumentType != checker->GlobalBuiltinVoidType()) { checker->ThrowTypeError("Unexpected return value, enclosing method return type is void.", stArgument->Start()); } - } else { - const Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(funcReturnType); - const Type *sourceType = checker->TryGettingFunctionTypeFromInvokeFunction(argumentType); + checker::AssignmentContext(checker->Relation(), stArgument, argumentType, funcReturnType, stArgument->Start(), + {"Return statement type is not compatible with the enclosing method's return type."}, + checker::TypeRelationFlag::DIRECT_RETURN); + return; + } - checker::AssignmentContext( - checker->Relation(), stArgument, argumentType, funcReturnType, stArgument->Start(), - {"Type '", sourceType, "' is not compatible with the enclosing method's return type '", targetType, "'"}, - checker::TypeRelationFlag::DIRECT_RETURN); + if (isAsync && funcReturnType->IsETSObjectType() && + funcReturnType->AsETSObjectType()->GetOriginalBaseType() == checker->GlobalBuiltinPromiseType()) { + auto promiseArg = funcReturnType->AsETSObjectType()->TypeArguments()[0]; + checker::AssignmentContext(checker->Relation(), stArgument, argumentType, promiseArg, stArgument->Start(), {}, + checker::TypeRelationFlag::DIRECT_RETURN | checker::TypeRelationFlag::NO_THROW); + if (checker->Relation()->IsTrue()) { + return; + } } + + const Type *targetType = checker->TryGettingFunctionTypeFromInvokeFunction(funcReturnType); + const Type *sourceType = checker->TryGettingFunctionTypeFromInvokeFunction(argumentType); + checker::AssignmentContext( + checker->Relation(), stArgument, argumentType, funcReturnType, stArgument->Start(), + {"Type '", sourceType, "' is not compatible with the enclosing method's return type '", targetType, "'"}, + checker::TypeRelationFlag::DIRECT_RETURN); } void InferReturnType(ETSChecker *checker, ir::ScriptFunction *containingFunc, checker::Type *&funcReturnType, @@ -2290,7 +2271,7 @@ checker::Type *ETSAnalyzer::GetFunctionReturnType(ir::ReturnStatement *st, ir::S } // Case when function's return type is defined explicitly: - funcReturnType = checker->GetTypeFromTypeAnnotation(returnTypeAnnotation); + funcReturnType = returnTypeAnnotation->GetType(checker); if (st->argument_ == nullptr) { if (!funcReturnType->IsETSVoidType() && funcReturnType != checker->GlobalBuiltinVoidType()) { @@ -2316,7 +2297,7 @@ checker::Type *ETSAnalyzer::GetFunctionReturnType(ir::ReturnStatement *st, ir::S checker::Type *argumentType = st->argument_->Check(checker); - CheckReturnType(checker, funcReturnType, argumentType, st->argument_); + CheckReturnType(checker, funcReturnType, argumentType, st->argument_, containingFunc->IsAsyncFunc()); } } else { // Case when function's return type should be inferred from return statement(s): @@ -2559,6 +2540,7 @@ checker::Type *ETSAnalyzer::Check(ir::TSAsExpression *expr) const checker->CreateBuiltinArraySignature(targetArrayType, targetArrayType->Rank()); } + checker->ComputeApparentType(targetType); expr->SetTsType(targetType); return expr->TsType(); } @@ -2722,12 +2704,12 @@ checker::Type *ETSAnalyzer::Check(ir::TSNonNullExpression *expr) const ETSChecker *checker = GetETSChecker(); auto exprType = expr->expr_->Check(checker); - if (!checker->MayHaveNulllikeValue(exprType)) { - checker->ThrowTypeError("Bad operand type, the operand of the non-null expression must be a nullable type", + if (!exprType->PossiblyETSNullish()) { + checker->ThrowTypeError("Bad operand type, the operand of the non-nullish expression must be a nullish type", expr->Expr()->Start()); } - expr->SetTsType(exprType->IsNullish() ? checker->GetNonNullishType(exprType) : exprType); + expr->SetTsType(checker->GetNonNullishType(exprType)); return expr->TsType(); } diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 834464fcb7aeca39c4c8fd21343bc27fcfbbeafd..658153da91d0fd7406fcec379d6cf5b70f102fba 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -29,6 +29,73 @@ #include "util/helpers.h" namespace panda::es2panda::checker { + +static util::StringView InitBuiltin(ETSChecker *checker, std::string_view signature) +{ + const auto varMap = checker->VarBinder()->TopScope()->Bindings(); + const auto iterator = varMap.find(signature); + ASSERT(iterator != varMap.end()); + auto *var = iterator->second; + Type *type {nullptr}; + if (var->Declaration()->Node()->IsClassDefinition()) { + type = checker->BuildBasicClassProperties(var->Declaration()->Node()->AsClassDefinition()); + } else { + ASSERT(var->Declaration()->Node()->IsTSInterfaceDeclaration()); + type = checker->BuildBasicInterfaceProperties(var->Declaration()->Node()->AsTSInterfaceDeclaration()); + } + checker->GetGlobalTypesHolder()->InitializeBuiltin(iterator->first, type); + return iterator->first; +} + +static void SetupFunctionalInterface(ETSChecker *checker, ETSObjectType *type) +{ + auto savedContext = SavedCheckerContext(checker, checker::CheckerStatus::IN_INTERFACE, type); + checker::ScopeContext scopeCtx(checker, type->GetDeclNode()->Scope()); + checker->ResolveDeclaredMembersOfObject(type); + type->AddObjectFlag(ETSObjectFlags::FUNCTIONAL); + auto *invoke = type->GetOwnProperty(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME); + auto *invokeType = invoke->TsType()->AsETSFunctionType(); + ASSERT(invokeType->CallSignatures().size() == 1); + auto *signature = invokeType->CallSignatures()[0]; + signature->AddSignatureFlag(SignatureFlags::FUNCTIONAL_INTERFACE_SIGNATURE); +} + +static void SetupBuiltinMember(ETSChecker *checker, varbinder::Variable *var) +{ + auto *type = var->TsType(); + if (type == nullptr || !type->IsETSObjectType()) { + return; + } + auto *objType = type->AsETSObjectType(); + auto *declNode = var->Declaration()->Node(); + if (declNode->IsClassDefinition()) { + auto savedContext = SavedCheckerContext(checker, checker::CheckerStatus::IN_CLASS, objType); + checker::ScopeContext scopeCtx(checker, declNode->Scope()); + checker->ResolveDeclaredMembersOfObject(objType); + } else if (declNode->IsTSInterfaceDeclaration()) { + auto savedContext = SavedCheckerContext(checker, checker::CheckerStatus::IN_INTERFACE, objType); + checker::ScopeContext scopeCtx(checker, declNode->Scope()); + checker->ResolveDeclaredMembersOfObject(objType); + } +} + +// NOLINTNEXTLINE(modernize-avoid-c-arrays) +static constexpr std::string_view BUILTINS_TO_INIT[] = { + compiler::Signatures::BUILTIN_BOOLEAN_CLASS, compiler::Signatures::BUILTIN_BYTE_CLASS, + compiler::Signatures::BUILTIN_CHAR_CLASS, compiler::Signatures::BUILTIN_SHORT_CLASS, + compiler::Signatures::BUILTIN_INT_CLASS, compiler::Signatures::BUILTIN_LONG_CLASS, + compiler::Signatures::BUILTIN_FLOAT_CLASS, compiler::Signatures::BUILTIN_DOUBLE_CLASS, + compiler::Signatures::BUILTIN_FUNCTION0_CLASS, compiler::Signatures::BUILTIN_FUNCTION1_CLASS, + compiler::Signatures::BUILTIN_FUNCTION2_CLASS, compiler::Signatures::BUILTIN_FUNCTION3_CLASS, + compiler::Signatures::BUILTIN_FUNCTION4_CLASS, compiler::Signatures::BUILTIN_FUNCTION5_CLASS, + compiler::Signatures::BUILTIN_FUNCTION6_CLASS, compiler::Signatures::BUILTIN_FUNCTION7_CLASS, + compiler::Signatures::BUILTIN_FUNCTION8_CLASS, compiler::Signatures::BUILTIN_FUNCTION9_CLASS, + compiler::Signatures::BUILTIN_FUNCTION10_CLASS, compiler::Signatures::BUILTIN_FUNCTION11_CLASS, + compiler::Signatures::BUILTIN_FUNCTION12_CLASS, compiler::Signatures::BUILTIN_FUNCTION13_CLASS, + compiler::Signatures::BUILTIN_FUNCTION14_CLASS, compiler::Signatures::BUILTIN_FUNCTION15_CLASS, + compiler::Signatures::BUILTIN_FUNCTION16_CLASS, compiler::Signatures::BUILTIN_FUNCTIONN_CLASS, +}; + void ETSChecker::InitializeBuiltins(varbinder::ETSBinder *varbinder) { if (HasStatus(CheckerStatus::BUILTINS_INITIALIZED)) { @@ -37,17 +104,23 @@ void ETSChecker::InitializeBuiltins(varbinder::ETSBinder *varbinder) const auto varMap = varbinder->TopScope()->Bindings(); - auto initBuiltin = [varMap](ETSChecker *checker, std::string_view signature) -> util::StringView { - const auto iterator = varMap.find(signature); - ASSERT(iterator != varMap.end()); - checker->GetGlobalTypesHolder()->InitializeBuiltin( - iterator->first, - checker->BuildClassProperties(iterator->second->Declaration()->Node()->AsClassDefinition())); - return iterator->first; - }; + auto const objectName = InitBuiltin(this, compiler::Signatures::BUILTIN_OBJECT_CLASS); + auto const voidName = InitBuiltin(this, compiler::Signatures::BUILTIN_VOID_CLASS); + + for (auto sig : BUILTINS_TO_INIT) { + InitBuiltin(this, sig); + } - auto const objectName = initBuiltin(this, compiler::Signatures::BUILTIN_OBJECT_CLASS); - auto const voidName = initBuiltin(this, compiler::Signatures::BUILTIN_VOID_CLASS); + for (size_t id = static_cast(GlobalTypeId::ETS_FUNCTION0_CLASS), nargs = 0; + id <= static_cast(GlobalTypeId::ETS_FUNCTIONN_CLASS); id++, nargs++) { + auto *type = GetGlobalTypesHolder()->GlobalFunctionBuiltinType(nargs)->AsETSObjectType(); + SetupFunctionalInterface(this, type); + } + + for (const auto &[name, var] : varMap) { + (void)name; + SetupBuiltinMember(this, var); + } for (const auto &[name, var] : varMap) { if (name == objectName || name == voidName) { @@ -55,7 +128,11 @@ void ETSChecker::InitializeBuiltins(varbinder::ETSBinder *varbinder) } if (var->HasFlag(varbinder::VariableFlags::BUILTIN_TYPE)) { - InitializeBuiltin(var, name); + if (var->TsType() == nullptr) { + InitializeBuiltin(var, name); + } else { + GetGlobalTypesHolder()->InitializeBuiltin(name, var->TsType()); + } } } @@ -160,9 +237,10 @@ Type *ETSChecker::CheckTypeCached(ir::Expression *expr) return expr->TsType(); } -ETSObjectType *ETSChecker::AsETSObjectType(Type *(GlobalTypesHolder::*typeFunctor)()) const +template +ETSObjectType *ETSChecker::AsETSObjectType(Type *(GlobalTypesHolder::*typeFunctor)(Args...), Args... args) const { - auto *ret = (GetGlobalTypesHolder()->*typeFunctor)(); + auto *ret = (GetGlobalTypesHolder()->*typeFunctor)(args...); return ret != nullptr ? ret->AsETSObjectType() : nullptr; } @@ -241,9 +319,10 @@ ETSObjectType *ETSChecker::GlobalETSObjectType() const return AsETSObjectType(&GlobalTypesHolder::GlobalETSObjectType); } -ETSObjectType *ETSChecker::GlobalETSNullishObjectType() const +ETSUnionType *ETSChecker::GlobalETSNullishObjectType() const { - return AsETSObjectType(&GlobalTypesHolder::GlobalETSNullishObjectType); + auto *ret = (GetGlobalTypesHolder()->*&GlobalTypesHolder::GlobalETSNullishObjectType)(); + return ret != nullptr ? ret->AsETSUnionType() : nullptr; } ETSObjectType *ETSChecker::GlobalBuiltinETSStringType() const @@ -296,6 +375,16 @@ ETSObjectType *ETSChecker::GlobalBuiltinVoidType() const return AsETSObjectType(&GlobalTypesHolder::GlobalBuiltinVoidType); } +ETSObjectType *ETSChecker::GlobalBuiltinFunctionType(size_t nargs) const +{ + return AsETSObjectType(&GlobalTypesHolder::GlobalFunctionBuiltinType, nargs); +} + +size_t ETSChecker::GlobalBuiltinFunctionTypeVariadicThreshold() const +{ + return GetGlobalTypesHolder()->VariadicFunctionTypeThreshold(); +} + ETSObjectType *ETSChecker::GlobalBuiltinDynamicType(Language lang) const { if (lang.GetId() == Language::Id::JS) { diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index e909286f9379778b42a2def9136e029356ee7fb0..a73353b79c9f52daf2070cd353763037263ff67d 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -17,7 +17,6 @@ #define ES2PANDA_CHECKER_ETS_CHECKER_H #include "checker/checkerContext.h" -#include "varbinder/enumMemberResult.h" #include "varbinder/scope.h" #include "checker/checker.h" #include "checker/ets/primitiveWrappers.h" @@ -29,18 +28,8 @@ #include "ir/ts/tsTypeParameter.h" #include "ir/ts/tsTypeParameterInstantiation.h" #include "lexer/token/tokenType.h" -#include "util/enumbitops.h" #include "util/ustring.h" -#include "utils/bit_utils.h" #include "checker/resolveResult.h" -#include "macros.h" - -#include -#include -#include -#include -#include -#include namespace panda::es2panda::varbinder { class VarBinder; @@ -63,6 +52,8 @@ using ArrayMap = ArenaUnorderedMap; using GlobalArraySignatureMap = ArenaUnorderedMap; using DynamicCallIntrinsicsMap = ArenaUnorderedMap>; using DynamicLambdaObjectSignatureMap = ArenaUnorderedMap; +using FunctionalInterfaceMap = ArenaUnorderedMap; +using TypeMapping = ArenaUnorderedMap; class ETSChecker final : public Checker { public: @@ -75,7 +66,9 @@ public: cachedComputedAbstracts_(Allocator()->Adapter()), dynamicCallIntrinsics_(Allocator()->Adapter()), dynamicNewIntrinsics_(Allocator()->Adapter()), - dynamicLambdaSignatureCache_(Allocator()->Adapter()) + dynamicLambdaSignatureCache_(Allocator()->Adapter()), + functionalInterfaceCache_(Allocator()->Adapter()), + apparentTypes_(Allocator()->Adapter()) { } @@ -105,7 +98,7 @@ public: Type *GlobalWildcardType() const; ETSObjectType *GlobalETSObjectType() const; - ETSObjectType *GlobalETSNullishObjectType() const; + ETSUnionType *GlobalETSNullishObjectType() const; ETSObjectType *GlobalBuiltinETSStringType() const; ETSObjectType *GlobalBuiltinETSBigIntType() const; ETSObjectType *GlobalBuiltinTypeType() const; @@ -118,6 +111,9 @@ public: ETSObjectType *GlobalBuiltinBoxType(const Type *contents) const; ETSObjectType *GlobalBuiltinVoidType() const; + ETSObjectType *GlobalBuiltinFunctionType(size_t nargs) const; + size_t GlobalBuiltinFunctionTypeVariadicThreshold() const; + ETSObjectType *GlobalBuiltinDynamicType(Language lang) const; const checker::WrapperDesc &PrimitiveWrapper() const; @@ -140,8 +136,10 @@ public: } // Object + ETSObjectType *BuildBasicClassProperties(ir::ClassDefinition *classDef); ETSObjectType *BuildClassProperties(ir::ClassDefinition *classDef); ETSObjectType *BuildAnonymousClassProperties(ir::ClassDefinition *classDef, ETSObjectType *superType); + ETSObjectType *BuildBasicInterfaceProperties(ir::TSInterfaceDeclaration *interfaceDecl); ETSObjectType *BuildInterfaceProperties(ir::TSInterfaceDeclaration *interfaceDecl); ETSObjectType *GetSuperType(ETSObjectType *type); ArenaVector GetInterfaces(ETSObjectType *type); @@ -180,13 +178,13 @@ public: void TransformProperties(ETSObjectType *classType); void CheckGetterSetterProperties(ETSObjectType *classType); void AddElementsToModuleObject(ETSObjectType *moduleObj, const util::StringView &str); - Type *FindLeastUpperBound(Type *source, Type *target); - static Type *GetApparentType(Type *type); - static Type const *GetApparentType(Type const *type); - Type *MaybePromotedBuiltinType(Type *type) const; - Type *GetCommonClass(Type *source, Type *target); + void ComputeApparentType(Type *type) + { + [[maybe_unused]] auto x = GetApparentType(type); + } + [[nodiscard]] Type *GetApparentType(Type *type); + [[nodiscard]] Type const *GetApparentType(Type const *type) const; ETSObjectType *GetClosestCommonAncestor(ETSObjectType *source, ETSObjectType *target); - ETSObjectType *GetTypeargumentedLUB(ETSObjectType *source, ETSObjectType *target); bool HasETSFunctionType(ir::TypeNode *typeAnnotation); // Type creation @@ -201,14 +199,17 @@ public: ETSBigIntType *CreateETSBigIntLiteralType(util::StringView value); ETSStringType *CreateETSStringLiteralType(util::StringView value); ETSArrayType *CreateETSArrayType(Type *elementType); - Type *CreateETSUnionType(ArenaVector &&constituentTypes); - template - Type *CreateETSUnionType(Types &&...types) + Type *CreateETSUnionType(Span constituentTypes); + template + Type *CreateETSUnionType(Type *const (&arr)[N]) // NOLINT(modernize-avoid-c-arrays) + { + return CreateETSUnionType(Span(arr)); + } + Type *CreateETSUnionType(ArenaVector &&constituentTypes) { - ArenaVector constituentTypes(Allocator()->Adapter()); - (constituentTypes.push_back(types), ...); - return CreateETSUnionType(std::move(constituentTypes)); + return CreateETSUnionType(Span(constituentTypes)); } + Type *CreateNullishType(Type *type, bool isNull, bool isUndefined); ETSFunctionType *CreateETSFunctionType(Signature *signature); ETSFunctionType *CreateETSFunctionType(Signature *signature, util::StringView name); ETSFunctionType *CreateETSFunctionType(ir::ScriptFunction *func, Signature *signature, util::StringView name); @@ -296,17 +297,13 @@ public: return Allocator()->New(*src); } static void EmplaceSubstituted(Substitution *substitution, ETSTypeParameter *tparam, Type *typeArg); - ArenaUnorderedSet *NewInstantiatedTypeParamsSet() - { - return Allocator()->New>(Allocator()->Adapter()); - } ArenaVector CreateTypeForTypeParameters(ir::TSTypeParameterDeclaration const *typeParams); [[nodiscard]] bool EnhanceSubstitutionForType(const ArenaVector &typeParams, Type *paramType, - Type *argumentType, Substitution *substitution, - ArenaUnorderedSet *instantiatedTypeParams); + Type *argumentType, Substitution *substitution); [[nodiscard]] bool EnhanceSubstitutionForObject(const ArenaVector &typeParams, ETSObjectType *paramType, - Type *argumentType, Substitution *substitution, - ArenaUnorderedSet *instantiatedTypeParams); + Type *argumentType, Substitution *substitution); + [[nodiscard]] bool EnhanceSubstitutionForUnion(const ArenaVector &typeParams, ETSUnionType *paramUn, + Type *argumentType, Substitution *substitution); Signature *ValidateParameterlessConstructor(Signature *signature, const lexer::SourcePosition &pos, TypeRelationFlag flags); Signature *CollectParameterlessConstructor(ArenaVector &signatures, const lexer::SourcePosition &pos, @@ -395,27 +392,28 @@ public: ArenaVector &properties); std::tuple CreateLambdaCtorImplicitParam( ArenaVector ¶ms, const lexer::SourceRange &pos, bool isStaticReference); - ir::MethodDefinition *CreateLambdaInvokeProto(); + ir::MethodDefinition *CreateLambdaInvokeProto(util::StringView invokeName); void CreateLambdaFuncDecl(ir::MethodDefinition *func, varbinder::LocalScope *scope); - void ResolveProxyMethod(ir::MethodDefinition *proxyMethod, ir::ArrowFunctionExpression *lambda); + void ResolveProxyMethod(ir::ClassDefinition *classDefinition, ir::MethodDefinition *proxyMethod, + ir::ArrowFunctionExpression *lambda); void ResolveLambdaObject(ir::ClassDefinition *lambdaObject, Signature *signature, ETSObjectType *functionalInterface, ir::AstNode *refNode); void ResolveLambdaObject(ir::ClassDefinition *lambdaObject, ETSObjectType *functionalInterface, ir::ArrowFunctionExpression *lambda, ir::MethodDefinition *proxyMethod, bool saveThis); void ResolveLambdaObjectCtor(ir::ClassDefinition *lambdaObject, bool isStaticReference); void ResolveLambdaObjectCtor(ir::ClassDefinition *lambdaObject); - void ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, Signature *signatureRef); + void ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, Signature *signatureRef, bool ifaceOverride); void ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, ir::ArrowFunctionExpression *lambda, - ir::MethodDefinition *proxyMethod, bool isStatic); - ir::Statement *ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaObject, Signature *signatureRef); + ir::MethodDefinition *proxyMethod, bool isStatic, bool ifaceOverride); + ir::Statement *ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaObject, Signature *signatureRef, + bool ifaceOverride); ir::Statement *ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaObject, - ir::MethodDefinition *proxyMethod, bool isStatic); - void CreateFunctionalInterfaceForFunctionType(ir::ETSFunctionType *funcType); - ir::MethodDefinition *CreateInvokeFunction(ir::ETSFunctionType *funcType); + ir::ArrowFunctionExpression *lambda, + ir::MethodDefinition *proxyMethod, bool isStatic, + bool ifaceOverride); void CheckCapturedVariables(); void CheckCapturedVariableInSubnodes(ir::AstNode *node, varbinder::Variable *var); void CheckCapturedVariable(ir::AstNode *node, varbinder::Variable *var); - void BuildFunctionalInterfaceName(ir::ETSFunctionType *funcType); void CreateAsyncProxyMethods(ir::ClassDefinition *classDef); ir::MethodDefinition *CreateAsyncImplMethod(ir::MethodDefinition *asyncMethod, ir::ClassDefinition *classDef); ir::MethodDefinition *CreateAsyncProxy(ir::MethodDefinition *asyncMethod, ir::ClassDefinition *classDef, @@ -466,15 +464,8 @@ public: checker::Type *CheckVariableDeclaration(ir::Identifier *ident, ir::TypeNode *typeAnnotation, ir::Expression *init, ir::ModifierFlags flags); void CheckTruthinessOfType(ir::Expression *expr); - Type *CreateNullishType(Type *otype, checker::TypeFlag nullishFlags, ArenaAllocator *allocator, - TypeRelation *relation, GlobalTypesHolder *globalTypes); - void CheckNonNullishType(Type *type, lexer::SourcePosition lineInfo); - Type *CreateOptionalResultType(Type *type); - Type *GetNonNullishType(Type *type) const; - const Type *GetNonNullishType(const Type *type) const; - bool MayHaveNullValue(const Type *type) const; - bool MayHaveUndefinedValue(const Type *type) const; - bool MayHaveNulllikeValue(const Type *type) const; + void CheckNonNullish(ir::Expression const *expr); + Type *GetNonNullishType(Type *type); void ConcatConstantString(util::UString &target, Type *type); Type *HandleStringConcatenation(Type *leftType, Type *rightType); Type *ResolveIdentifier(ir::Identifier *ident); @@ -486,7 +477,10 @@ public: bool IsFunctionContainsSignature(ETSFunctionType *funcType, Signature *signature); void CheckFunctionContainsClashingSignature(const ETSFunctionType *funcType, Signature *signature); bool IsTypeBuiltinType(const Type *type) const; - static bool IsReferenceType(const Type *type); + static bool IsReferenceType(const Type *type) + { + return type->IsETSReferenceType(); + } const ir::AstNode *FindJumpTarget(ir::AstNodeType nodeType, const ir::AstNode *node, const ir::Identifier *target); void ValidatePropertyAccess(varbinder::Variable *var, ETSObjectType *obj, const lexer::SourcePosition &pos); varbinder::VariableFlags GetAccessFlagFromNode(const ir::AstNode *node); @@ -502,6 +496,10 @@ public: { return MaybeBoxedType(var, Allocator()); } + Type *MaybeBoxExpression(ir::Expression *expr); + Type *MaybePromotedBuiltinType(Type *type) const; + Type const *MaybePromotedBuiltinType(Type const *type) const; + Type *MaybePrimitiveBuiltinType(Type *type) const; void CheckForSameSwitchCases(ArenaVector *cases); std::string GetStringFromIdentifierValue(checker::Type *caseType) const; bool CompareIdentifiersValuesAreDifferent(ir::Expression *compareValue, const std::string &caseValue); @@ -537,9 +535,9 @@ public: ETSObjectType *GetRelevantArgumentedTypeFromChild(ETSObjectType *child, ETSObjectType *target); util::StringView GetHashFromTypeArguments(const ArenaVector &typeArgTypes); util::StringView GetHashFromSubstitution(const Substitution *substitution); - ETSObjectType *GetOriginalBaseType(Type *object); - Type *GetTypeFromTypeAnnotation(ir::TypeNode *typeAnnotation); - void AddUndefinedParamsForDefaultParams(const Signature *signature, + util::StringView GetHashFromFunctionType(ir::ETSFunctionType *type); + static ETSObjectType *GetOriginalBaseType(Type *object); + void AddUndefinedParamsForDefaultParams(const Signature *signature, ir::AstNode *parent, ArenaVector &arguments, ETSChecker *checker); void SetArrayPreferredTypeForNestedMemberExpressions(ir::MemberExpression *expr, Type *annotationType); @@ -549,9 +547,8 @@ public: Type *SelectGlobalIntegerTypeForNumeric(Type *type); const Type *TryGettingFunctionTypeFromInvokeFunction(const Type *type) const; - void GenerateGetterSetterBody(ETSChecker *checker, ArenaVector &stmts, - ArenaVector ¶ms, ir::ClassProperty *field, - varbinder::FunctionParamScope *paramScope, bool isSetter); + void GenerateGetterSetterBody(ArenaVector &stmts, ArenaVector ¶ms, + ir::ClassProperty *field, varbinder::FunctionParamScope *paramScope, bool isSetter); static ir::MethodDefinition *GenerateDefaultGetterSetter(ir::ClassProperty *field, varbinder::ClassScope *scope, bool isSetter, ETSChecker *checker); @@ -576,6 +573,8 @@ public: ETSEnumInterface *enumType); [[nodiscard]] ETSEnumType::Method CreateEnumValuesMethod(ir::Identifier *itemsArrayIdent, ETSEnumInterface *enumType); + [[nodiscard]] ir::StringLiteral *CreateEnumStringLiteral(ETSEnumInterface *const enumType, + const ir::TSEnumMember *const member); // Dynamic interop template @@ -610,6 +609,9 @@ public: return ret; } + ETSObjectType *GetCachedFunctionlInterface(ir::ETSFunctionType *type); + void CacheFunctionalInterface(ir::ETSFunctionType *type, ETSObjectType *ifaceType); + private: using ClassBuilder = std::function *)>; using ClassInitializerBuilder = std::function *, @@ -635,6 +637,11 @@ private: PropertySearchFlags GetInitialSearchFlags(const ir::MemberExpression *memberExpr); const varbinder::Variable *GetTargetRef(const ir::MemberExpression *memberExpr); void BuildClass(util::StringView name, const ClassBuilder &builder); + + template + std::pair CreateScriptFunction(varbinder::FunctionScope *scope, + ClassInitializerBuilder const &builder); + template std::conditional_t CreateClassInitializer( varbinder::ClassScope *classScope, const ClassInitializerBuilder &builder, ETSObjectType *type = nullptr); @@ -643,9 +650,8 @@ private: checker::Type *type); template - ir::MethodDefinition *CreateClassMethod(varbinder::ClassScope *classScope, std::string_view methodName, - panda::es2panda::ir::ModifierFlags modifierFlags, - const MethodBuilder &builder); + ir::MethodDefinition *CreateClassMethod(varbinder::ClassScope *classScope, std::string_view name, + ir::ModifierFlags modifierFlags, const MethodBuilder &builder); template ir::ScriptFunction *CreateDynamicCallIntrinsic(ir::Expression *callee, const ArenaVector &arguments, @@ -663,6 +669,8 @@ private: Signature *invokeSignature, ir::TypeNode *retTypeAnnotation); + void ClassInitializerFromImport(ir::ETSImportDeclaration *import, varbinder::FunctionScope *scope, + ArenaVector *statements); void EmitDynamicModuleClassInitCall(); DynamicCallIntrinsicsMap *DynamicCallIntrinsics(bool isConstruct) @@ -688,7 +696,8 @@ private: template typename TargetType::UType GetOperand(Type *type); - ETSObjectType *AsETSObjectType(Type *(GlobalTypesHolder::*typeFunctor)()) const; + template + ETSObjectType *AsETSObjectType(Type *(GlobalTypesHolder::*typeFunctor)(Args...), Args... args) const; Signature *GetMostSpecificSignature(ArenaVector &compatibleSignatures, ArenaVector &proxySignatures, const ArenaVector &arguments, @@ -713,6 +722,8 @@ private: DynamicCallIntrinsicsMap dynamicCallIntrinsics_; DynamicCallIntrinsicsMap dynamicNewIntrinsics_; DynamicLambdaObjectSignatureMap dynamicLambdaSignatureCache_; + FunctionalInterfaceMap functionalInterfaceCache_; + TypeMapping apparentTypes_; std::recursive_mutex mtx_; }; diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index 81909d5f754a71eb01b297dc7b5a71c6f1e03b64..39cdb19b43fe45170df5ab8d1ecb20189c7e126c 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -301,6 +301,18 @@ checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ETSTypeReferencePart *node UNREACHABLE(); } +checker::Type *TSAnalyzer::Check(ir::ETSNullType *node) const +{ + (void)node; + UNREACHABLE(); +} + +checker::Type *TSAnalyzer::Check(ir::ETSUndefinedType *node) const +{ + (void)node; + UNREACHABLE(); +} + checker::Type *TSAnalyzer::Check(ir::ETSUnionType *node) const { (void)node; diff --git a/ets2panda/checker/checker.cpp b/ets2panda/checker/checker.cpp index 4a7f630115ba2cd3ce8b1007020d972012359af1..22570cb53e01005fd25a896b72b63eb472866dc0 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->IsNullish() || IsTypeComparableTo(source, target); + return IsTypeComparableTo(source, target); } parser::Program *Checker::Program() const diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index b3df0dc49d157de997eea01066cfa934264b289c..aeecfbda5e615221594a291d02d3388cdb8cfb36 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -207,10 +207,6 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp bool isEqualOp, checker::Type *const leftType, checker::Type *const rightType, Type *unboxedL, Type *unboxedR) { - if (leftType->IsETSUnionType() || rightType->IsETSUnionType()) { - ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); - } - if (leftType->IsETSStringType() || rightType->IsETSStringType()) { if (operationType == lexer::TokenType::PUNCTUATOR_MINUS || operationType == lexer::TokenType::PUNCTUATOR_MINUS_EQUAL) { @@ -220,6 +216,10 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp return HandleStringConcatenation(leftType, rightType); } + if (leftType->IsETSUnionType() || rightType->IsETSUnionType()) { + ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); + } + auto [promotedType, bothConst] = ApplyBinaryOperatorPromotion(unboxedL, unboxedR, TypeFlag::ETS_NUMERIC, !isEqualOp); @@ -365,8 +365,7 @@ std::tuple ETSChecker::CheckBinaryOperatorStrictEqual(ir::Expres checker::Type *const rightType) { checker::Type *tsType {}; - if (!(leftType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || leftType->IsETSUnionType()) || - !(rightType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || rightType->IsETSUnionType())) { + if (!IsReferenceType(leftType) || !IsReferenceType(rightType)) { ThrowTypeError("Both operands have to be reference types", pos); } @@ -410,8 +409,7 @@ std::tuple ETSChecker::CheckBinaryOperatorEqual( if (IsReferenceType(leftType) && IsReferenceType(rightType)) { tsType = GlobalETSBooleanType(); - auto *opType = GlobalETSObjectType(); - return {tsType, opType}; + return {tsType, CreateETSUnionType({leftType, rightType})}; } if (unboxedL != nullptr && unboxedL->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && unboxedR != nullptr && @@ -471,14 +469,8 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater( FlagExpressionWithUnboxing(leftType, unboxedL, left); FlagExpressionWithUnboxing(rightType, unboxedR, right); - if (leftType->IsETSUnionType()) { - tsType = GlobalETSBooleanType(); - return {tsType, leftType->AsETSUnionType()}; - } - - if (rightType->IsETSUnionType()) { - tsType = GlobalETSBooleanType(); - return {tsType, rightType->AsETSUnionType()}; + if (leftType->IsETSUnionType() || rightType->IsETSUnionType()) { + return {GlobalETSBooleanType(), CreateETSUnionType({leftType, rightType})}; } if (promotedType == nullptr && !bothConst) { @@ -512,53 +504,19 @@ std::tuple ETSChecker::CheckBinaryOperatorInstanceOf(lexer::Sour tsType = GlobalETSBooleanType(); checker::Type *opType = rightType->IsETSDynamicType() ? GlobalBuiltinJSValueType() : GlobalETSObjectType(); + ComputeApparentType(rightType); return {tsType, opType}; } Type *ETSChecker::CheckBinaryOperatorNullishCoalescing(ir::Expression *right, lexer::SourcePosition pos, - checker::Type *leftType, checker::Type *rightType) + checker::Type *const leftType, + [[maybe_unused]] checker::Type *const rightType) { - if (!leftType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) && !leftType->IsETSTypeParameter()) { + ASSERT(rightType == right->TsType()); + if (!IsReferenceType(leftType)) { ThrowTypeError("Left-hand side expression must be a reference type.", pos); } - - checker::Type *nonNullishLeftType = leftType; - - if (leftType->IsNullish()) { - nonNullishLeftType = GetNonNullishType(leftType); - } - - // NOTE: vpukhov. check convertibility and use numeric promotion - - if (rightType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - Relation()->SetNode(right); - auto *const boxedRightType = PrimitiveTypeAsETSBuiltinType(rightType); - if (boxedRightType == nullptr) { - ThrowTypeError("Invalid right-hand side expression", pos); - } - right->AddBoxingUnboxingFlags(GetBoxingFlag(boxedRightType)); - rightType = boxedRightType; - } - - if (rightType->IsETSNullType()) { - return CreateNullishType(nonNullishLeftType, TypeFlag::NULL_TYPE, Allocator(), Relation(), - GetGlobalTypesHolder()); - } - - if (rightType->IsETSUndefinedType()) { - return CreateNullishType(nonNullishLeftType, TypeFlag::UNDEFINED, Allocator(), Relation(), - GetGlobalTypesHolder()); - } - - if (nonNullishLeftType->IsETSTypeParameter()) { - nonNullishLeftType = nonNullishLeftType->AsETSTypeParameter()->GetConstraintType(); - } - - if (rightType->IsETSTypeParameter()) { - rightType = rightType->AsETSTypeParameter()->GetConstraintType(); - } - - return FindLeastUpperBound(nonNullishLeftType, rightType); + return CreateETSUnionType({GetNonNullishType(leftType), MaybeBoxExpression(right)}); } using CheckBinaryFunction = std::function #include "checker/ETSchecker.h" #include "varbinder/scope.h" @@ -85,7 +86,6 @@ template ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *callee, const ArenaVector &arguments, Language lang) { - auto *name = AllocNode("invoke", Allocator()); auto *paramScope = Allocator()->New(Allocator(), nullptr); auto *scope = Allocator()->New(Allocator(), paramScope); @@ -119,9 +119,9 @@ ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *calle info->params.push_back(param->Ident()->Variable()->AsLocalVariable()); } - auto *func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), nullptr, - ir::ScriptFunctionFlags::METHOD, ir::ModifierFlags::NONE, false, - Language(Language::Id::ETS)); + auto *func = AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), nullptr, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, ir::ModifierFlags::NONE}); func->SetScope(scope); scope->BindNode(func); @@ -129,6 +129,7 @@ ir::ScriptFunction *ETSChecker::CreateDynamicCallIntrinsic(ir::Expression *calle scope->BindParamScope(paramScope); paramScope->BindFunctionScope(scope); + auto *name = AllocNode("invoke", Allocator()); func->SetIdent(name); auto *signature = CreateSignature(info, dynamicType, func); @@ -197,50 +198,60 @@ template Signature *ETSChecker::ResolveDynamicCallExpression &arguments, Language lang, bool is_construct); template -std::conditional_t ETSChecker::CreateClassInitializer( - varbinder::ClassScope *classScope, const ClassInitializerBuilder &builder, ETSObjectType *type) +std::pair ETSChecker::CreateScriptFunction( + varbinder::FunctionScope *scope, ClassInitializerBuilder const &builder) { - varbinder::LocalScope *methodScope = nullptr; - if constexpr (IS_STATIC) { - methodScope = classScope->StaticMethodScope(); - } else { - methodScope = classScope->InstanceMethodScope(); - } - auto classCtx = varbinder::LexicalScope::Enter(VarBinder(), methodScope); - - ArenaVector params(Allocator()->Adapter()); - - auto *paramScope = Allocator()->New(Allocator(), classScope); - auto *scope = Allocator()->New(Allocator(), paramScope); - ArenaVector statements(Allocator()->Adapter()); + ArenaVector params(Allocator()->Adapter()); - ir::ScriptFunction *func = nullptr; - ir::Identifier *id = nullptr; + ir::ScriptFunction *func; + ir::Identifier *id; if constexpr (IS_STATIC) { builder(scope, &statements, nullptr); auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); id = AllocNode(compiler::Signatures::CCTOR, Allocator()); - func = - AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::EXPRESSION, - ir::ModifierFlags::STATIC, false, Language(Language::Id::ETS)); - func->SetScope(scope); + func = AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::STATIC_BLOCK | + ir::ScriptFunctionFlags::EXPRESSION, + ir::ModifierFlags::STATIC}); } else { builder(scope, &statements, ¶ms); auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); id = AllocNode(compiler::Signatures::CTOR, Allocator()); - func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::CONSTRUCTOR | ir::ScriptFunctionFlags::EXPRESSION, - ir::ModifierFlags::PUBLIC, false, Language(Language::Id::ETS)); - func->SetScope(scope); + func = AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData { + ir::ScriptFunctionFlags::CONSTRUCTOR | ir::ScriptFunctionFlags::EXPRESSION, ir::ModifierFlags::PUBLIC}); } + func->SetScope(scope); scope->BindNode(func); func->SetIdent(id); + + return std::make_pair(func, id); +} + +template +std::conditional_t ETSChecker::CreateClassInitializer( + varbinder::ClassScope *classScope, const ClassInitializerBuilder &builder, ETSObjectType *type) +{ + varbinder::LocalScope *methodScope = nullptr; + if constexpr (IS_STATIC) { + methodScope = classScope->StaticMethodScope(); + } else { + methodScope = classScope->InstanceMethodScope(); + } + auto classCtx = varbinder::LexicalScope::Enter(VarBinder(), methodScope); + + auto *paramScope = Allocator()->New(Allocator(), classScope); + auto *scope = Allocator()->New(Allocator(), paramScope); + + auto [func, id] = CreateScriptFunction(scope, builder); + paramScope->BindNode(func); scope->BindParamScope(paramScope); paramScope->BindFunctionScope(scope); @@ -263,12 +274,11 @@ std::conditional_t ET } else { type->AddConstructSignature(signature); - auto *ctor = Allocator()->New(ir::MethodDefinitionKind::CONSTRUCTOR, id, funcExpr, - ir::ModifierFlags::NONE, Allocator(), false); + auto *ctor = + AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, id->Clone(Allocator(), nullptr), + funcExpr, ir::ModifierFlags::NONE, Allocator(), false); auto *funcType = CreateETSFunctionType(signature, id->Name()); ctor->SetTsType(funcType); - funcExpr->SetParent(classScope->Node()->AsClassDeclaration()->Definition()); - func->SetParent(ctor); return ctor; } } @@ -371,10 +381,10 @@ void ETSChecker::BuildDynamicCallClass(bool isConstruct) auto *funcExpr = AllocNode(func); - auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, func->Id(), funcExpr, - ir::ModifierFlags::PUBLIC | ir::ModifierFlags::NATIVE | - ir::ModifierFlags::STATIC, - Allocator(), false); + auto *method = AllocNode( + ir::MethodDefinitionKind::METHOD, func->Id()->Clone(Allocator(), nullptr), funcExpr, + ir::ModifierFlags::PUBLIC | ir::ModifierFlags::NATIVE | ir::ModifierFlags::STATIC, Allocator(), + false); VarBinder()->AsETSBinder()->BuildInternalName(func); VarBinder()->AsETSBinder()->BuildFunctionName(func); @@ -387,56 +397,69 @@ void ETSChecker::BuildDynamicCallClass(bool isConstruct) } } -ir::ClassStaticBlock *ETSChecker::CreateDynamicModuleClassInitializer( - varbinder::ClassScope *classScope, const std::vector &imports) +void ETSChecker::ClassInitializerFromImport(ir::ETSImportDeclaration *import, varbinder::FunctionScope *scope, + ArenaVector *statements) { - return CreateClassInitializer( - classScope, [this, imports](varbinder::FunctionScope *scope, ArenaVector *statements, - [[maybe_unused]] ArenaVector *params) { - for (auto *import : imports) { - auto builtin = compiler::Signatures::Dynamic::LoadModuleBuiltin(import->Language()); - auto [builtin_class_name, builtin_method_name] = util::Helpers::SplitSignature(builtin); + auto builtin = compiler::Signatures::Dynamic::LoadModuleBuiltin(import->Language()); + auto [builtin_class_name, builtin_method_name] = util::Helpers::SplitSignature(builtin); - auto *classId = AllocNode(builtin_class_name, Allocator()); - auto *methodId = AllocNode(builtin_method_name, Allocator()); - auto *callee = AllocNode(classId, methodId, - ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + auto *classId = AllocNode(builtin_class_name, Allocator()); + auto *methodId = AllocNode(builtin_method_name, Allocator()); + auto *callee = + AllocNode(classId, methodId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - ArenaVector callParams(Allocator()->Adapter()); - callParams.push_back(import->ResolvedSource()); + ArenaVector callParams(Allocator()->Adapter()); + callParams.push_back(import->ResolvedSource()); - auto *loadCall = AllocNode(callee, std::move(callParams), nullptr, false); + auto *loadCall = AllocNode(callee, std::move(callParams), nullptr, false); - auto *moduleClassId = - AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS, Allocator()); - auto *fieldId = AllocNode(import->AssemblerName(), Allocator()); - auto *property = AllocNode( - moduleClassId, fieldId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + auto *moduleClassId = AllocNode(compiler::Signatures::DYNAMIC_MODULE_CLASS, Allocator()); + auto *fieldId = AllocNode(import->AssemblerName(), Allocator()); + auto *property = AllocNode(moduleClassId, fieldId, ir::MemberExpressionKind::PROPERTY_ACCESS, + false, false); - auto *initializer = - AllocNode(property, loadCall, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *initializer = + AllocNode(property, loadCall, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - { - ScopeContext ctx(this, scope); - initializer->Check(this); - } + { + ScopeContext ctx(this, scope); + initializer->Check(this); + } + statements->push_back(AllocNode(initializer)); +} - statements->push_back(AllocNode(initializer)); +ir::ClassStaticBlock *ETSChecker::CreateDynamicModuleClassInitializer( + varbinder::ClassScope *classScope, const std::vector &imports) +{ + return CreateClassInitializer( + classScope, [this, imports](varbinder::FunctionScope *scope, ArenaVector *statements, + [[maybe_unused]] ArenaVector *params) { + for (auto *import : imports) { + ClassInitializerFromImport(import, scope, statements); } }); } template -ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *classScope, - const std::string_view methodName, - panda::es2panda::ir::ModifierFlags modifierFlags, - const MethodBuilder &builder) +static void AddMethodToClass(varbinder::ClassScope *classScope, varbinder::Variable *methodVar) +{ + auto *classType = classScope->Node()->AsClassDeclaration()->Definition()->TsType()->AsETSObjectType(); + if constexpr (IS_STATIC) { + classType->AddProperty(methodVar->AsLocalVariable()); + } else { + classType->AddProperty(methodVar->AsLocalVariable()); + } +} + +template +ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *classScope, const std::string_view name, + ir::ModifierFlags modifierFlags, const MethodBuilder &builder) { auto classCtx = varbinder::LexicalScope::Enter(VarBinder(), classScope->StaticMethodScope()); ArenaVector params(Allocator()->Adapter()); auto *paramScope = Allocator()->New(Allocator(), classScope); auto *scope = Allocator()->New(Allocator(), paramScope); - auto *id = AllocNode(methodName, Allocator()); + auto *id = AllocNode(name, Allocator()); ArenaVector statements(Allocator()->Adapter()); Type *returnType = nullptr; @@ -446,9 +469,10 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); - auto *func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::METHOD, modifierFlags, false, - Language(Language::Id::ETS)); + auto *func = AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, modifierFlags}); + func->SetScope(scope); scope->BindNode(func); func->SetIdent(id); @@ -465,8 +489,9 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class func->SetSignature(signature); auto *funcExpr = AllocNode(func); - auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, func->Id(), funcExpr, - modifierFlags, Allocator(), false); + auto *method = + AllocNode(ir::MethodDefinitionKind::METHOD, func->Id()->Clone(Allocator(), nullptr), + funcExpr, modifierFlags, Allocator(), false); VarBinder()->AsETSBinder()->BuildInternalName(func); VarBinder()->AsETSBinder()->BuildFunctionName(func); @@ -481,13 +506,9 @@ ir::MethodDefinition *ETSChecker::CreateClassMethod(varbinder::ClassScope *class method->SetTsType(funcType); var->AddFlag(varbinder::VariableFlags::PROPERTY); func->Id()->SetVariable(var); + method->Id()->SetVariable(var); - auto *classType = classScope->Node()->AsClassDeclaration()->Definition()->TsType()->AsETSObjectType(); - if constexpr (IS_STATIC) { - classType->AddProperty(var->AsLocalVariable()); - } else { - classType->AddProperty(var->AsLocalVariable()); - } + AddMethodToClass(classScope, var); return method; } @@ -524,12 +545,12 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: scope->Parent()->AsFunctionParamScope(), util::UString(std::string("p") + std::to_string(idx), Allocator()).View(), invokeParam->TsType()); params->push_back(param); - callParams.push_back(param); + callParams.push_back(param->Clone(Allocator(), nullptr)); ++idx; } auto *properyId = AllocNode("jsvalue_lambda", Allocator()); - auto *callee = AllocNode(thisParam, properyId, + auto *callee = AllocNode(thisParam->Clone(Allocator(), nullptr), properyId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); auto *callLambda = AllocNode(callee, std::move(callParams), nullptr, false); @@ -538,9 +559,10 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInvokeMethod(varbinder: callLambda->Check(this); } - auto *castToRetTypeExpr = Allocator()->New(callLambda, retTypeAnnotation, false); + auto *castToRetTypeExpr = + AllocNode(callLambda, retTypeAnnotation->Clone(Allocator(), nullptr), false); castToRetTypeExpr->SetTsType(invokeSignature->ReturnType()); - auto *retStatement = Allocator()->New(castToRetTypeExpr); + auto *retStatement = AllocNode(castToRetTypeExpr); statements->push_back(retStatement); *returnType = invokeSignature->ReturnType(); @@ -571,7 +593,9 @@ void ETSChecker::EmitDynamicModuleClassInitCall() initCall->Check(this); } - cctorBody->Statements().push_back(AllocNode(initCall)); + auto *const node = AllocNode(initCall); + node->SetParent(cctorBody); + cctorBody->Statements().push_back(node); } void ETSChecker::BuildDynamicImportClass() @@ -653,8 +677,8 @@ ir::MethodDefinition *ETSChecker::CreateLambdaObjectClassInitializer(varbinder:: auto *fieldId = AllocNode("jsvalue_lambda", Allocator()); auto *property = AllocNode(moduleClassId, fieldId, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - auto *initializer = - AllocNode(property, jsvalueParam, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *initializer = AllocNode(property, jsvalueParam->Clone(Allocator(), nullptr), + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); { ScopeContext ctx(this, scope); initializer->Check(this); diff --git a/ets2panda/checker/ets/enum.cpp b/ets2panda/checker/ets/enum.cpp index f9a116f3f27bc4e043e692519b5df6cf72ed1623..5ab505aba65a1c719b16f5828b8c4ceab722153a 100644 --- a/ets2panda/checker/ets/enum.cpp +++ b/ets2panda/checker/ets/enum.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "util/ustring.h" #include "varbinder/ETSBinder.h" #include "varbinder/variable.h" #include "checker/ETSchecker.h" @@ -65,16 +66,16 @@ void AppendParentNames(util::UString &qualifiedName, const ir::AstNode *const no } } -[[nodiscard]] ir::Identifier *MakeQualifiedIdentifier(panda::ArenaAllocator *const allocator, +[[nodiscard]] ir::Identifier *MakeQualifiedIdentifier(ETSChecker *const checker, const ir::TSEnumDeclaration *const enumDecl, const util::StringView &name) { - util::UString qualifiedName(util::StringView("#"), allocator); + util::UString qualifiedName(util::StringView("#"), checker->Allocator()); AppendParentNames(qualifiedName, enumDecl->Parent()); qualifiedName.Append(enumDecl->Key()->Name()); qualifiedName.Append('#'); qualifiedName.Append(name); - return allocator->New(qualifiedName.View(), allocator); + return checker->AllocNode(qualifiedName.View(), checker->Allocator()); } template @@ -88,13 +89,13 @@ template elements.push_back(elementMaker(member->AsTSEnumMember())); } - auto *const arrayExpr = checker->Allocator()->New(std::move(elements), checker->Allocator()); + auto *const arrayExpr = checker->AllocNode(std::move(elements), checker->Allocator()); arrayExpr->SetPreferredType(elementType); arrayExpr->SetTsType(checker->CreateETSArrayType(elementType)); - auto *const arrayIdent = MakeQualifiedIdentifier(checker->Allocator(), enumType->GetDecl(), name); + auto *const arrayIdent = MakeQualifiedIdentifier(checker, enumType->GetDecl(), name); - auto *const arrayClassProp = checker->Allocator()->New( + auto *const arrayClassProp = checker->AllocNode( arrayIdent, arrayExpr, nullptr, ir::ModifierFlags::STATIC | ir::ModifierFlags::PUBLIC | ir::ModifierFlags::CONST, checker->Allocator(), false); arrayClassProp->SetTsType(arrayExpr->TsType()); @@ -118,8 +119,8 @@ template const util::StringView &name, Type *const type) { const auto paramCtx = varbinder::LexicalScope::Enter(varbinder, scope, false); - auto *const paramIdent = checker->Allocator()->New(name, checker->Allocator()); - auto *const param = checker->Allocator()->New(paramIdent, nullptr); + auto *const paramIdent = checker->AllocNode(name, checker->Allocator()); + auto *const param = checker->AllocNode(paramIdent, nullptr); auto *const paramVar = std::get<1>(varbinder->AddParamDecl(param)); paramVar->SetTsType(type); param->Ident()->SetVariable(paramVar); @@ -128,11 +129,11 @@ template return param; } -[[nodiscard]] ir::ETSTypeReference *MakeTypeReference(panda::ArenaAllocator *allocator, const util::StringView &name) +[[nodiscard]] ir::ETSTypeReference *MakeTypeReference(ETSChecker *const checker, const util::StringView &name) { - auto *const ident = allocator->New(name, allocator); - auto *const referencePart = allocator->New(ident); - return allocator->New(referencePart); + auto *const ident = checker->AllocNode(name, checker->Allocator()); + auto *const referencePart = checker->AllocNode(ident); + return checker->AllocNode(referencePart); } [[nodiscard]] ir::ScriptFunction *MakeFunction(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, @@ -145,7 +146,7 @@ template functionScope->BindParamScope(paramScope); paramScope->BindFunctionScope(functionScope); - auto *const bodyBlock = checker->Allocator()->New(checker->Allocator(), std::move(body)); + auto *const bodyBlock = checker->AllocNode(checker->Allocator(), std::move(body)); bodyBlock->SetScope(functionScope); auto flags = ir::ModifierFlags::PUBLIC; @@ -154,9 +155,9 @@ template flags |= ir::ModifierFlags::DECLARE; } - auto *const function = checker->Allocator()->New( + auto *const function = checker->AllocNode( ir::FunctionSignature(nullptr, std::move(params), returnTypeAnnotation), bodyBlock, - ir::ScriptFunctionFlags::METHOD, flags, isDeclare, Language(Language::Id::ETS)); + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, flags, isDeclare}); function->SetScope(functionScope); varbinder->AsETSBinder()->BuildInternalName(function); @@ -170,19 +171,21 @@ template void MakeMethodDef(ETSChecker *const checker, varbinder::ETSBinder *const varbinder, ir::Identifier *const ident, ir::ScriptFunction *const function) { - auto *const functionExpr = checker->Allocator()->New(function); - function->SetParent(functionExpr); + auto *const functionExpr = checker->AllocNode(function); + auto *const identClone = ident->Clone(checker->Allocator(), nullptr); + identClone->SetTsType(ident->TsType()); - auto *const methodDef = checker->Allocator()->New( - ir::MethodDefinitionKind::METHOD, ident, functionExpr, ir::ModifierFlags::PUBLIC, checker->Allocator(), false); + auto *const methodDef = + checker->AllocNode(ir::MethodDefinitionKind::METHOD, identClone, functionExpr, + ir::ModifierFlags::PUBLIC, checker->Allocator(), false); methodDef->SetParent(varbinder->Program()->GlobalClass()); - functionExpr->SetParent(methodDef); auto *const methodVar = std::get<1>(varbinder->NewVarDecl( methodDef->Start(), checker->Allocator(), methodDef->Id()->Name(), methodDef)); methodVar->AddFlag(varbinder::VariableFlags::STATIC | varbinder::VariableFlags::SYNTHETIC | varbinder::VariableFlags::METHOD); methodDef->Function()->Id()->SetVariable(methodVar); + methodDef->Id()->SetVariable(methodVar); } [[nodiscard]] ETSFunctionType *MakeProxyFunctionType(ETSChecker *const checker, const util::StringView &name, @@ -224,7 +227,7 @@ ir::Identifier *ETSChecker::CreateEnumNamesArray(ETSEnumInterface const *const e return MakeArray(this, VarBinder()->AsETSBinder(), enumType, "NamesArray", GlobalBuiltinETSStringType(), [this](const ir::TSEnumMember *const member) { auto *const enumNameStringLiteral = - Allocator()->New(member->Key()->AsIdentifier()->Name()); + AllocNode(member->Key()->AsIdentifier()->Name()); enumNameStringLiteral->SetTsType(GlobalBuiltinETSStringType()); return enumNameStringLiteral; }); @@ -236,7 +239,7 @@ ir::Identifier *ETSChecker::CreateEnumValuesArray(ETSEnumType *const enumType) return MakeArray( this, VarBinder()->AsETSBinder(), enumType, "ValuesArray", GlobalIntType(), [this](const ir::TSEnumMember *const member) { - auto *const enumValueLiteral = Allocator()->New(lexer::Number( + auto *const enumValueLiteral = AllocNode(lexer::Number( member->AsTSEnumMember()->Init()->AsNumberLiteral()->Number().GetValue())); enumValueLiteral->SetTsType(GlobalIntType()); return enumValueLiteral; @@ -246,17 +249,19 @@ ir::Identifier *ETSChecker::CreateEnumValuesArray(ETSEnumType *const enumType) ir::Identifier *ETSChecker::CreateEnumStringValuesArray(ETSEnumInterface *const enumType) { return MakeArray(this, VarBinder()->AsETSBinder(), enumType, "StringValuesArray", GlobalETSStringLiteralType(), - [this, isStringEnum = enumType->IsETSStringEnumType()](const ir::TSEnumMember *const member) { - auto const stringValue = - isStringEnum ? member->AsTSEnumMember()->Init()->AsStringLiteral()->Str() - : util::UString(std::to_string(member->AsTSEnumMember() - ->Init() - ->AsNumberLiteral() - ->Number() - .GetValue()), - Allocator()) - .View(); - auto *const enumValueStringLiteral = Allocator()->New(stringValue); + [this, enumType](const ir::TSEnumMember *const member) { + auto *const init = member->AsTSEnumMember()->Init(); + util::StringView stringValue; + + if (enumType->IsETSStringEnumType()) { + stringValue = init->AsStringLiteral()->Str(); + } else { + auto str = + std::to_string(init->AsNumberLiteral()->Number().GetValue()); + stringValue = util::UString(str, Allocator()).View(); + } + + auto *const enumValueStringLiteral = AllocNode(stringValue); enumValueStringLiteral->SetTsType(GlobalETSStringLiteralType()); return enumValueStringLiteral; }); @@ -264,17 +269,19 @@ ir::Identifier *ETSChecker::CreateEnumStringValuesArray(ETSEnumInterface *const ir::Identifier *ETSChecker::CreateEnumItemsArray(ETSEnumInterface *const enumType) { - auto *const enumTypeIdent = Allocator()->New(enumType->GetName(), Allocator()); - enumTypeIdent->SetTsType(enumType); - return MakeArray( this, VarBinder()->AsETSBinder(), enumType, "ItemsArray", enumType, - [this, enumTypeIdent](const ir::TSEnumMember *const member) { + [this, enumType](const ir::TSEnumMember *const member) { + auto *const enumTypeIdent = AllocNode(enumType->GetName(), Allocator()); + enumTypeIdent->SetTsType(enumType); + auto *const enumMemberIdent = - Allocator()->New(member->AsTSEnumMember()->Key()->AsIdentifier()->Name(), Allocator()); - auto *const enumMemberExpr = Allocator()->New( + AllocNode(member->AsTSEnumMember()->Key()->AsIdentifier()->Name(), Allocator()); + + auto *const enumMemberExpr = AllocNode( enumTypeIdent, enumMemberIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); enumMemberExpr->SetTsType(member->AsTSEnumMember()->Key()->AsIdentifier()->Variable()->TsType()); + return enumMemberExpr; }); } @@ -289,37 +296,41 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", GlobalIntType()); auto *const inArraySizeExpr = [this, namesArrayIdent, inputOrdinalIdent]() { - auto *const lengthIdent = Allocator()->New("length", Allocator()); - auto *const valuesArrayLengthExpr = Allocator()->New( + auto *const lengthIdent = AllocNode("length", Allocator()); + auto *const valuesArrayLengthExpr = AllocNode( namesArrayIdent, lengthIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - auto *const expr = Allocator()->New(inputOrdinalIdent, valuesArrayLengthExpr, - lexer::TokenType::PUNCTUATOR_LESS_THAN); + auto *const expr = AllocNode(inputOrdinalIdent, valuesArrayLengthExpr, + lexer::TokenType::PUNCTUATOR_LESS_THAN); expr->SetOperationType(GlobalIntType()); expr->SetTsType(GlobalETSBooleanType()); return expr; }(); auto *const returnEnumStmt = [this, inputOrdinalIdent, enumType]() { - inputOrdinalIdent->SetTsType(enumType); - return Allocator()->New(inputOrdinalIdent); + auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(enumType); + return AllocNode(identClone); }(); - auto *const ifOrdinalExistsStmt = Allocator()->New(inArraySizeExpr, returnEnumStmt, nullptr); + auto *const ifOrdinalExistsStmt = AllocNode(inArraySizeExpr, returnEnumStmt, nullptr); auto *const throwNoEnumStmt = [this, inputOrdinalIdent, enumType]() { - auto *const exceptionReference = MakeTypeReference(Allocator(), "Exception"); + auto *const exceptionReference = MakeTypeReference(this, "Exception"); util::UString messageString(util::StringView("No enum constant in "), Allocator()); messageString.Append(enumType->GetName()); messageString.Append(" with ordinal value "); - auto *const message = Allocator()->New(messageString.View()); + auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(GlobalIntType()); + + auto *const message = AllocNode(messageString.View()); auto *const newExprArg = - Allocator()->New(message, inputOrdinalIdent, lexer::TokenType::PUNCTUATOR_PLUS); + AllocNode(message, identClone, lexer::TokenType::PUNCTUATOR_PLUS); ArenaVector newExprArgs(Allocator()->Adapter()); newExprArgs.push_back(newExprArg); - auto *const newExpr = Allocator()->New( + auto *const newExpr = AllocNode( exceptionReference, std::move(newExprArgs), GlobalBuiltinExceptionType()->GetDeclNode()->AsClassDefinition()); @@ -327,24 +338,26 @@ ETSEnumType::Method ETSChecker::CreateEnumFromIntMethod(ir::Identifier *const na ResolveConstructExpression(GlobalBuiltinExceptionType(), newExpr->GetArguments(), newExpr->Start())); newExpr->SetTsType(GlobalBuiltinExceptionType()); - return Allocator()->New(newExpr); + return AllocNode(newExpr); }(); + auto *const identClone = inputOrdinalIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(inputOrdinalIdent->TsType()); ArenaVector params(Allocator()->Adapter()); - params.push_back(inputOrdinalIdent); + params.push_back(identClone); ArenaVector body(Allocator()->Adapter()); body.push_back(ifOrdinalExistsStmt); body.push_back(throwNoEnumStmt); body.push_back(returnEnumStmt); - auto *const enumTypeAnnotation = MakeTypeReference(Allocator(), enumType->GetName()); + auto *const enumTypeAnnotation = MakeTypeReference(this, enumType->GetName()); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), enumTypeAnnotation, enumType->GetDecl()->IsDeclare()); function->AddFlag(ir::ScriptFunctionFlags::THROWS); - auto *const ident = MakeQualifiedIdentifier(Allocator(), enumType->GetDecl(), ETSEnumType::FROM_INT_METHOD_NAME); + auto *const ident = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::FROM_INT_METHOD_NAME); function->SetIdent(ident); function->Scope()->BindInternalName(ident->Name()); @@ -362,25 +375,26 @@ ETSEnumType::Method ETSChecker::CreateEnumToStringMethod(ir::Identifier *const s auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", enumType); auto *const returnStmt = [this, inputEnumIdent, stringValuesArrayIdent]() { - auto *const arrayAccessExpr = Allocator()->New( + auto *const arrayAccessExpr = AllocNode( stringValuesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); arrayAccessExpr->SetTsType(GlobalETSStringLiteralType()); - return Allocator()->New(arrayAccessExpr); + return AllocNode(arrayAccessExpr); }(); ArenaVector body(Allocator()->Adapter()); body.push_back(returnStmt); + auto *const identClone = inputEnumIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(enumType); ArenaVector params(Allocator()->Adapter()); - params.push_back(inputEnumIdent); + params.push_back(identClone); - auto *const stringTypeAnnotation = MakeTypeReference(Allocator(), GlobalBuiltinETSStringType()->Name()); + auto *const stringTypeAnnotation = MakeTypeReference(this, GlobalBuiltinETSStringType()->Name()); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), stringTypeAnnotation, enumType->GetDecl()->IsDeclare()); - auto *const functionIdent = - MakeQualifiedIdentifier(Allocator(), enumType->GetDecl(), ETSEnumType::TO_STRING_METHOD_NAME); + auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::TO_STRING_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); @@ -400,25 +414,26 @@ ETSEnumType::Method ETSChecker::CreateEnumGetValueMethod(ir::Identifier *const v auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "e", enumType); auto *const returnStmt = [this, inputEnumIdent, valuesArrayIdent]() { - auto *const arrayAccessExpr = Allocator()->New( + auto *const arrayAccessExpr = AllocNode( valuesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); arrayAccessExpr->SetTsType(GlobalIntType()); - return Allocator()->New(arrayAccessExpr); + return AllocNode(arrayAccessExpr); }(); ArenaVector body(Allocator()->Adapter()); body.push_back(returnStmt); + auto *const identClone = inputEnumIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(enumType); ArenaVector params(Allocator()->Adapter()); - params.push_back(inputEnumIdent); + params.push_back(identClone); - auto *const intTypeAnnotation = Allocator()->New(ir::PrimitiveType::INT); + auto *const intTypeAnnotation = AllocNode(ir::PrimitiveType::INT); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), intTypeAnnotation, enumType->GetDecl()->IsDeclare()); - auto *const functionIdent = - MakeQualifiedIdentifier(Allocator(), enumType->GetDecl(), ETSEnumType::GET_VALUE_METHOD_NAME); + auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::GET_VALUE_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); @@ -437,26 +452,27 @@ ETSEnumType::Method ETSChecker::CreateEnumGetNameMethod(ir::Identifier *const na auto *const inputEnumIdent = MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "ordinal", enumType); auto *const returnStmt = [this, inputEnumIdent, namesArrayIdent]() { - auto *const arrayAccessExpr = Allocator()->New( + auto *const arrayAccessExpr = AllocNode( namesArrayIdent, inputEnumIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); arrayAccessExpr->SetTsType(GlobalBuiltinETSStringType()); - return Allocator()->New(arrayAccessExpr); + return AllocNode(arrayAccessExpr); }(); ArenaVector body(Allocator()->Adapter()); body.push_back(returnStmt); + auto *const identClone = inputEnumIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(enumType); ArenaVector params(Allocator()->Adapter()); - params.push_back(inputEnumIdent); + params.push_back(identClone); - auto *const stringTypeAnnotation = MakeTypeReference(Allocator(), GlobalBuiltinETSStringType()->Name()); + auto *const stringTypeAnnotation = MakeTypeReference(this, GlobalBuiltinETSStringType()->Name()); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), stringTypeAnnotation, enumType->GetDecl()->IsDeclare()); - auto *const functionIdent = - MakeQualifiedIdentifier(Allocator(), enumType->GetDecl(), ETSEnumType::GET_NAME_METHOD_NAME); + auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::GET_NAME_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); @@ -472,13 +488,10 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na auto *const paramScope = VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - auto *const inputNameIdent = - MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "name", GlobalBuiltinETSStringType()); - varbinder::LexicalScope loopDeclScope(VarBinder()); auto *const forLoopIIdent = [this]() { - auto *const ident = Allocator()->New("i", Allocator()); + auto *const ident = AllocNode("i", Allocator()); ident->SetTsType(GlobalIntType()); auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); ident->SetVariable(var); @@ -490,24 +503,23 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na }(); auto *const forLoopInitVarDecl = [this, forLoopIIdent]() { - auto *const init = Allocator()->New("0"); + auto *const init = AllocNode("0"); init->SetTsType(GlobalIntType()); - auto *const decl = - Allocator()->New(ir::VariableDeclaratorFlag::LET, forLoopIIdent, init); + auto *const decl = AllocNode(ir::VariableDeclaratorFlag::LET, forLoopIIdent, init); decl->SetTsType(GlobalIntType()); ArenaVector decls(Allocator()->Adapter()); decls.push_back(decl); - return Allocator()->New(ir::VariableDeclaration::VariableDeclarationKind::LET, - Allocator(), std::move(decls), false); + return AllocNode(ir::VariableDeclaration::VariableDeclarationKind::LET, Allocator(), + std::move(decls), false); }(); auto *const forLoopTest = [this, namesArrayIdent, forLoopIIdent]() { - auto *const lengthIdent = Allocator()->New("length", Allocator()); - auto *const arrayLengthExpr = Allocator()->New( + auto *const lengthIdent = AllocNode("length", Allocator()); + auto *const arrayLengthExpr = AllocNode( namesArrayIdent, lengthIdent, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); arrayLengthExpr->SetTsType(GlobalIntType()); - auto *const binaryExpr = Allocator()->New(forLoopIIdent, arrayLengthExpr, - lexer::TokenType::PUNCTUATOR_LESS_THAN); + auto *const binaryExpr = + AllocNode(forLoopIIdent, arrayLengthExpr, lexer::TokenType::PUNCTUATOR_LESS_THAN); binaryExpr->SetOperationType(GlobalIntType()); binaryExpr->SetTsType(GlobalETSBooleanType()); return binaryExpr; @@ -515,30 +527,34 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na auto *const forLoopUpdate = [this, forLoopIIdent]() { auto *const incrementExpr = - Allocator()->New(forLoopIIdent, lexer::TokenType::PUNCTUATOR_PLUS_PLUS, true); + AllocNode(forLoopIIdent, lexer::TokenType::PUNCTUATOR_PLUS_PLUS, true); incrementExpr->SetTsType(GlobalIntType()); return incrementExpr; }(); + auto *const inputNameIdent = + MakeFunctionParam(this, VarBinder()->AsETSBinder(), paramScope, "name", GlobalBuiltinETSStringType()); + auto *const ifStmt = [this, namesArrayIdent, forLoopIIdent, inputNameIdent]() { - auto *const namesArrayElementExpr = Allocator()->New( - namesArrayIdent, forLoopIIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); + auto *const identClone = namesArrayIdent->Clone(this->Allocator(), nullptr); + identClone->SetTsType(namesArrayIdent->TsType()); + auto *const namesArrayElementExpr = AllocNode( + identClone, forLoopIIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, true, false); namesArrayElementExpr->SetTsType(GlobalBuiltinETSStringType()); - auto *const namesEqualExpr = Allocator()->New(inputNameIdent, namesArrayElementExpr, - lexer::TokenType::PUNCTUATOR_EQUAL); + auto *const namesEqualExpr = + AllocNode(inputNameIdent, namesArrayElementExpr, lexer::TokenType::PUNCTUATOR_EQUAL); namesEqualExpr->SetOperationType(GlobalBuiltinETSStringType()); namesEqualExpr->SetTsType(GlobalETSBooleanType()); - auto *const returnStmt = Allocator()->New(forLoopIIdent); - return Allocator()->New(namesEqualExpr, returnStmt, nullptr); + auto *const returnStmt = AllocNode(forLoopIIdent); + return AllocNode(namesEqualExpr, returnStmt, nullptr); }(); varbinder::LexicalScope loopScope(VarBinder()); loopScope.GetScope()->BindDecls(loopDeclScope.GetScope()); - auto *const forLoop = - Allocator()->New(forLoopInitVarDecl, forLoopTest, forLoopUpdate, ifStmt); + auto *const forLoop = AllocNode(forLoopInitVarDecl, forLoopTest, forLoopUpdate, ifStmt); loopScope.GetScope()->BindNode(forLoop); forLoop->SetScope(loopScope.GetScope()); loopScope.GetScope()->DeclScope()->BindNode(forLoop); @@ -548,40 +564,43 @@ ETSEnumType::Method ETSChecker::CreateEnumValueOfMethod(ir::Identifier *const na messageString.Append(enumType->GetName()); messageString.Append('.'); - auto *const message = Allocator()->New(messageString.View()); + auto *const identClone = inputNameIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(inputNameIdent->TsType()); + auto *const message = AllocNode(messageString.View()); auto *const newExprArg = - Allocator()->New(message, inputNameIdent, lexer::TokenType::PUNCTUATOR_PLUS); + AllocNode(message, identClone, lexer::TokenType::PUNCTUATOR_PLUS); ArenaVector newExprArgs(Allocator()->Adapter()); newExprArgs.push_back(newExprArg); - auto *const exceptionReference = MakeTypeReference(Allocator(), "Exception"); + auto *const exceptionReference = MakeTypeReference(this, "Exception"); - auto *const newExpr = Allocator()->New( + auto *const newExpr = AllocNode( exceptionReference, std::move(newExprArgs), GlobalBuiltinExceptionType()->GetDeclNode()->AsClassDefinition()); newExpr->SetSignature( ResolveConstructExpression(GlobalBuiltinExceptionType(), newExpr->GetArguments(), newExpr->Start())); newExpr->SetTsType(GlobalBuiltinExceptionType()); - return Allocator()->New(newExpr); + return AllocNode(newExpr); }(); ArenaVector body(Allocator()->Adapter()); body.push_back(forLoop); body.push_back(throwStmt); + auto *const identClone = inputNameIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(inputNameIdent->TsType()); ArenaVector params(Allocator()->Adapter()); - params.push_back(inputNameIdent); + params.push_back(identClone); - auto *const enumTypeAnnotation = MakeTypeReference(Allocator(), enumType->GetName()); + auto *const enumTypeAnnotation = MakeTypeReference(this, enumType->GetName()); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), enumTypeAnnotation, enumType->GetDecl()->IsDeclare()); function->AddFlag(ir::ScriptFunctionFlags::THROWS); - auto *const functionIdent = - MakeQualifiedIdentifier(Allocator(), enumType->GetDecl(), ETSEnumType::VALUE_OF_METHOD_NAME); + auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::VALUE_OF_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); @@ -599,20 +618,18 @@ ETSEnumType::Method ETSChecker::CreateEnumValuesMethod(ir::Identifier *const ite auto *const paramScope = VarBinder()->Allocator()->New(Allocator(), Program()->GlobalScope()); - auto *const returnStmt = Allocator()->New(itemsArrayIdent); + auto *const returnStmt = AllocNode(itemsArrayIdent); ArenaVector body(Allocator()->Adapter()); body.push_back(returnStmt); ArenaVector params(Allocator()->Adapter()); - auto *const enumArrayTypeAnnotation = - Allocator()->New(MakeTypeReference(Allocator(), enumType->GetName())); + auto *const enumArrayTypeAnnotation = AllocNode(MakeTypeReference(this, enumType->GetName())); auto *const function = MakeFunction(this, VarBinder()->AsETSBinder(), paramScope, std::move(params), std::move(body), enumArrayTypeAnnotation, enumType->GetDecl()->IsDeclare()); - auto *const functionIdent = - MakeQualifiedIdentifier(Allocator(), enumType->GetDecl(), ETSEnumType::VALUES_METHOD_NAME); + auto *const functionIdent = MakeQualifiedIdentifier(this, enumType->GetDecl(), ETSEnumType::VALUES_METHOD_NAME); function->SetIdent(functionIdent); function->Scope()->BindInternalName(functionIdent->Name()); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index e6476c47e5aa9b87ce662392da988ef5231198fc..8409510c6ec7e093a73d7972c91cc35de5575be6 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -20,6 +20,7 @@ #include "varbinder/variable.h" #include "varbinder/variableFlags.h" #include "checker/ETSchecker.h" +#include "checker/ets/castingContext.h" #include "checker/ets/function_helpers.h" #include "checker/ets/typeRelationContext.h" #include "checker/types/ets/etsAsyncFuncReturnType.h" @@ -83,51 +84,80 @@ bool ETSChecker::IsCompatibleTypeArgument(ETSTypeParameter *typeParam, Type *typ /* A very rough and imprecise partial type inference */ bool ETSChecker::EnhanceSubstitutionForType(const ArenaVector &typeParams, Type *paramType, Type *argumentType, - Substitution *substitution, - ArenaUnorderedSet *instantiatedTypeParams) + Substitution *substitution) { if (paramType->IsETSTypeParameter()) { auto *const tparam = paramType->AsETSTypeParameter(); auto *const originalTparam = tparam->GetOriginal(); - if (instantiatedTypeParams->find(tparam) != instantiatedTypeParams->end() && - substitution->at(originalTparam) != argumentType) { - ThrowTypeError({"Type parameter already instantiated with another type "}, tparam->GetDeclNode()->Start()); - } if (std::find(typeParams.begin(), typeParams.end(), originalTparam) != typeParams.end() && substitution->count(originalTparam) == 0) { if (!IsCompatibleTypeArgument(tparam, argumentType, substitution)) { return false; } + if (substitution->find(originalTparam) != substitution->end() && + substitution->at(originalTparam) != argumentType) { + ThrowTypeError({"Type parameter already instantiated with another type "}, + tparam->GetDeclNode()->Start()); + } ETSChecker::EmplaceSubstituted(substitution, originalTparam, argumentType); - instantiatedTypeParams->insert(tparam); return true; } } if (paramType->IsETSUnionType()) { - auto const &constitutent = paramType->AsETSUnionType()->ConstituentTypes(); - return std::all_of(constitutent.begin(), constitutent.end(), - [this, typeParams, argumentType, substitution, instantiatedTypeParams](Type *member) { - return EnhanceSubstitutionForType(typeParams, member, argumentType, substitution, - instantiatedTypeParams); - }); + return EnhanceSubstitutionForUnion(typeParams, paramType->AsETSUnionType(), argumentType, substitution); } - if (paramType->IsETSObjectType()) { - return EnhanceSubstitutionForObject(typeParams, paramType->AsETSObjectType(), argumentType, substitution, - instantiatedTypeParams); + return EnhanceSubstitutionForObject(typeParams, paramType->AsETSObjectType(), argumentType, substitution); + } + return true; +} + +bool ETSChecker::EnhanceSubstitutionForUnion(const ArenaVector &typeParams, ETSUnionType *paramUn, + Type *argumentType, Substitution *substitution) +{ + if (!argumentType->IsETSUnionType()) { + for (auto *ctype : paramUn->ConstituentTypes()) { + if (!EnhanceSubstitutionForType(typeParams, ctype, argumentType, substitution)) { + return false; + } + } + return true; + } + auto *const argUn = argumentType->AsETSUnionType(); + + ArenaVector paramWlist(Allocator()->Adapter()); + ArenaVector argWlist(Allocator()->Adapter()); + + for (auto *pc : paramUn->ConstituentTypes()) { + for (auto *ac : argUn->ConstituentTypes()) { + if (ETSChecker::GetOriginalBaseType(pc) != ETSChecker::GetOriginalBaseType(ac)) { + paramWlist.push_back(pc); + argWlist.push_back(ac); + continue; + } + if (!EnhanceSubstitutionForType(typeParams, pc, ac, substitution)) { + return false; + } + } + } + auto *const newArg = CreateETSUnionType(std::move(argWlist)); + + for (auto *pc : paramWlist) { + if (!EnhanceSubstitutionForType(typeParams, pc, newArg, substitution)) { + return false; + } } return true; } bool ETSChecker::EnhanceSubstitutionForObject(const ArenaVector &typeParams, ETSObjectType *paramType, - Type *argumentType, Substitution *substitution, - ArenaUnorderedSet *instantiatedTypeParams) + Type *argumentType, Substitution *substitution) { auto *paramObjType = paramType->AsETSObjectType(); - auto const enhance = [this, typeParams, substitution, instantiatedTypeParams](Type *ptype, Type *atype) { - return EnhanceSubstitutionForType(typeParams, ptype, atype, substitution, instantiatedTypeParams); + auto const enhance = [this, typeParams, substitution](Type *ptype, Type *atype) { + return EnhanceSubstitutionForType(typeParams, ptype, atype, substitution); }; if (argumentType->IsETSObjectType()) { @@ -143,10 +173,12 @@ bool ETSChecker::EnhanceSubstitutionForObject(const ArenaVector &typePar } if (argumentType->IsETSFunctionType() && paramObjType->HasObjectFlag(ETSObjectFlags::FUNCTIONAL_INTERFACE)) { - auto ¶meterSignatures = paramObjType->GetOwnProperty("invoke") - ->TsType() - ->AsETSFunctionType() - ->CallSignatures(); + auto ¶meterSignatures = + paramObjType + ->GetOwnProperty(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME) + ->TsType() + ->AsETSFunctionType() + ->CallSignatures(); auto &argumentSignatures = argumentType->AsETSFunctionType()->CallSignatures(); ASSERT(argumentSignatures.size() == 1); ASSERT(parameterSignatures.size() == 1); @@ -892,7 +924,7 @@ Type *ETSChecker::ComposeReturnType(ir::ScriptFunction *func, util::StringView f } else if (func->IsEntryPoint() && returnTypeAnnotation->GetType(this) == GlobalBuiltinVoidType()) { returnType = GlobalVoidType(); } else { - returnType = GetTypeFromTypeAnnotation(returnTypeAnnotation); + returnType = returnTypeAnnotation->GetType(this); returnTypeAnnotation->SetTsType(returnType); } @@ -926,7 +958,7 @@ SignatureInfo *ETSChecker::ComposeSignatureInfo(ir::ScriptFunction *func) auto *const restParamTypeAnnotation = param->TypeAnnotation(); ASSERT(restParamTypeAnnotation); - signatureInfo->restVar->SetTsType(GetTypeFromTypeAnnotation(restParamTypeAnnotation)); + signatureInfo->restVar->SetTsType(restParamTypeAnnotation->GetType(this)); auto arrayType = signatureInfo->restVar->TsType()->AsETSArrayType(); CreateBuiltinArraySignature(arrayType, arrayType->Rank()); } else { @@ -938,7 +970,7 @@ SignatureInfo *ETSChecker::ComposeSignatureInfo(ir::ScriptFunction *func) auto *const paramTypeAnnotation = param->TypeAnnotation(); ASSERT(paramTypeAnnotation); - paramVar->SetTsType(GetTypeFromTypeAnnotation(paramTypeAnnotation)); + paramVar->SetTsType(paramTypeAnnotation->GetType(this)); signatureInfo->params.push_back(paramVar->AsLocalVariable()); ++signatureInfo->minArgCount; } @@ -1405,83 +1437,53 @@ void ETSChecker::CheckCapturedVariables() } } -void ETSChecker::BuildFunctionalInterfaceName(ir::ETSFunctionType *funcType) -{ - VarBinder()->AsETSBinder()->BuildFunctionalInterfaceName(funcType); -} +// Lambda creation for Lambda expressions -void ETSChecker::CreateFunctionalInterfaceForFunctionType(ir::ETSFunctionType *funcType) +// Chunk pulled out of CreateLambdaObjectForLambdaReference to appease Chinese code checker +static std::pair, bool> CreateLambdaObjectPropertiesForLambdaReference( + ETSChecker *checker, ir::ArrowFunctionExpression *lambda, varbinder::ClassScope *classScope) { - auto *identNode = Allocator()->New(util::StringView("FunctionalInterface"), Allocator()); - - auto interfaceCtx = varbinder::LexicalScope(VarBinder()); - auto *interfaceScope = interfaceCtx.GetScope(); - - ArenaVector members(Allocator()->Adapter()); - ir::MethodDefinition *invokeFunc = CreateInvokeFunction(funcType); - members.push_back(invokeFunc); - - auto methodCtx = - varbinder::LexicalScope::Enter(VarBinder(), interfaceScope->InstanceMethodScope()); - auto [_, var] = VarBinder()->NewVarDecl(invokeFunc->Start(), Allocator(), - invokeFunc->Id()->Name(), invokeFunc); - (void)_; - var->AddFlag(varbinder::VariableFlags::METHOD); - invokeFunc->Function()->Id()->SetVariable(var); + bool saveThis = false; + size_t idx = 0; + const auto &capturedVars = lambda->CapturedVars(); - if (funcType->IsThrowing()) { - invokeFunc->Function()->AddFlag(ir::ScriptFunctionFlags::THROWS); + // Create the synthetic class property nodes for the captured variables + ArenaVector properties(checker->Allocator()->Adapter()); + for (const auto *it : capturedVars) { + if (it->HasFlag(varbinder::VariableFlags::LOCAL)) { + properties.push_back(checker->CreateLambdaCapturedField(it, classScope, idx, lambda->Start())); + idx++; + } else if (!it->HasFlag(varbinder::VariableFlags::STATIC) && + !checker->Context().ContainingClass()->HasObjectFlag(ETSObjectFlags::GLOBAL)) { + saveThis = true; + } } - auto *body = Allocator()->New(std::move(members)); - - ArenaVector extends(Allocator()->Adapter()); - auto *interfaceDecl = Allocator()->New( - Allocator(), identNode, nullptr, body, std::move(extends), false, false, Language(Language::Id::ETS)); - interfaceDecl->SetScope(interfaceScope); - interfaceDecl->AddModifier(ir::ModifierFlags::FUNCTIONAL); - funcType->SetFunctionalInterface(interfaceDecl); - invokeFunc->SetParent(interfaceDecl); + // If the lambda captured a property in the current class, we have to make a synthetic class property to store + // 'this' in it + if (saveThis) { + properties.push_back(checker->CreateLambdaCapturedThis(classScope, idx, lambda->Start())); + idx++; + } - VarBinder()->AsETSBinder()->BuildFunctionType(funcType); + return {properties, saveThis}; } -ir::MethodDefinition *ETSChecker::CreateInvokeFunction(ir::ETSFunctionType *funcType) +static void HandleAsyncFuncInLambda(ETSChecker *checker, ir::ArrowFunctionExpression *lambda, + ir::MethodDefinition *proxyMethod, ir::ClassDefinition *currentClassDef) { - auto *identNode = Allocator()->New(util::StringView("invoke"), Allocator()); - - ArenaVector params(Allocator()->Adapter()); - auto *funcParamScope = CopyParams(funcType->Params(), params); - - auto paramCtx = varbinder::LexicalScope::Enter(VarBinder(), funcParamScope, false); - auto functionCtx = varbinder::LexicalScope(VarBinder()); - auto *functionScope = functionCtx.GetScope(); - functionScope->BindParamScope(funcParamScope); - funcParamScope->BindFunctionScope(functionScope); - - ir::ModifierFlags flags = ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::PUBLIC; - auto *func = Allocator()->New( - ir::FunctionSignature(nullptr, std::move(params), funcType->ReturnType()), nullptr, - ir::ScriptFunctionFlags::METHOD, flags, false, Language(Language::Id::ETS)); - - func->SetScope(functionScope); - functionScope->BindNode(func); - funcParamScope->BindNode(func); - - auto *funcExpr = Allocator()->New(func); - func->SetIdent(identNode); - - auto *method = Allocator()->New(ir::MethodDefinitionKind::METHOD, identNode, funcExpr, flags, - Allocator(), false); - - funcExpr->SetParent(method); - func->SetParent(funcExpr); - - return method; + ir::MethodDefinition *asyncImpl = checker->CreateAsyncProxy(proxyMethod, currentClassDef); + ir::ScriptFunction *asyncImplFunc = asyncImpl->Function(); + currentClassDef->Body().push_back(asyncImpl); + asyncImpl->SetParent(currentClassDef); + checker->ReplaceIdentifierReferencesInProxyMethod(asyncImplFunc->Body(), asyncImplFunc->Params(), + lambda->Function()->Params(), lambda->CapturedVars()); + Signature *implSig = checker->CreateSignature(proxyMethod->Function()->Signature()->GetSignatureInfo(), + checker->GlobalETSObjectType(), asyncImplFunc); + asyncImplFunc->SetSignature(implSig); + checker->VarBinder()->AsETSBinder()->BuildFunctionName(asyncImpl->Function()); } -// Lambda creation for Lambda expressions - void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpression *lambda, ETSObjectType *functionalInterface) { @@ -1489,33 +1491,12 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio return; } - bool saveThis = false; - size_t idx = 0; - const auto &capturedVars = lambda->CapturedVars(); - auto *currentClassDef = Context().ContainingClass()->GetDeclNode()->AsClassDefinition(); - // Create the class scope for the synthetic lambda class node auto classCtx = varbinder::LexicalScope(VarBinder()); auto *classScope = classCtx.GetScope(); - // Create the synthetic class property nodes for the captured variables - ArenaVector properties(Allocator()->Adapter()); - for (const auto *it : capturedVars) { - if (it->HasFlag(varbinder::VariableFlags::LOCAL)) { - properties.push_back(CreateLambdaCapturedField(it, classScope, idx, lambda->Start())); - idx++; - } else if (!it->HasFlag(varbinder::VariableFlags::STATIC) && - !Context().ContainingClass()->HasObjectFlag(ETSObjectFlags::GLOBAL)) { - saveThis = true; - } - } - - // If the lambda captured a property in the current class, we have to make a synthetic class property to store - // 'this' in it - if (saveThis) { - properties.push_back(CreateLambdaCapturedThis(classScope, idx, lambda->Start())); - idx++; - } + auto [properties, saveThis] = CreateLambdaObjectPropertiesForLambdaReference(this, lambda, classScope); + auto *currentClassDef = Context().ContainingClass()->GetDeclNode()->AsClassDefinition(); // Create the synthetic proxy method node for the current class definiton, which we will use in the lambda // 'invoke' method to propagate the function call to the current class @@ -1526,20 +1507,22 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio properties.push_back(ctor); // Create the synthetic invoke node for the lambda class, which will propagate the call to the proxy method - auto *invokeFunc = CreateLambdaInvokeProto(); + auto *invoke0Func = CreateLambdaInvokeProto(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME); + auto *invokeFunc = CreateLambdaInvokeProto("invoke"); + properties.push_back(invoke0Func); properties.push_back(invokeFunc); // Create the declarations for the synthetic constructor and invoke method CreateLambdaFuncDecl(ctor, classScope->StaticMethodScope()); + CreateLambdaFuncDecl(invoke0Func, classScope->InstanceMethodScope()); CreateLambdaFuncDecl(invokeFunc, classScope->InstanceMethodScope()); // Create the synthetic lambda class node - ArenaVector implements(Allocator()->Adapter()); - auto *identNode = Allocator()->New(util::StringView("LambdaObject"), Allocator()); + auto *identNode = AllocNode(util::StringView("LambdaObject"), Allocator()); auto *lambdaObject = - Allocator()->New(Allocator(), identNode, std::move(properties), - ir::ClassDefinitionModifiers::DECLARATION, Language(Language::Id::ETS)); + AllocNode(Allocator(), identNode, std::move(properties), + ir::ClassDefinitionModifiers::DECLARATION, Language(Language::Id::ETS)); lambda->SetResolvedLambda(lambdaObject); lambda->SetTsType(functionalInterface); lambdaObject->SetScope(classScope); @@ -1553,6 +1536,7 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio // Set the parent nodes ctor->SetParent(lambdaObject); + invoke0Func->SetParent(lambdaObject); invokeFunc->SetParent(lambdaObject); classScope->BindNode(lambdaObject); @@ -1560,17 +1544,9 @@ void ETSChecker::CreateLambdaObjectForLambdaReference(ir::ArrowFunctionExpressio VarBinder()->AsETSBinder()->BuildLambdaObject(lambda, lambdaObject, proxyMethod->Function()->Signature()); // Resolve the proxy method - ResolveProxyMethod(proxyMethod, lambda); + ResolveProxyMethod(currentClassDef, proxyMethod, lambda); if (lambda->Function()->IsAsyncFunc()) { - ir::MethodDefinition *asyncImpl = CreateAsyncProxy(proxyMethod, currentClassDef); - ir::ScriptFunction *asyncImplFunc = asyncImpl->Function(); - currentClassDef->Body().push_back(asyncImpl); - ReplaceIdentifierReferencesInProxyMethod(asyncImplFunc->Body(), asyncImplFunc->Params(), - lambda->Function()->Params(), lambda->CapturedVars()); - Signature *implSig = CreateSignature(proxyMethod->Function()->Signature()->GetSignatureInfo(), - GlobalETSObjectType(), asyncImplFunc); - asyncImplFunc->SetSignature(implSig); - VarBinder()->AsETSBinder()->BuildFunctionName(asyncImpl->Function()); + HandleAsyncFuncInLambda(this, lambda, proxyMethod, currentClassDef); } // Resolve the lambda object @@ -1608,45 +1584,75 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambdaObject, ETSObjec ResolveLambdaObjectCtor(lambdaObject); // Resolve the invoke function - ResolveLambdaObjectInvoke(lambdaObject, lambda, proxyMethod, !saveThis); + ResolveLambdaObjectInvoke(lambdaObject, lambda, proxyMethod, !saveThis, true); + ResolveLambdaObjectInvoke(lambdaObject, lambda, proxyMethod, !saveThis, false); } -void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, ir::ArrowFunctionExpression *lambda, - ir::MethodDefinition *proxyMethod, bool isStatic) +static Signature *CreateInvokeSignature(ETSChecker *checker, ir::ArrowFunctionExpression *lambda, + ir::ScriptFunction *invokeFunc, ETSObjectType *lambdaObjectType, + bool ifaceOverride) { - const auto &lambdaBody = lambdaObject->Body(); - auto *invokeFunc = lambdaBody[lambdaBody.size() - 1]->AsMethodDefinition()->Function(); - ETSObjectType *lambdaObjectType = lambdaObject->TsType()->AsETSObjectType(); - - // Set the implicit 'this' parameters type to the lambda object - auto *thisVar = invokeFunc->Scope()->ParamScope()->Params().front(); - thisVar->SetTsType(lambdaObjectType); + auto *allocator = checker->Allocator(); // Create the signature for the invoke function type - auto *invokeSignatureInfo = CreateSignatureInfo(); + auto *invokeSignatureInfo = checker->CreateSignatureInfo(); invokeSignatureInfo->restVar = nullptr; // Create the parameters for the invoke function, based on the lambda function's parameters - for (auto *it : lambda->Function()->Params()) { + auto maxParamsNum = checker->GlobalBuiltinFunctionTypeVariadicThreshold(); + auto paramsNum = lambda->Function()->Params().size(); + if (paramsNum < maxParamsNum || !ifaceOverride) { + for (auto *it : lambda->Function()->Params()) { + auto paramCtx = varbinder::LexicalScope::Enter( + checker->VarBinder(), invokeFunc->Scope()->ParamScope(), false); + auto *const param = it->Clone(allocator, it->Parent())->AsETSParameterExpression(); + auto [_, var] = checker->VarBinder()->AddParamDecl(param); + (void)_; + var->SetTsType(ifaceOverride ? checker->GlobalETSNullishObjectType() : param->Variable()->TsType()); + param->Ident()->SetVariable(var); + invokeFunc->Params().push_back(param); + invokeSignatureInfo->minArgCount++; + invokeSignatureInfo->params.push_back(var->AsLocalVariable()); + } + } else { auto paramCtx = varbinder::LexicalScope::Enter( - VarBinder(), invokeFunc->Scope()->ParamScope(), false); + checker->VarBinder(), invokeFunc->Scope()->ParamScope(), false); - auto *const param = it->AsETSParameterExpression(); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto *id = checker->AllocNode("p", allocator); + auto *restElement = checker->AllocNode(ir::AstNodeType::REST_ELEMENT, allocator, id); + auto *const param = checker->AllocNode(restElement, nullptr); + auto [_, var] = checker->VarBinder()->AddParamDecl(param); (void)_; - var->SetTsType(param->Variable()->TsType()); + var->SetTsType(checker->CreateETSArrayType(checker->GlobalETSNullishObjectType())); param->Ident()->SetVariable(var); invokeFunc->Params().push_back(param); - invokeSignatureInfo->minArgCount++; - invokeSignatureInfo->params.push_back(var->AsLocalVariable()); + invokeSignatureInfo->restVar = var->AsLocalVariable(); } // Create the function type for the invoke method - auto *invokeSignature = - CreateSignature(invokeSignatureInfo, lambda->Function()->Signature()->ReturnType(), invokeFunc); + auto *invokeSignature = checker->CreateSignature(invokeSignatureInfo, + ifaceOverride ? checker->GlobalETSNullishObjectType() + : lambda->Function()->Signature()->ReturnType(), + invokeFunc); invokeSignature->SetOwner(lambdaObjectType); invokeSignature->AddSignatureFlag(checker::SignatureFlags::CALL); + return invokeSignature; +} + +void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, ir::ArrowFunctionExpression *lambda, + ir::MethodDefinition *proxyMethod, bool isStatic, bool ifaceOverride) +{ + const auto &lambdaBody = lambdaObject->Body(); + auto *invokeFunc = lambdaBody[lambdaBody.size() - (ifaceOverride ? 2 : 1)]->AsMethodDefinition()->Function(); + ETSObjectType *lambdaObjectType = lambdaObject->TsType()->AsETSObjectType(); + + // Set the implicit 'this' parameters type to the lambda object + auto *thisVar = invokeFunc->Scope()->ParamScope()->Params().front(); + thisVar->SetTsType(lambdaObjectType); + + // Create the function type for the invoke method + auto *invokeSignature = CreateInvokeSignature(this, lambda, invokeFunc, lambdaObjectType, ifaceOverride); auto *invokeType = CreateETSFunctionType(invokeSignature); invokeFunc->SetSignature(invokeSignature); invokeFunc->Id()->Variable()->SetTsType(invokeType); @@ -1654,19 +1660,119 @@ void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, ir lambdaObjectType->AddProperty( invokeFunc->Id()->Variable()->AsLocalVariable()); - // Fill out the type information for the body of the invoke function - auto *resolvedLambdaInvokeFunctionBody = ResolveLambdaObjectInvokeFuncBody(lambdaObject, proxyMethod, isStatic); if (invokeFunc->IsAsyncFunc()) { return; } + + // Fill out the type information for the body of the invoke function + auto *resolvedLambdaInvokeFunctionBody = + ResolveLambdaObjectInvokeFuncBody(lambdaObject, lambda, proxyMethod, isStatic, ifaceOverride); + resolvedLambdaInvokeFunctionBody->SetParent(invokeFunc->Body()); invokeFunc->Body()->AsBlockStatement()->Statements().push_back(resolvedLambdaInvokeFunctionBody); + if (resolvedLambdaInvokeFunctionBody->IsExpressionStatement()) { - invokeFunc->Body()->AsBlockStatement()->Statements().push_back(Allocator()->New(nullptr)); + auto *const returnStatement = Allocator()->New(nullptr); + returnStatement->SetParent(invokeFunc->Body()); + invokeFunc->Body()->AsBlockStatement()->Statements().push_back(returnStatement); } } +/* Pulled out to appease the Chinese checker */ + +static void AddFieldRefsToCallParameters(ETSChecker *checker, ir::ClassDefinition *lambdaObject, bool isStatic, + ArenaVector &callParams) +{ + auto *allocator = checker->Allocator(); + auto &lambdaBody = lambdaObject->Body(); + size_t counter = isStatic ? lambdaBody.size() - 3 : lambdaBody.size() - 4; + for (size_t i = 0; i < counter; i++) { + if (lambdaBody[i]->IsMethodDefinition()) { + break; + } + + auto *classProp = lambdaBody[i]->AsClassProperty(); + auto *param = allocator->New(classProp->Key()->AsIdentifier()->Name(), allocator); + param->SetVariable(classProp->Key()->AsIdentifier()->Variable()); + param->SetIgnoreBox(); + param->SetTsType(checker->MaybeBoxedType(param->Variable())); + callParams.push_back(param); + } +} + +static ir::TSAsExpression *BuildNarrowingToType(ETSChecker *checker, ir::Expression *arg, Type *target) +{ + auto *boxedTarget = checker->MaybePromotedBuiltinType(target); + auto *paramAsExpr = + checker->AllocNode(arg, checker->AllocNode(boxedTarget), false); + if (boxedTarget != target) { + paramAsExpr = + checker->AllocNode(paramAsExpr, checker->AllocNode(target), false); + } + return paramAsExpr; +} + +static ArenaVector ResolveCallParametersForLambdaFuncBody(ETSChecker *checker, + ir::ClassDefinition *lambdaObject, + ir::ArrowFunctionExpression *lambda, + ir::ScriptFunction *invokeFunc, + bool isStatic, bool ifaceOverride) +{ + auto *allocator = checker->Allocator(); + ArenaVector callParams(allocator->Adapter()); + + AddFieldRefsToCallParameters(checker, lambdaObject, isStatic, callParams); + + auto maxParamsNum = checker->GlobalBuiltinFunctionTypeVariadicThreshold(); + auto paramsNum = lambda->Function()->Params().size(); + if (!ifaceOverride) { + for (auto const *const it : invokeFunc->Params()) { + auto const *const param = it->AsETSParameterExpression(); + auto *const paramIdent = allocator->New(param->Ident()->Name(), allocator); + paramIdent->SetVariable(param->Variable()); + paramIdent->SetTsType(param->Variable()->TsType()); + callParams.push_back(paramIdent); + } + } else if (paramsNum < maxParamsNum) { + // Then we add the lambda functions parameters to the call + auto nargs = invokeFunc->Params().size(); + for (size_t i = 0; i < nargs; i++) { + auto const *const param = invokeFunc->Params()[i]->AsETSParameterExpression(); + auto *const paramIdent = allocator->New(param->Ident()->Name(), allocator); + paramIdent->SetVariable(param->Variable()); + paramIdent->SetTsType(param->Variable()->TsType()); + + auto *lambdaParam = lambda->Function()->Params()[i]->AsETSParameterExpression(); + auto *const paramCast = + BuildNarrowingToType(checker, paramIdent, lambdaParam->TypeAnnotation()->GetType(checker)); + paramCast->Check(checker); + callParams.push_back(paramCast); + } + } else { + ASSERT(invokeFunc->Params().size() == 1); + auto const *const param = invokeFunc->Params()[0]->AsETSParameterExpression(); + auto *const paramIdent = allocator->New(param->Ident()->Name(), allocator); + paramIdent->SetVariable(param->Variable()); + paramIdent->SetTsType(param->Variable()->TsType()); + + for (size_t i = 0; i < paramsNum; i++) { + auto *idx = allocator->New(lexer::Number(static_cast(i))); + auto *arg = allocator->New(paramIdent, idx, ir::MemberExpressionKind::ELEMENT_ACCESS, + true, false); + + auto *lambdaParam = lambda->Function()->Params()[i]->AsETSParameterExpression(); + auto *const paramCast = BuildNarrowingToType(checker, arg, lambdaParam->TypeAnnotation()->GetType(checker)); + paramCast->Check(checker); + callParams.push_back(paramCast); + } + } + + return callParams; +} + ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaObject, - ir::MethodDefinition *proxyMethod, bool isStatic) + ir::ArrowFunctionExpression *lambda, + ir::MethodDefinition *proxyMethod, bool isStatic, + bool ifaceOverride) { const auto &lambdaBody = lambdaObject->Body(); auto *proxySignature = proxyMethod->Function()->Signature(); @@ -1675,13 +1781,13 @@ ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition // If the proxy method is static, we should call it through the owner class itself if (isStatic) { - fieldIdent = Allocator()->New(proxySignature->Owner()->Name(), Allocator()); + fieldIdent = AllocNode(proxySignature->Owner()->Name(), Allocator()); fieldPropType = proxySignature->Owner(); fieldIdent->SetVariable(proxySignature->Owner()->Variable()); fieldIdent->SetTsType(fieldPropType); } else { // Otherwise, we call the proxy method through the saved 'this' field - auto *savedThis = lambdaBody[lambdaBody.size() - 3]->AsClassProperty(); + auto *savedThis = lambdaBody[lambdaBody.size() - 4]->AsClassProperty(); auto *fieldProp = savedThis->Key()->AsIdentifier()->Variable(); fieldPropType = fieldProp->TsType()->AsETSObjectType(); fieldIdent = Allocator()->New(savedThis->Key()->AsIdentifier()->Name(), Allocator()); @@ -1690,55 +1796,39 @@ ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition } // Set the type information for the proxy function call - auto *funcIdent = Allocator()->New(proxyMethod->Function()->Id()->Name(), Allocator()); - auto *callee = Allocator()->New(fieldIdent, funcIdent, - ir::MemberExpressionKind::ELEMENT_ACCESS, false, false); + auto *funcIdent = AllocNode(proxyMethod->Function()->Id()->Name(), Allocator()); + auto *callee = + AllocNode(fieldIdent, funcIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, false, false); callee->SetPropVar(proxySignature->OwnerVar()->AsLocalVariable()); callee->SetObjectType(fieldPropType); callee->SetTsType(proxySignature->OwnerVar()->TsType()); // Resolve the proxy method call arguments, first we add the captured fields to the call - auto *invokeFunc = lambdaBody[lambdaBody.size() - 1]->AsMethodDefinition()->Function(); - ArenaVector callParams(Allocator()->Adapter()); - size_t counter = isStatic ? lambdaBody.size() - 2 : lambdaBody.size() - 3; - for (size_t i = 0; i < counter; i++) { - if (lambdaBody[i]->IsMethodDefinition()) { - break; - } - - auto *classProp = lambdaBody[i]->AsClassProperty(); - auto *param = Allocator()->New(classProp->Key()->AsIdentifier()->Name(), Allocator()); - param->SetVariable(classProp->Key()->AsIdentifier()->Variable()); - param->SetIgnoreBox(); - param->SetTsType(MaybeBoxedType(param->Variable())); - callParams.push_back(param); - } - - // Then we add the lambda functions parameters to the call - for (auto const *const it : invokeFunc->Params()) { - auto const *const param = it->AsETSParameterExpression(); - auto *const paramIdent = Allocator()->New(param->Ident()->Name(), Allocator()); - paramIdent->SetVariable(param->Variable()); - paramIdent->SetTsType(param->Variable()->TsType()); - callParams.push_back(paramIdent); - } + auto *invokeFunc = lambdaBody[lambdaBody.size() - (ifaceOverride ? 2 : 1)]->AsMethodDefinition()->Function(); + ArenaVector callParams = + ResolveCallParametersForLambdaFuncBody(this, lambdaObject, lambda, invokeFunc, isStatic, ifaceOverride); // Create the synthetic call expression to the proxy method - auto *resolvedCall = Allocator()->New(callee, std::move(callParams), nullptr, false); + auto *resolvedCall = AllocNode(callee, std::move(callParams), nullptr, false); resolvedCall->SetTsType(proxySignature->ReturnType()); resolvedCall->SetSignature(proxySignature); if (proxySignature->ReturnType()->IsETSVoidType()) { - return Allocator()->New(resolvedCall); + return AllocNode(resolvedCall); + } + + if (ifaceOverride && resolvedCall->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + resolvedCall->AddBoxingUnboxingFlags(GetBoxingFlag(resolvedCall->TsType())); } - return Allocator()->New(resolvedCall); + + return AllocNode(resolvedCall); } void ETSChecker::ResolveLambdaObjectCtor(ir::ClassDefinition *lambdaObject) { const auto &lambdaBody = lambdaObject->Body(); auto *lambdaObjectType = lambdaObject->TsType()->AsETSObjectType(); - auto *ctorFunc = lambdaBody[lambdaBody.size() - 2]->AsMethodDefinition()->Function(); + auto *ctorFunc = lambdaBody[lambdaBody.size() - 3]->AsMethodDefinition()->Function(); // Set the implicit 'this' parameters type to the lambda object auto *thisVar = ctorFunc->Scope()->ParamScope()->Params().front(); @@ -1781,15 +1871,16 @@ void ETSChecker::ResolveLambdaObjectCtor(ir::ClassDefinition *lambdaObject) } } -void ETSChecker::ResolveProxyMethod(ir::MethodDefinition *proxyMethod, ir::ArrowFunctionExpression *lambda) +void ETSChecker::ResolveProxyMethod(ir::ClassDefinition *const classDefinition, ir::MethodDefinition *proxyMethod, + ir::ArrowFunctionExpression *lambda) { + auto *const varbinder = VarBinder()->AsETSBinder(); auto *func = proxyMethod->Function(); bool isStatic = func->IsStatic(); auto *currentClassType = Context().ContainingClass(); // Build the proxy method in the binder - VarBinder()->AsETSBinder()->BuildProxyMethod( - func, currentClassType->GetDeclNode()->AsClassDefinition()->InternalName(), isStatic); + varbinder->BuildProxyMethod(func, currentClassType->GetDeclNode()->AsClassDefinition()->InternalName(), isStatic); // If the proxy method is not static, set the implicit 'this' parameters type to the current class if (!isStatic) { @@ -1811,13 +1902,28 @@ void ETSChecker::ResolveProxyMethod(ir::MethodDefinition *proxyMethod, ir::Arrow signature->SetOwner(currentClassType); // Add the proxy method to the current class methods + auto *const variable = func->Id()->Variable()->AsLocalVariable(); if (isStatic) { - currentClassType->AddProperty(func->Id()->Variable()->AsLocalVariable()); + currentClassType->AddProperty(variable); } else { - currentClassType->AddProperty( - func->Id()->Variable()->AsLocalVariable()); + currentClassType->AddProperty(variable); + } + varbinder->BuildFunctionName(func); + + if (lambda->Function()->IsAsyncFunc()) { + ir::MethodDefinition *asyncImpl = CreateAsyncProxy(proxyMethod, classDefinition); + ir::ScriptFunction *asyncImplFunc = asyncImpl->Function(); + + classDefinition->Body().emplace_back(asyncImpl); + asyncImpl->SetParent(classDefinition); + + ReplaceIdentifierReferencesInProxyMethod(asyncImplFunc->Body(), asyncImplFunc->Params(), + lambda->Function()->Params(), lambda->CapturedVars()); + Signature *implSig = CreateSignature(proxyMethod->Function()->Signature()->GetSignatureInfo(), + GlobalETSObjectType(), asyncImplFunc); + asyncImplFunc->SetSignature(implSig); + varbinder->BuildFunctionName(asyncImplFunc); } - VarBinder()->AsETSBinder()->BuildFunctionName(func); } size_t ETSChecker::ComputeProxyMethods(ir::ClassDefinition *klass) @@ -1868,8 +1974,8 @@ ir::ScriptFunction *ETSChecker::CreateProxyFunc(ir::ArrowFunctionExpression *lam funcFlags |= ir::ScriptFunctionFlags::ASYNC; } auto *func = Allocator()->New( - ir::FunctionSignature(nullptr, std::move(params), lambda->Function()->ReturnTypeAnnotation()), body, funcFlags, - GetFlagsForProxyLambda(isStatic), false, Language(Language::Id::ETS)); + ir::FunctionSignature(nullptr, std::move(params), lambda->Function()->ReturnTypeAnnotation()), body, + ir::ScriptFunction::ScriptFunctionData {funcFlags, GetFlagsForProxyLambda(isStatic)}); func->SetScope(scope); if (!func->IsAsyncFunc()) { @@ -1901,23 +2007,22 @@ ir::MethodDefinition *ETSChecker::CreateProxyMethodForLambda(ir::ClassDefinition auto *func = CreateProxyFunc(lambda, captured, isStatic); // Create the synthetic proxy method - auto *funcExpr = Allocator()->New(func); + auto *funcExpr = AllocNode(func); util::UString funcName(util::StringView("lambda$invoke$"), Allocator()); funcName.Append(std::to_string(ComputeProxyMethods(klass))); - auto *identNode = Allocator()->New(funcName.View(), Allocator()); + auto *identNode = AllocNode(funcName.View(), Allocator()); func->SetIdent(identNode); - auto *proxy = Allocator()->New(ir::MethodDefinitionKind::METHOD, identNode, funcExpr, - GetFlagsForProxyLambda(isStatic), Allocator(), false); + + auto *identClone = identNode->Clone(Allocator(), nullptr); + auto *proxy = AllocNode(ir::MethodDefinitionKind::METHOD, identClone, funcExpr, + GetFlagsForProxyLambda(isStatic), Allocator(), false); + klass->Body().push_back(proxy); proxy->SetParent(klass); // Add the proxy method to the current class declarations CreateLambdaFuncDecl(proxy, klass->Scope()->AsClassScope()->InstanceMethodScope()); - // Set the parent nodes - func->SetParent(funcExpr); - funcExpr->SetParent(proxy); - // Create the signature template for the proxy method to be able to save this signatures pointer in the binder // lambdaObjects_ to be able to compute the lambda object invoke functions internal name later auto *proxySignatureInfo = CreateSignatureInfo(); @@ -1973,16 +2078,18 @@ void ETSChecker::ReplaceIdentifierReferencesInProxyMethod( ir::AstNode *node, const ArenaVector &proxyParams, std::unordered_map &mergedTargetReferences) { - if (node->IsMemberExpression()) { - auto *memberExpr = node->AsMemberExpression(); - if (memberExpr->Kind() == ir::MemberExpressionKind::PROPERTY_ACCESS) { - ReplaceIdentifierReferenceInProxyMethod(memberExpr->Object(), proxyParams, mergedTargetReferences); - return; + if (node != nullptr) { + if (node->IsMemberExpression()) { + auto *memberExpr = node->AsMemberExpression(); + if (memberExpr->Kind() == ir::MemberExpressionKind::PROPERTY_ACCESS) { + ReplaceIdentifierReferenceInProxyMethod(memberExpr->Object(), proxyParams, mergedTargetReferences); + return; + } } + node->Iterate([this, &proxyParams, &mergedTargetReferences](ir::AstNode *childNode) { + ReplaceIdentifierReferenceInProxyMethod(childNode, proxyParams, mergedTargetReferences); + }); } - node->Iterate([this, &proxyParams, &mergedTargetReferences](ir::AstNode *childNode) { - ReplaceIdentifierReferenceInProxyMethod(childNode, proxyParams, mergedTargetReferences); - }); } void ETSChecker::ReplaceIdentifierReferenceInProxyMethod( @@ -2026,12 +2133,12 @@ varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunc // "this" should be binded with the parameter of the proxy method if (this->HasStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD) && lambda->CapturedVars()[i]->Name() == varbinder::VarBinder::MANDATORY_PARAM_THIS) { - paramIdent = Allocator()->New(varbinder::VarBinder::MANDATORY_PARAM_THIS, Allocator()); + paramIdent = AllocNode(varbinder::VarBinder::MANDATORY_PARAM_THIS, Allocator()); } else { - paramIdent = Allocator()->New(capturedVar->Name(), Allocator()); + paramIdent = AllocNode(capturedVar->Name(), Allocator()); } - auto *param = Allocator()->New(paramIdent, nullptr); + auto *param = AllocNode(paramIdent, nullptr); auto [_, var] = VarBinder()->AddParamDecl(param); (void)_; var->SetTsType(capturedVar->TsType()); @@ -2046,16 +2153,15 @@ varbinder::FunctionParamScope *ETSChecker::CreateProxyMethodParams(ir::ArrowFunc // Then add the lambda function parameters to the proxy method's parameter vector, and set the type from the // already computed types for the lambda parameters - for (auto const *const it : params) { - auto *const oldParamExprIdent = it->AsETSParameterExpression()->Ident(); - auto *const paramIdent = Allocator()->New(oldParamExprIdent->Name(), Allocator()); - auto *param = Allocator()->New(paramIdent, nullptr); - auto [_, var] = VarBinder()->AddParamDecl(param); + for (auto *const it : params) { + auto *const oldParameter = it->AsETSParameterExpression(); + auto *newParameter = oldParameter->Clone(Allocator(), nullptr); + auto [_, var] = VarBinder()->AddParamDecl(newParameter); (void)_; - var->SetTsType(oldParamExprIdent->Variable()->TsType()); - param->SetVariable(var); - param->SetTsType(oldParamExprIdent->Variable()->TsType()); - proxyParams.push_back(param); + var->SetTsType(oldParameter->Variable()->TsType()); + newParameter->SetVariable(var); + newParameter->SetTsType(oldParameter->Variable()->TsType()); + proxyParams.push_back(newParameter); } return paramCtx.GetScope(); @@ -2135,12 +2241,13 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(ArenaVectorNew(Allocator(), std::move(statements)); + auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); auto *func = - Allocator()->New(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::CONSTRUCTOR, false, Language(Language::Id::ETS)); + AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::CONSTRUCTOR}); func->SetScope(scope); + // Set the scopes scope->BindNode(func); funcParamScope->BindNode(func); @@ -2148,15 +2255,13 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(ArenaVectorBindFunctionScope(scope); // Create the name for the synthetic constructor - auto *funcExpr = Allocator()->New(func); - auto *key = Allocator()->New("constructor", Allocator()); + auto *funcExpr = AllocNode(func); + auto *key = AllocNode("constructor", Allocator()); func->SetIdent(key); - auto *ctor = Allocator()->New(ir::MethodDefinitionKind::CONSTRUCTOR, key, funcExpr, - ir::ModifierFlags::NONE, Allocator(), false); - // Set the parent nodes - func->SetParent(funcExpr); - funcExpr->SetParent(ctor); + auto *keyClone = key->Clone(Allocator(), nullptr); + auto *ctor = AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, keyClone, funcExpr, + ir::ModifierFlags::NONE, Allocator(), false); return ctor; } @@ -2171,8 +2276,8 @@ varbinder::FunctionParamScope *ETSChecker::CreateLambdaCtorImplicitParams(ArenaV // captured variables for (auto *it : properties) { auto *field = it->AsClassProperty()->Key()->AsIdentifier(); - auto *paramField = Allocator()->New(field->Name(), Allocator()); - auto *param = Allocator()->New(paramField, nullptr); + auto *paramField = field->Clone(Allocator(), nullptr); + auto *param = AllocNode(paramField, nullptr); auto [_, var] = VarBinder()->AddParamDecl(param); (void)_; auto *type = MaybeBoxedType(field->Variable()); @@ -2190,15 +2295,15 @@ ir::Statement *ETSChecker::CreateLambdaCtorFieldInit(util::StringView name, varb // Create synthetic field initializers for the lambda class fields // The node structure is the following: this.field0 = field0, where the left hand side refers to the lambda // classes field, and the right hand side is refers to the constructors parameter - auto *thisExpr = Allocator()->New(); - auto *fieldAccessExpr = Allocator()->New(name, Allocator()); - auto *leftHandSide = Allocator()->New( - thisExpr, fieldAccessExpr, ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); - auto *rightHandSide = Allocator()->New(name, Allocator()); + auto *thisExpr = AllocNode(); + auto *fieldAccessExpr = AllocNode(name, Allocator()); + auto *leftHandSide = AllocNode(thisExpr, fieldAccessExpr, + ir::MemberExpressionKind::PROPERTY_ACCESS, false, false); + auto *rightHandSide = AllocNode(name, Allocator()); rightHandSide->SetVariable(var); - auto *initializer = Allocator()->New(leftHandSide, rightHandSide, - lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - return Allocator()->New(initializer); + auto *initializer = + AllocNode(leftHandSide, rightHandSide, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + return AllocNode(initializer); } // Lambda creation for Function references @@ -2210,10 +2315,13 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si return; } + /* signature has been converted through BpxPrimitives, we need to call the original one */ + auto *trueSignature = signature->Function()->Signature(); + // Create the class scope for the synthetic lambda class node auto classCtx = varbinder::LexicalScope(VarBinder()); auto *classScope = classCtx.GetScope(); - bool isStaticReference = signature->HasSignatureFlag(SignatureFlags::STATIC); + bool isStaticReference = trueSignature->HasSignatureFlag(SignatureFlags::STATIC); // Create the synthetic field where we will store the instance object which we are trying to obtain the function // reference through, if the referenced function is static, we won't need to store the instance object @@ -2229,15 +2337,17 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si // Create the template for the synthetic invoke function which will propagate the function call to the saved // instance's referenced function, or the class static function, if this is a static reference - auto *invokeFunc = CreateLambdaInvokeProto(); + auto *invoke0Func = CreateLambdaInvokeProto(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME); + auto *invokeFunc = CreateLambdaInvokeProto("invoke"); + properties.push_back(invoke0Func); properties.push_back(invokeFunc); // Create the declarations for the synthetic constructor and invoke method CreateLambdaFuncDecl(ctor, classScope->StaticMethodScope()); + CreateLambdaFuncDecl(invoke0Func, classScope->InstanceMethodScope()); CreateLambdaFuncDecl(invokeFunc, classScope->InstanceMethodScope()); // Create the synthetic lambda class node - ArenaVector implements(Allocator()->Adapter()); auto *identNode = Allocator()->New(util::StringView("LambdaObject"), Allocator()); auto *lambdaObject = Allocator()->New(Allocator(), identNode, std::move(properties), @@ -2245,14 +2355,15 @@ void ETSChecker::CreateLambdaObjectForFunctionReference(ir::AstNode *refNode, Si lambdaObject->SetScope(classScope); // Set the parent nodes ctor->SetParent(lambdaObject); + invoke0Func->SetParent(lambdaObject); invokeFunc->SetParent(lambdaObject); classScope->BindNode(lambdaObject); // Build the lambda object in the binder - VarBinder()->AsETSBinder()->BuildLambdaObject(refNode, lambdaObject, signature); + VarBinder()->AsETSBinder()->BuildLambdaObject(refNode, lambdaObject, trueSignature); // Resolve the lambda object - ResolveLambdaObject(lambdaObject, signature, functionalInterface, refNode); + ResolveLambdaObject(lambdaObject, trueSignature, functionalInterface, refNode); } ir::AstNode *ETSChecker::CreateLambdaImplicitField(varbinder::ClassScope *scope, const lexer::SourcePosition &pos) @@ -2291,11 +2402,11 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa statements.push_back(CreateLambdaCtorFieldInit(util::StringView("field0"), var)); } - auto *body = Allocator()->New(Allocator(), std::move(statements)); + auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); auto *func = - Allocator()->New(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::CONSTRUCTOR, false, Language(Language::Id::ETS)); + AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::CONSTRUCTOR}); func->SetScope(scope); // Bind the scopes scope->BindNode(func); @@ -2304,15 +2415,13 @@ ir::MethodDefinition *ETSChecker::CreateLambdaImplicitCtor(const lexer::SourceRa funcParamScope->BindFunctionScope(scope); // Create the synthetic constructor - auto *funcExpr = Allocator()->New(func); - auto *key = Allocator()->New("constructor", Allocator()); + auto *funcExpr = AllocNode(func); + auto *key = AllocNode("constructor", Allocator()); func->SetIdent(key); - auto *ctor = Allocator()->New(ir::MethodDefinitionKind::CONSTRUCTOR, key, funcExpr, - ir::ModifierFlags::NONE, Allocator(), false); - // Set the parent nodes - func->SetParent(funcExpr); - funcExpr->SetParent(ctor); + auto *keyClone = key->Clone(Allocator(), nullptr); + auto *ctor = AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, keyClone, funcExpr, + ir::ModifierFlags::NONE, Allocator(), false); return ctor; } @@ -2327,8 +2436,8 @@ std::tuple ETSChecker::C // since when initializing the lambda class, we don't need to save the instance object which we tried to get the // function reference through if (!isStaticReference) { - auto *paramIdent = Allocator()->New("field0", Allocator()); - auto *param = Allocator()->New(paramIdent, nullptr); + auto *paramIdent = AllocNode("field0", Allocator()); + auto *param = AllocNode(paramIdent, nullptr); paramIdent->SetRange(pos); auto [_, var] = VarBinder()->AddParamDecl(param); (void)_; @@ -2340,22 +2449,21 @@ std::tuple ETSChecker::C return {paramCtx.GetScope(), nullptr}; } -ir::MethodDefinition *ETSChecker::CreateLambdaInvokeProto() +ir::MethodDefinition *ETSChecker::CreateLambdaInvokeProto(util::StringView invokeName) { // Create the template for the synthetic 'invoke' method, which will be used when the function type will be // called - auto *name = Allocator()->New("invoke", Allocator()); auto *paramScope = VarBinder()->Allocator()->New(Allocator(), VarBinder()->GetScope()); auto *scope = VarBinder()->Allocator()->New(Allocator(), paramScope); ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); - auto *body = Allocator()->New(Allocator(), std::move(statements)); + auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(scope); - auto *func = Allocator()->New(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::METHOD, ir::ModifierFlags::PUBLIC, false, - Language(Language::Id::ETS)); + auto *func = AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::METHOD, ir::ModifierFlags::PUBLIC}); func->SetScope(scope); scope->BindNode(func); @@ -2363,14 +2471,14 @@ ir::MethodDefinition *ETSChecker::CreateLambdaInvokeProto() scope->BindParamScope(paramScope); paramScope->BindFunctionScope(scope); - auto *funcExpr = Allocator()->New(func); + auto *name = AllocNode(invokeName, Allocator()); func->SetIdent(name); - auto *method = Allocator()->New(ir::MethodDefinitionKind::METHOD, name, funcExpr, - ir::ModifierFlags::PUBLIC, Allocator(), false); + auto *funcExpr = AllocNode(func); - funcExpr->SetParent(method); - func->SetParent(funcExpr); + auto *nameClone = name->Clone(Allocator(), nullptr); + auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, nameClone, funcExpr, + ir::ModifierFlags::PUBLIC, Allocator(), false); return method; } @@ -2379,9 +2487,11 @@ void ETSChecker::CreateLambdaFuncDecl(ir::MethodDefinition *func, varbinder::Loc { // Add the function declarations to the lambda class scope auto ctx = varbinder::LexicalScope::Enter(VarBinder(), scope); - auto [_, var] = - VarBinder()->NewVarDecl(func->Start(), Allocator(), func->Id()->Name(), func); - (void)_; + varbinder::Variable *var = scope->FindLocal(func->Id()->Name(), varbinder::ResolveBindingOptions::ALL_DECLARATION); + if (var == nullptr) { + var = std::get<1>( + VarBinder()->NewVarDecl(func->Start(), Allocator(), func->Id()->Name(), func)); + } var->AddFlag(varbinder::VariableFlags::METHOD); func->Function()->Id()->SetVariable(var); } @@ -2426,13 +2536,14 @@ void ETSChecker::ResolveLambdaObject(ir::ClassDefinition *lambdaObject, Signatur ResolveLambdaObjectCtor(lambdaObject, isStaticReference); // Resolve the invoke function - ResolveLambdaObjectInvoke(lambdaObject, signature); + ResolveLambdaObjectInvoke(lambdaObject, signature, true); + ResolveLambdaObjectInvoke(lambdaObject, signature, false); } void ETSChecker::ResolveLambdaObjectCtor(ir::ClassDefinition *lambdaObject, bool isStaticReference) { const auto &lambdaBody = lambdaObject->Body(); - auto *ctorFunc = lambdaBody[lambdaBody.size() - 2]->AsMethodDefinition()->Function(); + auto *ctorFunc = lambdaBody[lambdaBody.size() - 3]->AsMethodDefinition()->Function(); ETSObjectType *lambdaObjectType = lambdaObject->TsType()->AsETSObjectType(); varbinder::Variable *fieldVar {}; @@ -2490,41 +2601,70 @@ void ETSChecker::ResolveLambdaObjectCtor(ir::ClassDefinition *lambdaObject, bool fieldinit->Right()->SetTsType(ctorSignature->Params()[0]->TsType()); } -void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, Signature *signatureRef) +static Signature *CreateInvokeSignature(ETSChecker *checker, Signature *signatureRef, ir::ScriptFunction *invokeFunc, + ETSObjectType *lambdaObjectType, bool ifaceOverride) { - const auto &lambdaBody = lambdaObject->Body(); - auto *invokeFunc = lambdaBody[lambdaBody.size() - 1]->AsMethodDefinition()->Function(); - ETSObjectType *lambdaObjectType = lambdaObject->TsType()->AsETSObjectType(); - - // Set the implicit 'this' parameters type to the lambda object - auto *thisVar = invokeFunc->Scope()->ParamScope()->Params().front(); - thisVar->SetTsType(lambdaObjectType); + auto *allocator = checker->Allocator(); // Create the signature for the invoke function type - auto *invokeSignatureInfo = CreateSignatureInfo(); + auto *invokeSignatureInfo = checker->CreateSignatureInfo(); invokeSignatureInfo->restVar = nullptr; // Create the parameters for the invoke function, based on the referenced function's signature - for (auto *it : signatureRef->Params()) { + auto maxParamsNum = checker->GlobalBuiltinFunctionTypeVariadicThreshold(); + auto paramsNum = signatureRef->Params().size(); + if (paramsNum < maxParamsNum || !ifaceOverride) { + for (auto *it : signatureRef->Params()) { + auto paramCtx = varbinder::LexicalScope::Enter( + checker->VarBinder(), invokeFunc->Scope()->ParamScope(), false); + + auto *paramIdent = checker->AllocNode(it->Name(), allocator); + auto *param = checker->AllocNode(paramIdent, nullptr); + auto [_, var] = checker->VarBinder()->AddParamDecl(param); + (void)_; + var->SetTsType(ifaceOverride ? checker->GlobalETSObjectType() : it->TsType()); + paramIdent->SetVariable(var); + invokeFunc->Params().push_back(param); + invokeSignatureInfo->minArgCount++; + invokeSignatureInfo->params.push_back(var->AsLocalVariable()); + } + } else { auto paramCtx = varbinder::LexicalScope::Enter( - VarBinder(), invokeFunc->Scope()->ParamScope(), false); + checker->VarBinder(), invokeFunc->Scope()->ParamScope(), false); - auto *paramIdent = Allocator()->New(it->Name(), Allocator()); - auto *param = Allocator()->New(paramIdent, nullptr); - auto [_, var] = VarBinder()->AddParamDecl(param); + auto *id = checker->AllocNode("p", allocator); + auto *restElement = checker->AllocNode(ir::AstNodeType::REST_ELEMENT, allocator, id); + auto *const param = checker->AllocNode(restElement, nullptr); + auto [_, var] = checker->VarBinder()->AddParamDecl(param); (void)_; - var->SetTsType(it->TsType()); - paramIdent->SetVariable(var); + var->SetTsType(checker->CreateETSArrayType(checker->GlobalETSObjectType())); + param->Ident()->SetVariable(var); invokeFunc->Params().push_back(param); - invokeSignatureInfo->minArgCount++; - invokeSignatureInfo->params.push_back(var->AsLocalVariable()); + invokeSignatureInfo->restVar = var->AsLocalVariable(); } // Create the function type for the constructor - auto *invokeSignature = CreateSignature(invokeSignatureInfo, signatureRef->ReturnType(), invokeFunc); + auto *invokeSignature = checker->CreateSignature( + invokeSignatureInfo, ifaceOverride ? checker->GlobalETSObjectType() : signatureRef->ReturnType(), invokeFunc); invokeSignature->SetOwner(lambdaObjectType); invokeSignature->AddSignatureFlag(checker::SignatureFlags::CALL); + return invokeSignature; +} + +void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, Signature *signatureRef, + bool ifaceOverride) +{ + const auto &lambdaBody = lambdaObject->Body(); + auto *invokeFunc = lambdaBody[lambdaBody.size() - (ifaceOverride ? 2 : 1)]->AsMethodDefinition()->Function(); + ETSObjectType *lambdaObjectType = lambdaObject->TsType()->AsETSObjectType(); + + // Set the implicit 'this' parameters type to the lambda object + auto *thisVar = invokeFunc->Scope()->ParamScope()->Params().front(); + thisVar->SetTsType(lambdaObjectType); + + auto *invokeSignature = CreateInvokeSignature(this, signatureRef, invokeFunc, lambdaObjectType, ifaceOverride); + auto *invokeType = CreateETSFunctionType(invokeSignature); invokeFunc->SetSignature(invokeSignature); invokeFunc->Id()->Variable()->SetTsType(invokeType); @@ -2533,16 +2673,92 @@ void ETSChecker::ResolveLambdaObjectInvoke(ir::ClassDefinition *lambdaObject, Si invokeFunc->Id()->Variable()->AsLocalVariable()); // Fill out the type information for the body of the invoke function - - auto *resolvedLambdaInvokeFunctionBody = ResolveLambdaObjectInvokeFuncBody(lambdaObject, signatureRef); - + auto *resolvedLambdaInvokeFunctionBody = + ResolveLambdaObjectInvokeFuncBody(lambdaObject, signatureRef, ifaceOverride); + resolvedLambdaInvokeFunctionBody->SetParent(invokeFunc->Body()); invokeFunc->Body()->AsBlockStatement()->Statements().push_back(resolvedLambdaInvokeFunctionBody); + if (resolvedLambdaInvokeFunctionBody->IsExpressionStatement()) { - invokeFunc->Body()->AsBlockStatement()->Statements().push_back(Allocator()->New(nullptr)); + auto *const returnStatement = Allocator()->New(nullptr); + returnStatement->SetParent(invokeFunc->Body()); + invokeFunc->Body()->AsBlockStatement()->Statements().push_back(returnStatement); + } +} + +static ir::Expression *BuildParamExpression(ETSChecker *checker, ir::Identifier *paramIdent, Type *type) +{ + if (type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + auto *boxedType = checker->PrimitiveTypeAsETSBuiltinType(type); + auto *boxedTypeNode = checker->AllocNode(boxedType); + boxedTypeNode->SetTsType(boxedType); + auto *paramAsExpr = checker->AllocNode(paramIdent, boxedTypeNode, false); + paramAsExpr->SetTsType(boxedType); + paramAsExpr->AddBoxingUnboxingFlags(checker->GetUnboxingFlag(type)); + return paramAsExpr; + } + checker::CastingContext ctx(checker->Relation(), paramIdent, paramIdent->TsType(), type, paramIdent->Start(), {}); + auto *const paramCast = checker->Allocator()->New(paramIdent, nullptr, false); + paramCast->SetUncheckedCast(ctx.UncheckedCast()); + paramCast->SetTsType(type); + return paramCast; +} + +static ArenaVector ResolveCallParametersForLambdaFuncBody(ETSChecker *checker, + Signature *signatureRef, + ir::ScriptFunction *invokeFunc, + bool ifaceOverride) +{ + auto *allocator = checker->Allocator(); + ArenaVector callParams(allocator->Adapter()); + + auto maxParamsNum = checker->GlobalBuiltinFunctionTypeVariadicThreshold(); + auto paramsNum = signatureRef->Params().size(); + if (!ifaceOverride) { + for (size_t idx = 0; idx != paramsNum; idx++) { + auto *paramIdent = allocator->New(signatureRef->Params()[idx]->Name(), allocator); + paramIdent->SetVariable(invokeFunc->Params()[idx]->AsETSParameterExpression()->Variable()); + paramIdent->SetTsType(invokeFunc->Params()[idx]->AsETSParameterExpression()->Variable()->TsType()); + callParams.push_back(paramIdent); + } + } else if (paramsNum < maxParamsNum) { + // Then we add the lambda functions parameters to the call + auto nargs = invokeFunc->Params().size(); + for (size_t i = 0; i < nargs; i++) { + auto const *const param = invokeFunc->Params()[i]->AsETSParameterExpression(); + auto *const paramIdent = allocator->New(param->Ident()->Name(), allocator); + paramIdent->SetVariable(param->Variable()); + paramIdent->SetTsType(param->Variable()->TsType()); + callParams.push_back(BuildParamExpression(checker, paramIdent, signatureRef->Params()[i]->TsType())); + } + } else { + ASSERT(invokeFunc->Params().size() == 1); + auto const *const param = invokeFunc->Params()[0]->AsETSParameterExpression(); + auto *const paramIdent = allocator->New(param->Ident()->Name(), allocator); + paramIdent->SetVariable(param->Variable()); + paramIdent->SetTsType(param->Variable()->TsType()); + + for (size_t i = 0; i < paramsNum; i++) { + auto *idx = allocator->New(lexer::Number(static_cast(i))); + auto *arg = allocator->New(paramIdent, idx, ir::MemberExpressionKind::ELEMENT_ACCESS, + true, false); + + auto *type = signatureRef->Params()[i]->TsType(); + if (type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + arg->AddBoxingUnboxingFlags(checker->GetUnboxingFlag(type)); + callParams.push_back(arg); + } else { + auto *const paramCast = allocator->New(arg, nullptr, false); + paramCast->SetTsType(type); + callParams.push_back(paramCast); + } + } } + + return callParams; } -ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaObject, Signature *signatureRef) +ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition *lambdaObject, Signature *signatureRef, + bool ifaceOverride) { const auto &lambdaBody = lambdaObject->Body(); bool isStaticReference = signatureRef->HasSignatureFlag(SignatureFlags::STATIC); @@ -2551,7 +2767,7 @@ ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition // If this is a static function reference, we have to call the referenced function through the class itself if (isStaticReference) { - fieldIdent = Allocator()->New(signatureRef->Owner()->Name(), Allocator()); + fieldIdent = AllocNode(signatureRef->Owner()->Name(), Allocator()); fieldPropType = signatureRef->Owner(); fieldIdent->SetVariable(signatureRef->Owner()->Variable()); fieldIdent->SetTsType(fieldPropType); @@ -2560,39 +2776,38 @@ ir::Statement *ETSChecker::ResolveLambdaObjectInvokeFuncBody(ir::ClassDefinition // reference auto *fieldProp = lambdaBody[0]->AsClassProperty()->Key()->AsIdentifier()->Variable(); fieldPropType = fieldProp->TsType()->AsETSObjectType(); - fieldIdent = Allocator()->New("field0", Allocator()); + fieldIdent = AllocNode("field0", Allocator()); fieldIdent->SetVariable(fieldProp); fieldIdent->SetTsType(fieldPropType); } // Set the type information for the function reference call - auto *funcIdent = Allocator()->New(signatureRef->Function()->Id()->Name(), Allocator()); - auto *callee = Allocator()->New(fieldIdent, funcIdent, - ir::MemberExpressionKind::ELEMENT_ACCESS, false, false); + auto *funcIdent = AllocNode(signatureRef->Function()->Id()->Name(), Allocator()); + auto *callee = + AllocNode(fieldIdent, funcIdent, ir::MemberExpressionKind::ELEMENT_ACCESS, false, false); callee->SetPropVar(signatureRef->OwnerVar()->AsLocalVariable()); callee->SetObjectType(fieldPropType); callee->SetTsType(signatureRef->OwnerVar()->TsType()); // Create the parameters for the referenced function call - auto *invokeFunc = lambdaBody[lambdaBody.size() - 1]->AsMethodDefinition()->Function(); - ArenaVector callParams(Allocator()->Adapter()); - for (size_t idx = 0; idx != signatureRef->Params().size(); idx++) { - auto *paramIdent = Allocator()->New(signatureRef->Params()[idx]->Name(), Allocator()); - paramIdent->SetVariable(invokeFunc->Params()[idx]->AsETSParameterExpression()->Variable()); - paramIdent->SetTsType(invokeFunc->Params()[idx]->AsETSParameterExpression()->Variable()->TsType()); - callParams.push_back(paramIdent); - } + auto *invokeFunc = lambdaBody[lambdaBody.size() - (ifaceOverride ? 2 : 1)]->AsMethodDefinition()->Function(); + ArenaVector callParams = + ResolveCallParametersForLambdaFuncBody(this, signatureRef, invokeFunc, ifaceOverride); // Create the synthetic call expression to the referenced function - auto *resolvedCall = Allocator()->New(callee, std::move(callParams), nullptr, false); + auto *resolvedCall = AllocNode(callee, std::move(callParams), nullptr, false); resolvedCall->SetTsType(signatureRef->ReturnType()); resolvedCall->SetSignature(signatureRef); if (signatureRef->ReturnType()->IsETSVoidType()) { - return Allocator()->New(resolvedCall); + return AllocNode(resolvedCall); } - return Allocator()->New(resolvedCall); + if (ifaceOverride && resolvedCall->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + resolvedCall->AddBoxingUnboxingFlags(GetBoxingFlag(resolvedCall->TsType())); + } + + return AllocNode(resolvedCall); } bool ETSChecker::AreOverrideEquivalent(Signature *const s1, Signature *const s2) @@ -2620,7 +2835,7 @@ bool ETSChecker::IsReturnTypeSubstitutable(Signature *const s1, Signature *const // - If R1 is a reference type then R1, adapted to the type parameters of d2 (link to generic methods), is a // subtype of R2. - ASSERT(r1->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT) || r1->IsETSTypeParameter()); + ASSERT(IsReferenceType(r1)); return Relation()->IsSupertypeOf(r2, r1); } @@ -2660,17 +2875,17 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as varbinder::FunctionParamScope *paramScope = CopyParams(asyncFunc->Params(), params); // Set impl method return type "Object" because it may return Promise as well as Promise parameter's type - auto *objectId = Allocator()->New(compiler::Signatures::BUILTIN_OBJECT_CLASS, Allocator()); + auto *objectId = AllocNode(compiler::Signatures::BUILTIN_OBJECT_CLASS, Allocator()); objectId->SetReference(); VarBinder()->AsETSBinder()->LookupTypeReference(objectId, false); auto *returnTypeAnn = - Allocator()->New(Allocator()->New(objectId, nullptr, nullptr)); + AllocNode(AllocNode(objectId, nullptr, nullptr)); objectId->SetParent(returnTypeAnn->Part()); returnTypeAnn->Part()->SetParent(returnTypeAnn); auto *asyncFuncRetTypeAnn = asyncFunc->ReturnTypeAnnotation(); auto *promiseType = [this](ir::TypeNode *type) { if (type != nullptr) { - return GetTypeFromTypeAnnotation(type)->AsETSObjectType(); + return type->GetType(this)->AsETSObjectType(); } return GlobalBuiltinPromiseType()->AsETSObjectType(); @@ -2684,8 +2899,6 @@ ir::MethodDefinition *ETSChecker::CreateAsyncImplMethod(ir::MethodDefinition *as asyncFunc->SetBody(nullptr); returnTypeAnn->SetParent(implMethod->Function()); implMethod->SetParent(asyncMethod->Parent()); - std::for_each(implMethod->Function()->Params().begin(), implMethod->Function()->Params().end(), - [implMethod](ir::Expression *param) { param->SetParent(implMethod->Function()); }); return implMethod; } @@ -2733,28 +2946,24 @@ ir::MethodDefinition *ETSChecker::CreateMethod(const util::StringView &name, ir: varbinder::FunctionParamScope *paramScope, ir::TypeNode *returnType, ir::AstNode *body) { - auto *nameId = Allocator()->New(name, Allocator()); + auto *nameId = AllocNode(name, Allocator()); auto *scope = VarBinder()->Allocator()->New(Allocator(), paramScope); - ir::ScriptFunction *func = - Allocator()->New(ir::FunctionSignature(nullptr, std::move(params), returnType), body, flags, - modifiers, false, Language(Language::Id::ETS)); + auto *const func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), returnType), + body, ir::ScriptFunction::ScriptFunctionData {flags, modifiers}); func->SetScope(scope); func->SetIdent(nameId); - body->SetParent(func); - if (body->IsBlockStatement()) { + if (body != nullptr && body->IsBlockStatement()) { body->AsBlockStatement()->SetScope(scope); } scope->BindNode(func); paramScope->BindNode(func); scope->BindParamScope(paramScope); paramScope->BindFunctionScope(scope); - auto *funcExpr = Allocator()->New(func); - auto *method = Allocator()->New(ir::MethodDefinitionKind::METHOD, nameId, funcExpr, modifiers, - Allocator(), false); - funcExpr->SetParent(method); - func->SetParent(funcExpr); - nameId->SetParent(method); + auto *funcExpr = AllocNode(func); + auto *nameClone = nameId->Clone(Allocator(), nullptr); + auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, nameClone, funcExpr, modifiers, + Allocator(), false); return method; } @@ -2782,6 +2991,10 @@ varbinder::FunctionParamScope *ETSChecker::CopyParams(const ArenaVectorIterate([this, oldNode, newScope](ir::AstNode *child) { auto *scope = NodeScope(child); if (scope != nullptr) { @@ -2842,7 +3055,7 @@ void ETSChecker::TransformTraillingLambda(ir::CallExpression *callExpr) ArenaVector params(Allocator()->Adapter()); auto *funcNode = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), trailingBlock, - ir::ScriptFunctionFlags::ARROW, false, Language(Language::Id::ETS)); + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::ARROW}); funcNode->SetScope(funcScope); funcScope->BindNode(funcNode); funcParamScope->BindNode(funcNode); @@ -2868,8 +3081,9 @@ ArenaVector ETSChecker::ExtendArgumentsWithFakeLamda(ir::CallE auto *body = AllocNode(Allocator(), std::move(statements)); body->SetScope(funcScope); - auto *funcNode = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::ARROW, false, Language(Language::Id::ETS)); + auto *funcNode = + AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::ARROW}); funcNode->SetScope(funcScope); funcScope->BindNode(funcNode); auto *arrowFuncNode = AllocNode(Allocator(), funcNode); @@ -2893,4 +3107,22 @@ void ETSChecker::EnsureValidCurlyBrace(ir::CallExpression *callExpr) ThrowTypeError({"No matching call signature with trailing lambda"}, callExpr->Start()); } + +ETSObjectType *ETSChecker::GetCachedFunctionlInterface(ir::ETSFunctionType *type) +{ + auto hash = GetHashFromFunctionType(type); + auto it = functionalInterfaceCache_.find(hash); + if (it == functionalInterfaceCache_.cend()) { + return nullptr; + } + return it->second; +} + +void ETSChecker::CacheFunctionalInterface(ir::ETSFunctionType *type, ETSObjectType *ifaceType) +{ + auto hash = GetHashFromFunctionType(type); + ASSERT(functionalInterfaceCache_.find(hash) == functionalInterfaceCache_.cend()); + functionalInterfaceCache_.emplace(hash, ifaceType); +} + } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ets/function_helpers.h b/ets2panda/checker/ets/function_helpers.h index 2fa371318630e76ce3d4e8517f1553beae6ce3a5..12a6c290f62dddb5ef6314e2c7c02b9931854b6b 100644 --- a/ets2panda/checker/ets/function_helpers.h +++ b/ets2panda/checker/ets/function_helpers.h @@ -86,22 +86,20 @@ static const Substitution *BuildImplicitSubstitutionForArguments(ETSChecker *che const ArenaVector &arguments) { Substitution *substitution = checker->NewSubstitution(); - auto *instantiatedTypeParams = checker->NewInstantiatedTypeParamsSet(); auto *sigInfo = signature->GetSignatureInfo(); - auto &typeParams = sigInfo->typeParams; for (size_t ix = 0; ix < arguments.size(); ix++) { auto *arg = arguments[ix]; if (arg->IsObjectExpression()) { continue; } - auto *argType = arg->Check(checker); - argType = MaybeBoxedType(checker, argType, arg); - auto *paramType = (ix < signature->MinArgCount()) ? sigInfo->params[ix]->TsType() : sigInfo->restVar->TsType(); + auto *argType = MaybeBoxedType(checker, arg->Check(checker), arg); + auto *paramType = (ix < signature->MinArgCount()) ? sigInfo->params[ix]->TsType() + : sigInfo->restVar != nullptr ? sigInfo->restVar->TsType() + : nullptr; if (paramType == nullptr) { continue; } - if (!checker->EnhanceSubstitutionForType(typeParams, paramType, argType, substitution, - instantiatedTypeParams)) { + if (!checker->EnhanceSubstitutionForType(sigInfo->typeParams, paramType, argType, substitution)) { return nullptr; } } @@ -161,7 +159,10 @@ static Signature *MaybeSubstituteTypeParameters(ETSChecker *checker, Signature * const Substitution *substitution = (typeArguments != nullptr) ? BuildExplicitSubstitutionForArguments(checker, signature, typeArguments->Params(), pos, flags) - : BuildImplicitSubstitutionForArguments(checker, signature, arguments); + : (signature->GetSignatureInfo()->params.empty() + ? nullptr + : BuildImplicitSubstitutionForArguments(checker, signature, arguments)); + return (substitution == nullptr) ? nullptr : signature->Substitute(checker->Relation(), substitution); } @@ -260,4 +261,4 @@ static varbinder::Scope *NodeScope(ir::AstNode *ast) } // namespace panda::es2panda::checker -#endif \ No newline at end of file +#endif diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 41e52fafab41dfa69f6e896b7839b31b51e0f803..016b897f3bbff96079e04450069fb9b8f46ef5e6 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -89,123 +89,115 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) ThrowTypeError("Condition must be of possible condition type", expr->Start()); } - if (unboxedType != nullptr && unboxedType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { + if (unboxedType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { FlagExpressionWithUnboxing(type, unboxedType, expr); } expr->SetTsType(unboxedType); } -// NOTE: vpukhov. this entire function is isolated work-around until nullish type are not unions -Type *ETSChecker::CreateNullishType(Type *type, checker::TypeFlag nullishFlags, ArenaAllocator *allocator, - TypeRelation *relation, GlobalTypesHolder *globalTypes) +void ETSChecker::CheckNonNullish(ir::Expression const *expr) { - ASSERT((nullishFlags & ~TypeFlag::NULLISH) == 0); - - auto *const nullish = type->Instantiate(allocator, relation, globalTypes); - - // Doesnt work for primitive array types, because instantiated type is equal to original one - - if ((nullishFlags & TypeFlag::NULL_TYPE) != 0) { - nullish->AddTypeFlag(checker::TypeFlag::NULL_TYPE); - } - if ((nullishFlags & 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 lineInfo) -{ - // 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 - } - if (type->IsETSTypeParameter()) { - return type->AsETSTypeParameter()->GetOriginal(); - } - - while (type->IsNullish()) { - type = type->AsETSObjectType()->GetBaseType(); - ASSERT(type != nullptr); + if (expr->TsType()->PossiblyETSNullish()) { + ThrowTypeError("Value is possibly nullish.", expr->Start()); } - return type; } -// NOTE: vpukhov. rewrite with union types -const Type *ETSChecker::GetNonNullishType(const Type *type) const +Type *ETSChecker::GetNonNullishType(Type *type) { - if (type->IsETSArrayType()) { - return type; // give up + if (type->DefinitelyNotETSNullish()) { + return type; } if (type->IsETSTypeParameter()) { - return type->AsETSTypeParameter()->GetOriginal(); - } - - while (type->IsNullish()) { - type = type->AsETSObjectType()->GetBaseType(); - ASSERT(type != nullptr); + return Allocator()->New(type->AsETSTypeParameter()); } - return type; -} - -Type *ETSChecker::CreateOptionalResultType(Type *type) -{ - if (type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - type = PrimitiveTypeAsETSBuiltinType(type); - ASSERT(type->IsETSObjectType()); - Relation()->GetNode()->AddBoxingUnboxingFlags(GetBoxingFlag(type)); + ArenaVector copied(Allocator()->Adapter()); + for (auto const &t : type->AsETSUnionType()->ConstituentTypes()) { + if (t->IsETSNullType() || t->IsETSUndefinedType()) { + continue; + } + copied.push_back(GetNonNullishType(t)); } - - return CreateNullishType(type, checker::TypeFlag::UNDEFINED, Allocator(), Relation(), GetGlobalTypesHolder()); + return copied.empty() ? GetGlobalTypesHolder()->GlobalBuiltinNeverType() : CreateETSUnionType(std::move(copied)); } -// NOTE(vpukhov): #14595 could be implemented with relation -template -static bool MatchConstitutentOrConstraint(P const &pred, const Type *type) +// NOTE(vpukhov): can be implemented with relation if etscompiler will support it +template +static bool MatchConstituentOrConstraint(P const &pred, const Type *type) { + auto const traverse = [](P const &p, const Type *t) { + return MatchConstituentOrConstraint(p, t); + }; if (pred(type)) { return true; } if (type->IsETSUnionType()) { for (auto const &ctype : type->AsETSUnionType()->ConstituentTypes()) { - if (MatchConstitutentOrConstraint(pred, ctype)) { + if (traverse(pred, ctype)) { return true; } } return false; } if (type->IsETSTypeParameter()) { - return MatchConstitutentOrConstraint(pred, type->AsETSTypeParameter()->GetConstraintType()); + return traverse(pred, type->AsETSTypeParameter()->GetConstraintType()); + } + if constexpr (VISIT_NONNULLISH) { + if (type->IsETSNonNullishType()) { + auto tparam = type->AsETSNonNullishType()->GetUnderlying(); + return traverse(pred, tparam->GetConstraintType()); + } } return false; } -bool ETSChecker::MayHaveNullValue(const Type *type) const +bool Type::PossiblyETSNull() const +{ + const auto pred = [](const Type *t) { return t->IsETSNullType(); }; + return MatchConstituentOrConstraint(pred, this); +} + +bool Type::PossiblyETSUndefined() const +{ + const auto pred = [](const Type *t) { return t->IsETSUndefinedType(); }; + return MatchConstituentOrConstraint(pred, this); +} + +bool Type::PossiblyETSNullish() const +{ + const auto pred = [](const Type *t) { return t->IsETSNullType() || t->IsETSUndefinedType(); }; + return MatchConstituentOrConstraint(pred, this); +} + +bool Type::DefinitelyETSNullish() const +{ + const auto pred = [](const Type *t) { + return !(t->IsTypeParameter() || t->IsETSUnionType() || t->IsETSNullType() || t->IsETSUndefinedType()); + }; + return !MatchConstituentOrConstraint(pred, this); +} + +bool Type::DefinitelyNotETSNullish() const +{ + return !PossiblyETSNullish(); +} + +bool Type::PossiblyETSString() const { - const auto pred = [](const Type *t) { return t->ContainsNull() || t->IsETSNullType(); }; - return MatchConstitutentOrConstraint(pred, type); + const auto pred = [](const Type *t) { + return t->IsETSStringType() || (t->IsETSObjectType() && t->AsETSObjectType()->IsGlobalETSObjectType()); + }; + return MatchConstituentOrConstraint(pred, this); } -bool ETSChecker::MayHaveUndefinedValue(const Type *type) const +bool Type::IsETSReferenceType() const { - const auto pred = [](const Type *t) { return t->ContainsUndefined() || t->IsETSUndefinedType(); }; - return MatchConstitutentOrConstraint(pred, type); + return HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || IsETSNullType() || IsETSUndefinedType() || + IsETSStringType() || IsETSTypeParameter() || IsETSUnionType() || IsETSNonNullishType() || IsETSBigIntType(); } -bool ETSChecker::MayHaveNulllikeValue(const Type *type) const +bool Type::IsETSUnboxableObject() const { - const auto pred = [](const Type *t) { return t->IsNullishOrNullLike(); }; - return MatchConstitutentOrConstraint(pred, type); + return IsETSObjectType() && AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE); } bool ETSChecker::IsConstantExpression(ir::Expression *expr, Type *type) @@ -216,8 +208,6 @@ 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(); } @@ -225,9 +215,6 @@ 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(); } @@ -357,12 +344,13 @@ Type *ETSChecker::GetTypeOfVariable(varbinder::Variable *const var) // Determine if unchecked cast is needed and yield guaranteed source type Type *ETSChecker::GuaranteedTypeForUncheckedCast(Type *base, Type *substituted) { - if (!base->IsETSTypeParameter()) { - return nullptr; - } - auto *constr = base->AsETSTypeParameter()->GetConstraintType(); - // Constraint is supertype of TypeArg AND TypeArg is supertype of Constraint - return Relation()->IsIdenticalTo(substituted, constr) ? nullptr : constr; + // Apparent type acts as effective representation for type. + // For T extends SomeClass|undefined + // Apparent(Int|T|null) is Int|SomeClass|undefined|null + auto *appBase = GetApparentType(base); + auto *appSubst = GetApparentType(substituted); + // Base is supertype of Substituted AND Substituted is supertype of Base + return Relation()->IsIdenticalTo(appSubst, appBase) ? nullptr : appBase; } // Determine if substituted property access requires cast from erased type @@ -511,12 +499,17 @@ void ETSChecker::NotResolvedError(ir::Identifier *const ident) void ETSChecker::ValidateCallExpressionIdentifier(ir::Identifier *const ident, Type *const type) { - if (ident->Parent()->AsCallExpression()->Callee() == ident && !type->IsETSFunctionType() && - !type->IsETSDynamicType() && - (!type->IsETSObjectType() || !type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) && - !TryTransformingToStaticInvoke(ident, type)) { - ThrowError(ident); + if (ident->Parent()->AsCallExpression()->Callee() != ident) { + return; + } + if (type->IsETSFunctionType() || type->IsETSDynamicType() || + (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { + return; + } + if (TryTransformingToStaticInvoke(ident, type)) { + return; } + ThrowTypeError({"This expression is not callable."}, ident->Start()); } void ETSChecker::ValidateNewClassInstanceIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved) @@ -604,7 +597,7 @@ bool ETSChecker::ValidateBinaryExpressionIdentifier(ir::Identifier *const ident, const auto *const binaryExpr = ident->Parent()->AsBinaryExpression(); bool isFinished = false; if (binaryExpr->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF && binaryExpr->Right() == ident) { - if (!type->IsETSObjectType()) { + if (!IsReferenceType(type)) { ThrowError(ident); } isFinished = true; @@ -618,7 +611,7 @@ void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbind NotResolvedError(ident); } - auto *const resolvedType = ETSChecker::GetApparentType(GetTypeOfVariable(resolved)); + auto *const resolvedType = GetApparentType(GetTypeOfVariable(resolved)); switch (ident->Parent()->Type()) { case ir::AstNodeType::CALL_EXPRESSION: { @@ -877,7 +870,7 @@ Type *ETSChecker::ApplyUnaryOperatorPromotion(Type *type, const bool createConst bool ETSChecker::IsNullLikeOrVoidExpression(const ir::Expression *expr) const { - return expr->TsType()->IsETSNullLike() || expr->TsType()->IsETSVoidType(); + return expr->TsType()->DefinitelyETSNullish() || expr->TsType()->IsETSVoidType(); } std::tuple ETSChecker::IsResolvedAndValue(const ir::Expression *expr, Type *type) const @@ -886,7 +879,7 @@ std::tuple ETSChecker::IsResolvedAndValue(const ir::Expression *expr IsNullLikeOrVoidExpression(expr) ? std::make_tuple(true, false) : type->ResolveConditionExpr(); const Type *tsType = expr->TsType(); - if (!tsType->ContainsUndefined() && !tsType->ContainsNull() && !tsType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { + if (tsType->DefinitelyNotETSNullish() && !type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { isResolve = true; isValue = true; } @@ -904,10 +897,7 @@ Type *ETSChecker::HandleBooleanLogicalOperatorsExtended(Type *leftType, Type *ri if (IsTypeIdenticalTo(leftType, rightType)) { return leftType; } - ArenaVector types(Allocator()->Adapter()); - types.push_back(leftType); - types.push_back(rightType); - return CreateETSUnionType(std::move(types)); + return CreateETSUnionType({leftType, rightType}); } switch (expr->OperatorType()) { @@ -996,8 +986,7 @@ void ETSChecker::ResolveReturnStatement(checker::Type *funcReturnType, checker:: ThrowTypeError("Invalid return function expression", st->Start()); } } - - funcReturnType = FindLeastUpperBound(funcReturnType, argumentType); + funcReturnType = CreateETSUnionType({funcReturnType, argumentType}); containingFunc->Signature()->SetReturnType(funcReturnType); containingFunc->Signature()->AddSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE); } else if (funcReturnType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE_RETURN) && @@ -1061,7 +1050,7 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T const bool isConst = (flags & ir::ModifierFlags::CONST) != 0; if (typeAnnotation != nullptr) { - annotationType = GetTypeFromTypeAnnotation(typeAnnotation); + annotationType = typeAnnotation->GetType(this); bindingVar->SetTsType(annotationType); } @@ -1123,11 +1112,11 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T if (init->IsArrowFunctionExpression()) { typeAnnotation = init->AsArrowFunctionExpression()->CreateTypeAnnotation(this); } else { - typeAnnotation = init->AsTSAsExpression()->TypeAnnotation(); + typeAnnotation = init->AsTSAsExpression()->TypeAnnotation()->Clone(Allocator(), nullptr); } ident->SetTsTypeAnnotation(typeAnnotation); typeAnnotation->SetParent(ident); - annotationType = GetTypeFromTypeAnnotation(typeAnnotation); + annotationType = typeAnnotation->GetType(this); bindingVar->SetTsType(annotationType); } @@ -1144,27 +1133,13 @@ checker::Type *ETSChecker::CheckVariableDeclaration(ir::Identifier *ident, ir::T return bindingVar->TsType(); } - if (initType->IsETSNullLike()) { - TypeFlag nullishFlags {0}; - - if (initType->IsETSNullType()) { - nullishFlags = TypeFlag::NULL_TYPE; - } - if (initType->IsETSUndefinedType()) { - nullishFlags = TypeFlag::UNDEFINED; - } - initType = CreateNullishType(GetGlobalTypesHolder()->GlobalETSObjectType(), nullishFlags, Allocator(), - Relation(), GetGlobalTypesHolder()); - } - if (initType->IsETSObjectType() && initType->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::ENUM) && !init->IsMemberExpression()) { ThrowTypeError({"Cannot assign type '", initType->AsETSObjectType()->Name(), "' for variable ", varName, "."}, init->Start()); } - (initType->IsNullish() || isConst) ? bindingVar->SetTsType(initType) - : bindingVar->SetTsType(GetNonConstantTypeFromPrimitiveType(initType)); + isConst ? bindingVar->SetTsType(initType) : bindingVar->SetTsType(GetNonConstantTypeFromPrimitiveType(initType)); return bindingVar->TsType(); } @@ -1208,7 +1183,7 @@ Type *ETSChecker::GetTypeFromTypeAliasReference(varbinder::Variable *var) auto *const aliasTypeNode = var->Declaration()->Node()->AsTSTypeAliasDeclaration(); TypeStackElement tse(this, aliasTypeNode, "Circular type alias reference", aliasTypeNode->Start()); aliasTypeNode->Check(this); - auto *const aliasedType = GetTypeFromTypeAnnotation(aliasTypeNode->TypeAnnotation()); + auto *const aliasedType = aliasTypeNode->TypeAnnotation()->GetType(this); var->SetTsType(aliasedType); return aliasedType; @@ -1672,12 +1647,6 @@ bool ETSChecker::IsTypeBuiltinType(const Type *type) const } } -bool ETSChecker::IsReferenceType(const Type *type) -{ - return type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || type->IsETSNullLike() || - type->IsETSStringType() || type->IsETSTypeParameter() || type->IsETSUnionType() || type->IsETSBigIntType(); -} - const ir::AstNode *ETSChecker::FindJumpTarget(ir::AstNodeType nodeType, const ir::AstNode *node, const ir::Identifier *target) { @@ -1780,6 +1749,10 @@ Type *ETSChecker::ETSBuiltinTypeAsConditionalType(Type *objectType) return nullptr; } + if (auto *unboxed = ETSBuiltinTypeAsPrimitiveType(objectType); unboxed != nullptr) { + return unboxed; + } + return objectType; } @@ -1819,6 +1792,30 @@ void ETSChecker::AddBoxingUnboxingFlagsToNode(ir::AstNode *node, Type *boxingUnb } } +Type *ETSChecker::MaybePromotedBuiltinType(Type *type) const +{ + return type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) ? checker::BoxingConverter::ETSTypeFromSource(this, type) : type; +} + +Type const *ETSChecker::MaybePromotedBuiltinType(Type const *type) const +{ + return type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) ? checker::BoxingConverter::ETSTypeFromSource(this, type) : type; +} + +Type *ETSChecker::MaybePrimitiveBuiltinType(Type *type) const +{ + return type->IsETSObjectType() ? UnboxingConverter::GlobalTypeFromSource(this, type->AsETSObjectType()) : type; +} + +Type *ETSChecker::MaybeBoxExpression(ir::Expression *expr) +{ + auto *promoted = MaybePromotedBuiltinType(expr->TsType()); + if (promoted != expr->TsType()) { + expr->AddBoxingUnboxingFlags(GetBoxingFlag(promoted)); + } + return promoted; +} + ir::BoxingUnboxingFlags ETSChecker::GetBoxingFlag(Type *const boxingType) { auto typeKind = TypeKind(ETSBuiltinTypeAsPrimitiveType(boxingType)); @@ -2294,38 +2291,6 @@ ETSObjectType *ETSChecker::GetRelevantArgumentedTypeFromChild(ETSObjectType *con return GetRelevantArgumentedTypeFromChild(child->SuperType(), target); } -static void TypeToString(std::stringstream &ss, Type *tp) -{ - if (tp->IsETSTypeParameter()) { - ss << tp->AsETSTypeParameter()->GetDeclNode()->Start().index; - ss << "."; - } - if (!tp->IsETSObjectType()) { - tp->ToString(ss); - return; - } - auto *const objType = tp->AsETSObjectType(); - ss << objType->Name(); - - if (!objType->TypeArguments().empty()) { - auto typeArgs = objType->TypeArguments(); - ss << "<"; - for (auto *ta : typeArgs) { - TypeToString(ss, ta); - ss << ";"; - } - ss << ">"; - } - - if (tp->ContainsNull()) { - ss << "|null"; - } - - if (tp->ContainsUndefined()) { - ss << "|undefined"; - } -} - void ETSChecker::EmplaceSubstituted(Substitution *substitution, ETSTypeParameter *tparam, Type *typeArg) { substitution->emplace(tparam, typeArg); @@ -2336,7 +2301,7 @@ util::StringView ETSChecker::GetHashFromTypeArguments(const ArenaVector std::stringstream ss; for (auto *it : typeArgTypes) { - TypeToString(ss, it); + it->ToString(ss, true); ss << compiler::Signatures::MANGLE_SEPARATOR; } @@ -2348,9 +2313,9 @@ util::StringView ETSChecker::GetHashFromSubstitution(const Substitution *substit std::vector fields; for (auto [k, v] : *substitution) { std::stringstream ss; - TypeToString(ss, k); + k->ToString(ss, true); ss << ":"; - TypeToString(ss, v); + v->ToString(ss, true); fields.push_back(ss.str()); } std::sort(fields.begin(), fields.end()); @@ -2363,39 +2328,36 @@ util::StringView ETSChecker::GetHashFromSubstitution(const Substitution *substit return util::UString(ss.str(), Allocator()).View(); } -ETSObjectType *ETSChecker::GetOriginalBaseType(Type *const object) +util::StringView ETSChecker::GetHashFromFunctionType(ir::ETSFunctionType *type) { - if (object == nullptr || !object->IsETSObjectType()) { - return nullptr; + std::stringstream ss; + for (auto *p : type->Params()) { + auto *const param = p->AsETSParameterExpression(); + param->TypeAnnotation()->GetType(this)->ToString(ss, true); + ss << ";"; } - return object->AsETSObjectType()->GetOriginalBaseType(); -} - -Type *ETSChecker::GetTypeFromTypeAnnotation(ir::TypeNode *const typeAnnotation) -{ - auto *type = typeAnnotation->GetType(this); + type->ReturnType()->GetType(this)->ToString(ss, true); + ss << ";"; - if (!typeAnnotation->IsNullAssignable() && !typeAnnotation->IsUndefinedAssignable()) { - return type; + if (type->IsThrowing()) { + ss << "throws;"; } - if (!IsReferenceType(type)) { - ThrowTypeError("Non reference types cannot be nullish.", typeAnnotation->Start()); + if (type->IsRethrowing()) { + ss << "rethrows;"; } - if (type->IsNullish()) { - return type; - } + return util::UString(ss.str(), Allocator()).View(); +} - TypeFlag nullishFlags {0}; - if (typeAnnotation->IsNullAssignable()) { - nullishFlags |= TypeFlag::NULL_TYPE; - } - if (typeAnnotation->IsUndefinedAssignable()) { - nullishFlags |= TypeFlag::UNDEFINED; +ETSObjectType *ETSChecker::GetOriginalBaseType(Type *const object) +{ + if (object == nullptr || !object->IsETSObjectType()) { + return nullptr; } - return CreateNullishType(type, nullishFlags, Allocator(), Relation(), GetGlobalTypesHolder()); + + return object->AsETSObjectType()->GetOriginalBaseType(); } void ETSChecker::CheckValidGenericTypeParameter(Type *const argType, const lexer::SourcePosition &pos) @@ -2419,6 +2381,10 @@ void ETSChecker::CheckNumberOfTypeArguments(ETSObjectType *const type, ir::TSTyp return; } + if (typeArgs == nullptr) { + return; + } + size_t minimumTypeArgs = std::count_if(typeParams.begin(), typeParams.end(), [](Type *param) { return param->AsETSTypeParameter()->GetDefaultType() == nullptr; }); @@ -2501,7 +2467,9 @@ void ETSChecker::InferTypesForLambda(ir::ScriptFunction *lambda, ir::ETSFunction const auto *const calleeParam = calleeType->Params()[i]->AsETSParameterExpression()->Ident(); auto *const lambdaParam = lambda->Params()[i]->AsETSParameterExpression()->Ident(); if (lambdaParam->TypeAnnotation() == nullptr) { - lambdaParam->SetTsTypeAnnotation(calleeParam->TypeAnnotation()); + auto *const typeAnnotation = calleeParam->TypeAnnotation()->Clone(Allocator(), lambdaParam); + lambdaParam->SetTsTypeAnnotation(typeAnnotation); + typeAnnotation->SetParent(lambdaParam); } } if (lambda->ReturnTypeAnnotation() == nullptr) { @@ -2556,7 +2524,7 @@ bool ETSChecker::TypeInference(Signature *signature, const ArenaVector &arguments, ETSChecker *checker) { @@ -2564,28 +2532,36 @@ void ETSChecker::AddUndefinedParamsForDefaultParams(const Signature *const signa return; } + // Just to avoid extra nested levels + auto const addDefaultLiteral = [&arguments, checker, parent](ir::TypeNode const *const typeAnnotation) -> void { + if (typeAnnotation->IsETSPrimitiveType()) { + if (typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType() == ir::PrimitiveType::BOOLEAN) { + arguments.push_back(checker->Allocator()->New(false)); + } else { + arguments.push_back(checker->Allocator()->New(lexer::Number(0))); + } + arguments.back()->SetParent(parent); + } else { + // A proxy-function is called, so default reference parameters + // are initialized with null instead of undefined + auto *const nullLiteral = checker->Allocator()->New(); + nullLiteral->SetTsType(checker->GlobalETSNullType()); + nullLiteral->SetParent(parent); + arguments.push_back(nullLiteral); + } + }; + uint32_t num = 0; - for (size_t i = arguments.size(); i != signature->Function()->Params().size() - 1; i++) { + for (size_t i = arguments.size(); i != signature->Function()->Params().size() - 1U; ++i) { if (auto const *const param = signature->Function()->Params()[i]->AsETSParameterExpression(); !param->IsRestParameter()) { - auto const *const typeAnn = param->Ident()->TypeAnnotation(); - if (typeAnn->IsETSPrimitiveType()) { - if (typeAnn->AsETSPrimitiveType()->GetPrimitiveType() == ir::PrimitiveType::BOOLEAN) { - arguments.push_back(checker->Allocator()->New(false)); - } else { - 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 nullLiteral = checker->Allocator()->New(); - nullLiteral->SetTsType(checker->GlobalETSNullType()); - arguments.push_back(nullLiteral); - } + addDefaultLiteral(param->Ident()->TypeAnnotation()); num |= (1U << (arguments.size() - 1)); } } + arguments.push_back(checker->Allocator()->New(lexer::Number(num))); + arguments.back()->SetParent(parent); } bool ETSChecker::ExtensionETSFunctionType(checker::Type *type) @@ -2638,35 +2614,35 @@ std::string GenerateImplicitInstantiateArg(varbinder::LocalVariable *instantiate return implicitInstantiateArgument; } -void ETSChecker::GenerateGetterSetterBody(ETSChecker *checker, ArenaVector &stmts, - ArenaVector ¶ms, ir::ClassProperty *const field, - varbinder::FunctionParamScope *paramScope, bool isSetter) +void ETSChecker::GenerateGetterSetterBody(ArenaVector &stmts, ArenaVector ¶ms, + ir::ClassProperty *const field, varbinder::FunctionParamScope *paramScope, + bool isSetter) { if (!isSetter) { - stmts.push_back(checker->Allocator()->New(field->Key())); + auto *clone = field->Key()->Clone(Allocator(), nullptr)->AsExpression(); + stmts.push_back(AllocNode(clone)); return; } - auto *paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); - paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator())); - paramIdent->TypeAnnotation()->SetParent(paramIdent); + auto *paramIdent = field->Key()->AsIdentifier()->Clone(Allocator(), nullptr); + auto *const typeAnnotation = field->TypeAnnotation()->Clone(Allocator(), paramIdent); + paramIdent->SetTsTypeAnnotation(typeAnnotation); - auto *paramExpression = checker->AllocNode(paramIdent, nullptr); + auto *paramExpression = AllocNode(paramIdent, nullptr); paramExpression->SetRange(paramIdent->Range()); - auto *const paramVar = std::get<2>(paramScope->AddParamDecl(checker->Allocator(), paramExpression)); - - paramIdent->SetVariable(paramVar); + auto *const paramVar = std::get<2>(paramScope->AddParamDecl(Allocator(), paramExpression)); paramExpression->SetVariable(paramVar); params.push_back(paramExpression); - auto *assignmentExpression = checker->AllocNode( - field->Key(), paramExpression, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *assignmentExpression = AllocNode( + field->Key()->Clone(Allocator(), nullptr)->AsExpression(), paramExpression->Clone(Allocator(), nullptr), + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); assignmentExpression->SetRange({field->Start(), field->End()}); - stmts.push_back(checker->AllocNode(assignmentExpression)); - stmts.push_back(checker->Allocator()->New(nullptr)); + stmts.push_back(AllocNode(assignmentExpression)); + stmts.push_back(Allocator()->New(nullptr)); } ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty *const field, @@ -2683,20 +2659,20 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty ArenaVector params(checker->Allocator()->Adapter()); ArenaVector stmts(checker->Allocator()->Adapter()); - checker->GenerateGetterSetterBody(checker, stmts, params, field, paramScope, isSetter); + checker->GenerateGetterSetterBody(stmts, params, field, paramScope, isSetter); auto *body = checker->AllocNode(checker->Allocator(), std::move(stmts)); auto funcFlags = isSetter ? ir::ScriptFunctionFlags::SETTER : ir::ScriptFunctionFlags::GETTER; - auto *const returnTypeAnn = isSetter ? nullptr : field->TypeAnnotation(); + auto *const returnTypeAnn = isSetter ? nullptr : field->TypeAnnotation()->Clone(checker->Allocator(), nullptr); auto *func = checker->AllocNode(ir::FunctionSignature(nullptr, std::move(params), returnTypeAnn), body, - funcFlags, flags, true, Language(Language::Id::ETS)); + ir::ScriptFunction::ScriptFunctionData {funcFlags, flags, true}); func->SetRange(field->Range()); func->SetScope(functionScope); body->SetScope(functionScope); - auto *methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); + auto *methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); auto *decl = checker->Allocator()->New( checker->Allocator(), field->Key()->AsIdentifier()->Name(), field->Key()->AsIdentifier()->Variable()->Declaration()->Node()); @@ -2713,7 +2689,7 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty method->Id()->SetMutator(); method->SetRange(field->Range()); - method->Function()->SetIdent(method->Id()); + method->Function()->SetIdent(method->Id()->Clone(checker->Allocator(), nullptr)); method->Function()->AddModifier(method->Modifiers()); method->SetVariable(var); @@ -2730,7 +2706,7 @@ ir::MethodDefinition *ETSChecker::GenerateDefaultGetterSetter(ir::ClassProperty const Type *ETSChecker::TryGettingFunctionTypeFromInvokeFunction(const Type *type) const { if (type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { - auto const propInvoke = type->AsETSObjectType()->GetProperty(util::StringView("invoke"), + auto const propInvoke = type->AsETSObjectType()->GetProperty(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME, PropertySearchFlags::SEARCH_INSTANCE_METHOD); ASSERT(propInvoke != nullptr); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 8c06deccbc40e0c84799fcc304c753c462a02968..3022240684c098b68910cd38c1acd807eb093024 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -285,9 +285,10 @@ void ETSChecker::CreateTypeForClassOrInterfaceTypeParameters(ETSObjectType *type : type->GetDeclNode()->AsTSInterfaceDeclaration()->TypeParams(); type->SetTypeArguments(CreateTypeForTypeParameters(typeParams)); type->AddObjectFlag(ETSObjectFlags::RESOLVED_TYPE_PARAMS); + type->AddObjectFlag(ETSObjectFlags::INCOMPLETE_INSTANTIATION); } -ETSObjectType *ETSChecker::BuildInterfaceProperties(ir::TSInterfaceDeclaration *interfaceDecl) +ETSObjectType *ETSChecker::BuildBasicInterfaceProperties(ir::TSInterfaceDeclaration *interfaceDecl) { auto *var = interfaceDecl->Id()->Variable(); ASSERT(var); @@ -309,6 +310,14 @@ ETSObjectType *ETSChecker::BuildInterfaceProperties(ir::TSInterfaceDeclaration * GetInterfacesOfInterface(interfaceType); + interfaceType->SetSuperType(GlobalETSObjectType()); + + return interfaceType; +} + +ETSObjectType *ETSChecker::BuildInterfaceProperties(ir::TSInterfaceDeclaration *interfaceDecl) +{ + auto *interfaceType = BuildBasicInterfaceProperties(interfaceDecl); checker::ScopeContext scopeCtx(this, interfaceDecl->Scope()); auto savedContext = checker::SavedCheckerContext(this, checker::CheckerStatus::IN_INTERFACE, interfaceType); @@ -317,7 +326,7 @@ ETSObjectType *ETSChecker::BuildInterfaceProperties(ir::TSInterfaceDeclaration * return interfaceType; } -ETSObjectType *ETSChecker::BuildClassProperties(ir::ClassDefinition *classDef) +ETSObjectType *ETSChecker::BuildBasicClassProperties(ir::ClassDefinition *classDef) { if (classDef->IsFinal() && classDef->IsAbstract()) { ThrowTypeError("Cannot use both 'final' and 'abstract' modifiers.", classDef->Start()); @@ -327,7 +336,6 @@ ETSObjectType *ETSChecker::BuildClassProperties(ir::ClassDefinition *classDef) ASSERT(var); const util::StringView &className = classDef->Ident()->Name(); - auto *classScope = classDef->Scope(); checker::ETSObjectType *classType {}; if (var->TsType() == nullptr) { @@ -368,10 +376,17 @@ ETSObjectType *ETSChecker::BuildClassProperties(ir::ClassDefinition *classDef) return classType; } - checker::ScopeContext scopeCtx(this, classScope); + return classType; +} - ResolveDeclaredMembersOfObject(classType); +ETSObjectType *ETSChecker::BuildClassProperties(ir::ClassDefinition *classDef) +{ + auto *classType = BuildBasicClassProperties(classDef); + + auto savedContext = checker::SavedCheckerContext(this, checker::CheckerStatus::IN_CLASS, classType); + checker::ScopeContext scopeCtx(this, classDef->Scope()); + ResolveDeclaredMembersOfObject(classType); return classType; } @@ -435,34 +450,51 @@ static void ResolveDeclaredMethodsOfObject(ETSChecker *checker, ETSObjectType *t { for (auto &[_, it] : scope->InstanceMethodScope()->Bindings()) { (void)_; - auto *node = it->Declaration()->Node()->AsMethodDefinition(); + auto *method = it->Declaration()->Node()->AsMethodDefinition(); + auto *function = method->Function(); + + function->Id()->SetVariable(method->Id()->Variable()); + for (ir::MethodDefinition *const overload : method->Overloads()) { + overload->Function()->Id()->SetVariable(overload->Id()->Variable()); + } - if (node->Function()->IsProxy()) { + if (function->IsProxy()) { continue; } - it->AddFlag(checker->GetAccessFlagFromNode(node)); - auto *funcType = checker->BuildMethodSignature(node); + it->AddFlag(checker->GetAccessFlagFromNode(method)); + auto *funcType = checker->BuildMethodSignature(method); it->SetTsType(funcType); funcType->SetVariable(it); - node->SetTsType(funcType); + method->SetTsType(funcType); type->AddProperty(it->AsLocalVariable()); } for (auto &[_, it] : scope->StaticMethodScope()->Bindings()) { (void)_; - if (!it->Declaration()->Node()->IsMethodDefinition() || - it->Declaration()->Node()->AsMethodDefinition()->Function()->IsProxy()) { + if (!it->Declaration()->Node()->IsMethodDefinition()) { continue; } - auto *node = it->Declaration()->Node()->AsMethodDefinition(); - it->AddFlag(checker->GetAccessFlagFromNode(node)); - auto *funcType = checker->BuildMethodSignature(node); + + auto *method = it->Declaration()->Node()->AsMethodDefinition(); + auto *function = method->Function(); + + function->Id()->SetVariable(method->Id()->Variable()); + for (ir::MethodDefinition *const overload : method->Overloads()) { + overload->Function()->Id()->SetVariable(overload->Id()->Variable()); + } + + if (function->IsProxy()) { + continue; + } + + it->AddFlag(checker->GetAccessFlagFromNode(method)); + auto *funcType = checker->BuildMethodSignature(method); it->SetTsType(funcType); funcType->SetVariable(it); - node->SetTsType(funcType); + method->SetTsType(funcType); - if (node->IsConstructor()) { + if (method->IsConstructor()) { type->AddConstructSignature(funcType->CallSignatures()); continue; } @@ -846,6 +878,7 @@ void ETSChecker::CreateAsyncProxyMethods(ir::ClassDefinition *classDef) } } for (auto *it : asyncImpls) { + it->SetParent(classDef); it->Check(this); classDef->Body().push_back(it); } @@ -997,7 +1030,7 @@ void ETSChecker::ValidateArrayIndex(ir::Expression *const expr, bool relaxed) double value = num.GetDouble(); double intpart; if (std::modf(value, &intpart) != 0.0) { - ThrowTypeError("Index fracional part should not be different from 0.0", expr->Start()); + ThrowTypeError("Index fractional part should be zero.", expr->Start()); } return; } @@ -1492,6 +1525,7 @@ void ETSChecker::TransformProperties(ETSObjectType *classType) ir::MethodDefinition *getter = GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), false, this); classDef->Body().push_back(getter); + getter->SetParent(classDef); classType->AddProperty(getter->Variable()->AsLocalVariable()); auto *const methodScope = scope->AsClassScope()->InstanceMethodScope(); @@ -1509,6 +1543,7 @@ void ETSChecker::TransformProperties(ETSObjectType *classType) if (!classProp->IsReadonly()) { ir::MethodDefinition *const setter = GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); + setter->SetParent(classDef); classType->AddProperty(setter->Variable()->AsLocalVariable()); prevDecl->Node()->AsMethodDefinition()->AddOverload(setter); @@ -1522,6 +1557,7 @@ void ETSChecker::TransformProperties(ETSObjectType *classType) if (!classProp->IsReadonly()) { ir::MethodDefinition *const setter = GenerateDefaultGetterSetter(classProp, scope->AsClassScope(), true, this); + setter->SetParent(classDef); classType->AddProperty(setter->Variable()->AsLocalVariable()); getter->AddOverload(setter); @@ -1584,86 +1620,68 @@ void ETSChecker::AddElementsToModuleObject(ETSObjectType *moduleObj, const util: } } -Type *ETSChecker::FindLeastUpperBound(Type *source, Type *target) -{ - ASSERT(source->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT) && target->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)); - - // GetCommonClass(GenA, GenB) => LUB(GenA, GenB) - auto commonClass = GetCommonClass(source, target); - - if (!commonClass->IsETSObjectType() || !commonClass->HasTypeFlag(TypeFlag::GENERIC)) { - return commonClass->HasTypeFlag(TypeFlag::CONSTANT) ? commonClass->Variable()->TsType() : commonClass; - } - - // GetRelevantArgumentedTypeFromChild(GenA, LUB(GenA, GenB)) => LUB(GenA, GenB) - ETSObjectType *relevantSourceType = - GetRelevantArgumentedTypeFromChild(source->AsETSObjectType(), commonClass->AsETSObjectType()); - ETSObjectType *relevantTargetType = - GetRelevantArgumentedTypeFromChild(target->AsETSObjectType(), commonClass->AsETSObjectType()); - - // GetTypeargumentedLUB(LUB(GenA, GenB), LUB(GenA, GenB)) => LUB(GenA, GenB) - return GetTypeargumentedLUB(relevantSourceType, relevantTargetType); -} - +// This function computes effective runtime view of type Type *ETSChecker::GetApparentType(Type *type) { - while (type->IsETSTypeParameter()) { - type = type->AsETSTypeParameter()->GetConstraintType(); + if (auto it = apparentTypes_.find(type); LIKELY(it != apparentTypes_.end())) { + return it->second; } - return type; -} + auto cached = [this, type](Type *res) { + if (type != res) { + apparentTypes_.insert({type, res}); + } + apparentTypes_.insert({res, res}); + return res; + }; -Type const *ETSChecker::GetApparentType(Type const *type) -{ - while (type->IsETSTypeParameter()) { - type = type->AsETSTypeParameter()->GetConstraintType(); + if (type->IsETSTypeParameter()) { + return cached(GetApparentType(type->AsETSTypeParameter()->GetConstraintType())); } - return type; -} - -Type *ETSChecker::MaybePromotedBuiltinType(Type *type) const -{ - return type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) ? checker::BoxingConverter::ETSTypeFromSource(this, type) : type; + if (type->IsETSNonNullishType()) { + return cached( + GetNonNullishType(GetApparentType(type->AsETSNonNullishType()->GetUnderlying()->GetConstraintType()))); + } + if (type->IsETSArrayType()) { + return cached(type); + } + if (type->IsETSUnionType()) { + bool differ = false; + ArenaVector newConstituent(Allocator()->Adapter()); + for (auto const &ct : type->AsETSUnionType()->ConstituentTypes()) { + newConstituent.push_back(GetApparentType(ct)); + differ |= (newConstituent.back() != ct); + } + return cached(differ ? CreateETSUnionType(std::move(newConstituent)) : type); + } + return cached(type); } -Type *ETSChecker::GetCommonClass(Type *source, Type *target) +Type const *ETSChecker::GetApparentType(Type const *type) const { - SavedTypeRelationFlagsContext checkerCtx(this->Relation(), TypeRelationFlag::IGNORE_TYPE_PARAMETERS); - - if (IsTypeIdenticalTo(source, target)) { - return source; + if (auto it = apparentTypes_.find(type); LIKELY(it != apparentTypes_.end())) { + return it->second; } - - if (Relation()->IsSupertypeOf(target, source)) { - return target; + // Relaxed for some types + if (type->IsETSTypeParameter()) { + return GetApparentType(type->AsETSTypeParameter()->GetConstraintType()); } - - if (Relation()->IsSupertypeOf(source, target)) { - return source; + if (type->IsETSArrayType()) { + return type; } - - if (source->IsETSObjectType() && target->IsETSObjectType()) { - if (source->IsETSNullLike()) { - return target; - } - - if (target->IsETSNullLike()) { - return source; - } - - if (source->AsETSObjectType()->GetDeclNode() == target->AsETSObjectType()->GetDeclNode()) { - return source; - } - - return GetClosestCommonAncestor(source->AsETSObjectType(), target->AsETSObjectType()); + if (type->IsETSUnionType() || type->IsETSNonNullishType()) { + ASSERT_PRINT(false, std::string("Type ") + type->ToString() + " was not found in apparent_types_"); } - - return GlobalETSObjectType(); + return type; } ETSObjectType *ETSChecker::GetClosestCommonAncestor(ETSObjectType *source, ETSObjectType *target) { - ASSERT(target->SuperType() != nullptr); + if (source->AsETSObjectType()->GetDeclNode() == target->AsETSObjectType()->GetDeclNode()) { + return source; + } + if (target->SuperType() == nullptr) { + return GlobalETSObjectType(); + } auto *targetBase = GetOriginalBaseType(target->SuperType()); auto *targetType = targetBase == nullptr ? target->SuperType() : targetBase; @@ -1679,36 +1697,6 @@ ETSObjectType *ETSChecker::GetClosestCommonAncestor(ETSObjectType *source, ETSOb return GetClosestCommonAncestor(sourceType, targetType); } -ETSObjectType *ETSChecker::GetTypeargumentedLUB(ETSObjectType *const source, ETSObjectType *const target) -{ - ASSERT(source->TypeArguments().size() == target->TypeArguments().size()); - - ArenaVector params(Allocator()->Adapter()); - - for (uint32_t i = 0; i < source->TypeArguments().size(); i++) { - params.push_back(FindLeastUpperBound(source->TypeArguments()[i], target->TypeArguments()[i])); - } - - const util::StringView hash = GetHashFromTypeArguments(params); - - if (!source->GetDeclNode()->IsClassDefinition()) { - return source; - } - - ETSObjectType *templateType = source->GetDeclNode()->AsClassDefinition()->TsType()->AsETSObjectType(); - - auto *lubType = templateType->GetInstantiatedType(hash); - - if (lubType == nullptr) { - lubType = templateType->Instantiate(Allocator(), Relation(), GetGlobalTypesHolder())->AsETSObjectType(); - lubType->SetTypeArguments(std::move(params)); - - templateType->GetInstantiationMap().try_emplace(hash, lubType); - } - - return lubType; -} - void ETSChecker::CheckInvokeMethodsLegitimacy(ETSObjectType *const classType) { if (classType->HasObjectFlag(ETSObjectFlags::CHECKED_INVOKE_LEGITIMACY)) { diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index ea39dcd47ced2ae9e31fc730999c79875efd611f..a7aa1b5a018f46afdc4b54a22e4fe09cadc87bab 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -131,18 +131,14 @@ ETSArrayType *ETSChecker::CreateETSArrayType(Type *elementType) return arrayType; } -Type *ETSChecker::CreateETSUnionType(ArenaVector &&constituentTypes) +Type *ETSChecker::CreateETSUnionType(Span constituentTypes) { if (constituentTypes.empty()) { return nullptr; } ArenaVector newConstituentTypes(Allocator()->Adapter()); - - for (auto *it : constituentTypes) { - newConstituentTypes.push_back( - it->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) ? BoxingConverter::ETSTypeFromSource(this, it) : it); - } + newConstituentTypes.assign(constituentTypes.begin(), constituentTypes.end()); ETSUnionType::NormalizeTypes(Relation(), newConstituentTypes); if (newConstituentTypes.size() == 1) { @@ -308,8 +304,7 @@ ETSObjectType *ETSChecker::UpdateGlobalType(ETSObjectType *objType, util::String } if (name == compiler::Signatures::BUILTIN_OBJECT_CLASS) { - auto *nullish = - CreateNullishType(objType, checker::TypeFlag::NULLISH, Allocator(), Relation(), GetGlobalTypesHolder()); + auto *nullish = CreateETSUnionType({objType, GlobalETSNullType(), GlobalETSUndefinedType()}); GetGlobalTypesHolder()->GlobalTypes()[static_cast(GlobalTypeId::ETS_NULLISH_OBJECT)] = nullish; } } @@ -389,28 +384,40 @@ ETSEnumType *ETSChecker::CreateETSEnumType(ir::TSEnumDeclaration const *const en auto *const namesArrayIdent = CreateEnumNamesArray(enumType); - auto const getNameMethod = CreateEnumGetNameMethod(namesArrayIdent, enumType); + auto *identClone = namesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(namesArrayIdent->TsType()); + auto const getNameMethod = CreateEnumGetNameMethod(identClone, enumType); enumType->SetGetNameMethod(getNameMethod); - auto const valueOfMethod = CreateEnumValueOfMethod(namesArrayIdent, enumType); + identClone = namesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(namesArrayIdent->TsType()); + auto const valueOfMethod = CreateEnumValueOfMethod(identClone, enumType); enumType->SetValueOfMethod(valueOfMethod); - auto const fromIntMethod = CreateEnumFromIntMethod(namesArrayIdent, enumType); + identClone = namesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(namesArrayIdent->TsType()); + auto const fromIntMethod = CreateEnumFromIntMethod(identClone, enumType); enumType->SetFromIntMethod(fromIntMethod); auto *const valuesArrayIdent = CreateEnumValuesArray(enumType); - auto const getValueMethod = CreateEnumGetValueMethod(valuesArrayIdent, enumType); + identClone = valuesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(valuesArrayIdent->TsType()); + auto const getValueMethod = CreateEnumGetValueMethod(identClone, enumType); enumType->SetGetValueMethod(getValueMethod); auto *const stringValuesArrayIdent = CreateEnumStringValuesArray(enumType); - auto const toStringMethod = CreateEnumToStringMethod(stringValuesArrayIdent, enumType); + identClone = stringValuesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(stringValuesArrayIdent->TsType()); + auto const toStringMethod = CreateEnumToStringMethod(identClone, enumType); enumType->SetToStringMethod(toStringMethod); auto *const itemsArrayIdent = CreateEnumItemsArray(enumType); - auto const valuesMethod = CreateEnumValuesMethod(itemsArrayIdent, enumType); + identClone = itemsArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(itemsArrayIdent->TsType()); + auto const valuesMethod = CreateEnumValuesMethod(identClone, enumType); enumType->SetValuesMethod(valuesMethod); for (auto *const member : enumType->GetMembers()) { @@ -444,24 +451,34 @@ ETSStringEnumType *ETSChecker::CreateETSStringEnumType(ir::TSEnumDeclaration con auto *const namesArrayIdent = CreateEnumNamesArray(enumType); - auto const getNameMethod = CreateEnumGetNameMethod(namesArrayIdent, enumType); + auto *identClone = namesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(namesArrayIdent->TsType()); + auto const getNameMethod = CreateEnumGetNameMethod(identClone, enumType); enumType->SetGetNameMethod(getNameMethod); - auto const valueOfMethod = CreateEnumValueOfMethod(namesArrayIdent, enumType); + identClone = namesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(namesArrayIdent->TsType()); + auto const valueOfMethod = CreateEnumValueOfMethod(identClone, enumType); enumType->SetValueOfMethod(valueOfMethod); - auto const fromIntMethod = CreateEnumFromIntMethod(namesArrayIdent, enumType); + identClone = namesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(namesArrayIdent->TsType()); + auto const fromIntMethod = CreateEnumFromIntMethod(identClone, enumType); enumType->SetFromIntMethod(fromIntMethod); auto *const stringValuesArrayIdent = CreateEnumStringValuesArray(enumType); - auto const toStringMethod = CreateEnumToStringMethod(stringValuesArrayIdent, enumType); + identClone = stringValuesArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(stringValuesArrayIdent->TsType()); + auto const toStringMethod = CreateEnumToStringMethod(identClone, enumType); enumType->SetToStringMethod(toStringMethod); enumType->SetGetValueMethod(toStringMethod); auto *const itemsArrayIdent = CreateEnumItemsArray(enumType); - auto const valuesMethod = CreateEnumValuesMethod(itemsArrayIdent, enumType); + identClone = itemsArrayIdent->Clone(Allocator(), nullptr); + identClone->SetTsType(itemsArrayIdent->TsType()); + auto const valuesMethod = CreateEnumValuesMethod(identClone, enumType); enumType->SetValuesMethod(valuesMethod); for (auto *const member : enumType->GetMembers()) { diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index b74e3dcbc3d95865bb962bcb7149645200f2b575..e21764bd2266621b6340944d2feef47330dab619 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -101,7 +101,7 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType bool InstantiationContext::ValidateTypeArg(Type *constraintType, Type *typeArg) { - // NOTE: #14993 enforce ETSChecker::IsReferenceType + // NOTE: #14993 enforce IsETSReferenceType if (typeArg->IsWildcardType()) { return true; } @@ -117,7 +117,7 @@ void InstantiationContext::InstantiateType(ETSObjectType *type, ir::TSTypeParame if (typeArgs != nullptr) { for (auto *const it : typeArgs->Params()) { - auto *paramType = checker_->GetTypeFromTypeAnnotation(it); + auto *paramType = it->GetType(checker_); if (paramType->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { checker_->Relation()->SetNode(it); diff --git a/ets2panda/checker/ets/unboxingConverter.cpp b/ets2panda/checker/ets/unboxingConverter.cpp index 3dba28ee9384615a46d6f3d7af22778f55e4b81c..46d412d285cf7526c682012b6241db78e7edad4f 100644 --- a/ets2panda/checker/ets/unboxingConverter.cpp +++ b/ets2panda/checker/ets/unboxingConverter.cpp @@ -20,35 +20,35 @@ namespace panda::es2panda::checker { -checker::Type *UnboxingConverter::GlobalTypeFromSource(ETSObjectFlags type) +checker::Type *UnboxingConverter::GlobalTypeFromSource(checker::ETSChecker const *checker, ETSObjectType *type) { - switch (type) { + switch (type->BuiltInKind()) { case ETSObjectFlags::BUILTIN_BOOLEAN: { - return Checker()->GlobalETSBooleanType(); + return checker->GlobalETSBooleanType(); } case ETSObjectFlags::BUILTIN_BYTE: { - return Checker()->GlobalByteType(); + return checker->GlobalByteType(); } case ETSObjectFlags::BUILTIN_SHORT: { - return Checker()->GlobalShortType(); + return checker->GlobalShortType(); } case ETSObjectFlags::BUILTIN_CHAR: { - return Checker()->GlobalCharType(); + return checker->GlobalCharType(); } case ETSObjectFlags::BUILTIN_INT: { - return Checker()->GlobalIntType(); + return checker->GlobalIntType(); } case ETSObjectFlags::BUILTIN_LONG: { - return Checker()->GlobalLongType(); + return checker->GlobalLongType(); } case ETSObjectFlags::BUILTIN_FLOAT: { - return Checker()->GlobalFloatType(); + return checker->GlobalFloatType(); } case ETSObjectFlags::BUILTIN_DOUBLE: { - return Checker()->GlobalDoubleType(); + return checker->GlobalDoubleType(); } default: - return Source(); + return type; } } diff --git a/ets2panda/checker/ets/unboxingConverter.h b/ets2panda/checker/ets/unboxingConverter.h index 540f22fb9d935aa3f4177f86235cbda5a9451527..0c878884b13ed35da625076f068cba40bb4681e7 100644 --- a/ets2panda/checker/ets/unboxingConverter.h +++ b/ets2panda/checker/ets/unboxingConverter.h @@ -31,7 +31,7 @@ public: return; } - SetResult(GlobalTypeFromSource(source->AsETSObjectType()->BuiltInKind())); + SetResult(GlobalTypeFromSource(checker, source->AsETSObjectType())); relation->Result(source != Result()); } @@ -44,12 +44,12 @@ public: return; } - SetResult(GlobalTypeFromSource(Source()->AsETSObjectType()->BuiltInKind())); + SetResult(GlobalTypeFromSource(checker, source->AsETSObjectType())); Relation()->Result(Result()->TypeFlags() == target->TypeFlags()); } - checker::Type *GlobalTypeFromSource(ETSObjectFlags type); + static checker::Type *GlobalTypeFromSource(checker::ETSChecker const *checker, ETSObjectType *type); }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ts/helpers.cpp b/ets2panda/checker/ts/helpers.cpp index 8647a7dcde7dec70246a3b3e3c32eba5546e6c6e..7a45f97be611c8871eeb61266ddda74432c1c599 100644 --- a/ets2panda/checker/ts/helpers.cpp +++ b/ets2panda/checker/ts/helpers.cpp @@ -132,7 +132,7 @@ Type *TSChecker::ExtractDefinitelyFalsyTypes(Type *type) return GlobalZeroBigintType(); } - if (type == GlobalFalseType() || type->IsNullish() || type->HasTypeFlag(TypeFlag::ANY_OR_UNKNOWN) || + if (type == GlobalFalseType() || type->DefinitelyETSNullish() || type->HasTypeFlag(TypeFlag::ANY_OR_UNKNOWN) || type->HasTypeFlag(TypeFlag::VOID) || (type->IsStringLiteralType() && IsTypeIdenticalTo(type, GlobalEmptyStringType())) || (type->IsNumberLiteralType() && IsTypeIdenticalTo(type, GlobalZeroType())) || diff --git a/ets2panda/checker/types/ets/byteType.h b/ets2panda/checker/types/ets/byteType.h index cd81d91cd3ad250330121d70bbc1c1ab71291f73..3bc9deb36dd38b0e039c69f375ce295f8d674020 100644 --- a/ets2panda/checker/types/ets/byteType.h +++ b/ets2panda/checker/types/ets/byteType.h @@ -37,12 +37,12 @@ public: void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "byte"; } - void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override + void ToAssemblerType(std::stringstream &ss) const override { ss << compiler::Signatures::PRIMITIVE_BYTE; } diff --git a/ets2panda/checker/types/ets/charType.h b/ets2panda/checker/types/ets/charType.h index f917156bcf5ac851bc61ddd2a9deee84ed26b184..54641c35d1adf14cf2b36cecb725d1cd928d257d 100644 --- a/ets2panda/checker/types/ets/charType.h +++ b/ets2panda/checker/types/ets/charType.h @@ -37,7 +37,7 @@ public: void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "char"; } diff --git a/ets2panda/checker/types/ets/doubleType.h b/ets2panda/checker/types/ets/doubleType.h index ddf7cc3e41102344f620e13423eda07d67a6e84e..57579724f2d938e407d4b610d81bbc1f1670c06f 100644 --- a/ets2panda/checker/types/ets/doubleType.h +++ b/ets2panda/checker/types/ets/doubleType.h @@ -37,7 +37,7 @@ public: void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "double"; } diff --git a/ets2panda/checker/types/ets/etsArrayType.cpp b/ets2panda/checker/types/ets/etsArrayType.cpp index 9b0e9403aad8cc4a0cc7699c4f027367add94ac6..98b3323d2068eabc6ae1a6ba06cf8736ad953ec7 100644 --- a/ets2panda/checker/types/ets/etsArrayType.cpp +++ b/ets2panda/checker/types/ets/etsArrayType.cpp @@ -21,15 +21,17 @@ #include "checker/types/typeRelation.h" namespace panda::es2panda::checker { -void ETSArrayType::ToString(std::stringstream &ss) const +void ETSArrayType::ToString(std::stringstream &ss, bool precise) const { - element_->ToString(ss); - ss << "[]"; - - if (IsNullish()) { - ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) - << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); + bool needParens = (element_->IsETSUnionType() || element_->IsETSFunctionType()); + if (needParens) { + ss << "("; } + element_->ToString(ss, precise); + if (needParens) { + ss << ")"; + } + ss << "[]"; } void ETSArrayType::ToAssemblerType(std::stringstream &ss) const @@ -66,10 +68,6 @@ uint32_t ETSArrayType::Rank() const void ETSArrayType::Identical(TypeRelation *relation, Type *other) { - if ((ContainsNull() != other->ContainsNull()) || (ContainsUndefined() != other->ContainsUndefined())) { - return; - } - if (other->IsETSArrayType()) { // will be removed, if wildcard type is assigned to array type, not element type if (element_->IsWildcardType() || other->AsETSArrayType()->ElementType()->IsWildcardType()) { @@ -82,19 +80,6 @@ void ETSArrayType::Identical(TypeRelation *relation, Type *other) void ETSArrayType::AssignmentTarget(TypeRelation *relation, Type *source) { - if (source->IsETSNullType()) { - relation->Result(ContainsNull()); - return; - } - if (source->IsETSUndefinedType()) { - relation->Result(ContainsUndefined()); - return; - } - - if ((source->ContainsNull() && !ContainsNull()) || (source->ContainsUndefined() && !ContainsUndefined())) { - return; - } - if (source->IsETSArrayType()) { if (AsETSArrayType()->ElementType()->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) || source->AsETSArrayType()->ElementType()->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { @@ -152,7 +137,7 @@ void ETSArrayType::IsSupertypeOf(TypeRelation *const relation, Type *source) if (source->IsETSArrayType()) { auto *const sourceElemType = this->AsETSArrayType()->ElementType(); auto *const targetElemType = source->AsETSArrayType()->ElementType(); - if (ETSChecker::IsReferenceType(targetElemType) && ETSChecker::IsReferenceType(sourceElemType)) { + if (targetElemType->IsETSReferenceType() && sourceElemType->IsETSReferenceType()) { sourceElemType->IsSupertypeOf(relation, targetElemType); } } diff --git a/ets2panda/checker/types/ets/etsArrayType.h b/ets2panda/checker/types/ets/etsArrayType.h index f4f90331b9512aa7c8c929e2e8e97343351801fd..edd0ddde3cc1b5ee5b644d51fa1734b04bb57d03 100644 --- a/ets2panda/checker/types/ets/etsArrayType.h +++ b/ets2panda/checker/types/ets/etsArrayType.h @@ -38,7 +38,7 @@ public: return {false, false}; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void ToAssemblerType(std::stringstream &ss) const override; void ToAssemblerTypeWithRank(std::stringstream &ss) const override; void ToDebugInfoType(std::stringstream &ss) const override; diff --git a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp index 71738ebf7c2dc0c640b06f6131719ec5cdb720a7..38550b5097f8b59db27275de1d8b2e18a919890b 100644 --- a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp +++ b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.cpp @@ -18,11 +18,11 @@ #include "checker/types/ets/etsAsyncFuncReturnType.h" namespace panda::es2panda::checker { -void ETSAsyncFuncReturnType::ToString(std::stringstream &ss) const +void ETSAsyncFuncReturnType::ToString(std::stringstream &ss, bool precise) const { - promiseType_->ToString(ss); + promiseType_->ToString(ss, precise); ss << " | "; - GetPromiseTypeArg()->ToString(ss); + GetPromiseTypeArg()->ToString(ss, precise); } void ETSAsyncFuncReturnType::Identical(TypeRelation *relation, Type *other) diff --git a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h index 339a3b1d1fb36f9f48d27b22f7d6d134ec4624af..07c9ecf6bddbb8c94178daeedd7b1e3f6ffcf549 100644 --- a/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h +++ b/ets2panda/checker/types/ets/etsAsyncFuncReturnType.h @@ -30,7 +30,7 @@ public: SetAssemblerName(compiler::Signatures::BUILTIN_OBJECT); } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; diff --git a/ets2panda/checker/types/ets/etsBigIntType.h b/ets2panda/checker/types/ets/etsBigIntType.h index befbfb3de9cd9d965fcc3e063ca4b651f7e752d8..a8b4fa3ecc77596201f4d274022b90c89ce9aea5 100644 --- a/ets2panda/checker/types/ets/etsBigIntType.h +++ b/ets2panda/checker/types/ets/etsBigIntType.h @@ -43,7 +43,7 @@ public: void AssignmentTarget(TypeRelation *relation, Type *source) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << lexer::TokenToString(lexer::TokenType::KEYW_BIGINT); } diff --git a/ets2panda/checker/types/ets/etsBooleanType.h b/ets2panda/checker/types/ets/etsBooleanType.h index 5127daf1fa56668d143014f3d97f68952eac3dae..4a9f175ea84b921e6c0619d505f8a81f74b39d92 100644 --- a/ets2panda/checker/types/ets/etsBooleanType.h +++ b/ets2panda/checker/types/ets/etsBooleanType.h @@ -36,7 +36,7 @@ public: return value_; } - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "boolean"; } diff --git a/ets2panda/checker/types/ets/etsDynamicType.cpp b/ets2panda/checker/types/ets/etsDynamicType.cpp index 4f577085efbf1c308fb30e7258a3d2199c0b920b..23c4c420ec40abb546bbb1cb2052841fa350e083 100644 --- a/ets2panda/checker/types/ets/etsDynamicType.cpp +++ b/ets2panda/checker/types/ets/etsDynamicType.cpp @@ -100,8 +100,7 @@ void ETSDynamicType::CastTarget(TypeRelation *relation, Type *source) bool ETSDynamicType::IsConvertible(Type const *target) { - return target->IsETSDynamicType() || (target->IsETSObjectType() && !target->IsETSNullLike()) || - target->IsETSArrayType() || + return target->IsETSDynamicType() || target->IsETSObjectType() || target->IsETSArrayType() || target->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC | checker::TypeFlag::ETS_BOOLEAN); } diff --git a/ets2panda/checker/types/ets/etsEnumType.cpp b/ets2panda/checker/types/ets/etsEnumType.cpp index 2a779b6a18f7a7ceb2b72012f9e26405c332b9ad..45d4cdce0fd15559ebe2becb0b29a5364f123a85 100644 --- a/ets2panda/checker/types/ets/etsEnumType.cpp +++ b/ets2panda/checker/types/ets/etsEnumType.cpp @@ -87,7 +87,7 @@ void ETSEnumInterface::ToDebugInfoType(std::stringstream &ss) const ToDebugInfoTypeImpl(ss); } -void ETSEnumInterface::ToString(std::stringstream &ss) const +void ETSEnumInterface::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << decl_->Key()->Name(); } diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index 2bd8c99d3e2bc35d51ff9ace55572753de6a8cdb..0ccfa56d29af6b23bb2c0d48f7030c901a77a4d3 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -60,7 +60,7 @@ public: void ToAssemblerType(std::stringstream &ss) const override; void ToDebugInfoType(std::stringstream &ss) const override; - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; [[nodiscard]] const ir::TSEnumDeclaration *GetDecl() const noexcept; diff --git a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp index b737bd39b44a2bd56258300b4b978e9b461de704..687496405eb080f15abc45929e7c006fbb0b5f95 100644 --- a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp +++ b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.cpp @@ -27,11 +27,11 @@ namespace panda::es2panda::checker { in order to figure out a representation for case 3, we need the etsExtensionFuncHelperType */ -void ETSExtensionFuncHelperType::ToString(std::stringstream &ss) const +void ETSExtensionFuncHelperType::ToString(std::stringstream &ss, bool precise) const { - classMethodType_->ToString(ss); + classMethodType_->ToString(ss, precise); ss << " | "; - extensionFunctionType_->ToString(ss); + extensionFunctionType_->ToString(ss, precise); } void ETSExtensionFuncHelperType::AssignmentTarget(TypeRelation *relation, Type *source) diff --git a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h index a646bec1436f1f39ebeb5565437e90ccb2e4eec7..8e4b85c913247c57eba4ff8da4518da96a5d76c9 100644 --- a/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h +++ b/ets2panda/checker/types/ets/etsExtensionFuncHelperType.h @@ -38,7 +38,7 @@ public: return extensionFunctionType_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void AssignmentTarget(TypeRelation *relation, Type *source) override; private: diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index a95e78d4d676aa7e15057237e54a14afa5da5893..19d3c3132b8be697efca233fd29b4e2d66c9b5b8 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -33,9 +33,9 @@ Signature *ETSFunctionType::FirstAbstractSignature() return nullptr; } -void ETSFunctionType::ToString(std::stringstream &ss) const +void ETSFunctionType::ToString(std::stringstream &ss, bool precise) const { - callSignatures_[0]->ToString(ss, nullptr); + callSignatures_[0]->ToString(ss, nullptr, false, precise); } void ETSFunctionType::Identical(TypeRelation *relation, Type *other) @@ -86,17 +86,16 @@ static Signature *ProcessSignatures(TypeRelation *relation, Signature *target, E if (!it->GetSignatureInfo()->typeParams.empty()) { auto *substitution = relation->GetChecker()->AsETSChecker()->NewSubstitution(); - auto *instantiatedTypeParams = relation->GetChecker()->AsETSChecker()->NewInstantiatedTypeParamsSet(); bool res = true; for (size_t ix = 0; ix < target->MinArgCount(); ix++) { res &= relation->GetChecker()->AsETSChecker()->EnhanceSubstitutionForType( it->GetSignatureInfo()->typeParams, it->GetSignatureInfo()->params[ix]->TsType(), - target->GetSignatureInfo()->params[ix]->TsType(), substitution, instantiatedTypeParams); + target->GetSignatureInfo()->params[ix]->TsType(), substitution); } if (target->RestVar() != nullptr) { res &= relation->GetChecker()->AsETSChecker()->EnhanceSubstitutionForType( it->GetSignatureInfo()->typeParams, it->RestVar()->TsType(), target->RestVar()->TsType(), - substitution, instantiatedTypeParams); + substitution); } if (!res) { continue; @@ -106,7 +105,7 @@ static Signature *ProcessSignatures(TypeRelation *relation, Signature *target, E size_t idx = 0; for (; idx != target->MinArgCount(); idx++) { - if (!relation->IsIdenticalTo(target->Params()[idx]->TsType(), it->Params()[idx]->TsType())) { + if (!relation->IsAssignableTo(target->Params()[idx]->TsType(), it->Params()[idx]->TsType())) { break; } } @@ -116,11 +115,11 @@ static Signature *ProcessSignatures(TypeRelation *relation, Signature *target, E } if (target->RestVar() != nullptr && - !relation->IsIdenticalTo(target->RestVar()->TsType(), it->RestVar()->TsType())) { + !relation->IsAssignableTo(target->RestVar()->TsType(), it->RestVar()->TsType())) { continue; } - if (!relation->IsAssignableTo(target->ReturnType(), it->ReturnType())) { + if (!relation->IsAssignableTo(it->ReturnType(), target->ReturnType())) { continue; } @@ -130,6 +129,27 @@ static Signature *ProcessSignatures(TypeRelation *relation, Signature *target, E return match; } +static ETSObjectType *SubstitutedFunctionalInterfaceForSignature(TypeRelation *relation, Signature *signature, + ETSObjectType *functionalInterface) +{ + auto &interfaceArgs = functionalInterface->TypeArguments(); + auto *checker = relation->GetChecker()->AsETSChecker(); + Substitution *substitution = checker->NewSubstitution(); + size_t i = 0; + for (auto *param : signature->Params()) { + auto *paramType = (param->TsType()->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) + ? checker->PrimitiveTypeAsETSBuiltinType(param->TsType()) + : param->TsType(); + substitution->emplace(interfaceArgs[i++]->AsETSTypeParameter(), paramType); + } + auto *retType = (signature->ReturnType()->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) + ? checker->PrimitiveTypeAsETSBuiltinType(signature->ReturnType()) + : signature->ReturnType(); + substitution->emplace(interfaceArgs[i]->AsETSTypeParameter(), retType); + + return functionalInterface->Substitute(relation, substitution); +} + void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) { if (!source->IsETSFunctionType() && @@ -150,8 +170,9 @@ void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) return; } - if (!target->Function()->IsThrowing()) { - if (match->Function()->IsThrowing() || match->Function()->IsRethrowing()) { + if (!(target->Function()->IsThrowing() || target->HasSignatureFlag(SignatureFlags::THROWS))) { + if (match->Function()->IsThrowing() || match->Function()->IsRethrowing() || + match->HasSignatureFlag(SignatureFlags::THROWS) || match->HasSignatureFlag(SignatureFlags::RETHROWS)) { relation->GetChecker()->ThrowTypeError( "Functions that can throw exceptions cannot be assigned to non throwing functions.", relation->GetNode()->Start()); @@ -160,12 +181,15 @@ void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) ASSERT(relation->GetNode() != nullptr); if (!sourceIsFunctional) { + auto *substitutedFuncInterface = + SubstitutedFunctionalInterfaceForSignature(relation, match, callSignatures_[0]->Owner()); + if (relation->GetNode()->IsArrowFunctionExpression()) { relation->GetChecker()->AsETSChecker()->CreateLambdaObjectForLambdaReference( - relation->GetNode()->AsArrowFunctionExpression(), callSignatures_[0]->Owner()); + relation->GetNode()->AsArrowFunctionExpression(), substitutedFuncInterface); } else { relation->GetChecker()->AsETSChecker()->CreateLambdaObjectForFunctionReference(relation->GetNode(), match, - callSignatures_[0]->Owner()); + substitutedFuncInterface); } } @@ -206,19 +230,22 @@ ETSFunctionType *ETSFunctionType::Substitute(TypeRelation *relation, const Subst return anyChange ? copiedType : this; } -checker::RelationResult ETSFunctionType::CastFunctionParams(TypeRelation *relation, Type *target) +checker::RelationResult ETSFunctionType::CastFunctionParams(TypeRelation *relation, Signature *targetInvokeSig) { - auto *targetType = target->AsETSObjectType(); - auto *body = targetType->GetDeclNode()->AsTSInterfaceDeclaration()->Body(); - auto targetParams = body->AsTSInterfaceBody()->Body()[0]->AsMethodDefinition()->Function()->Params(); - for (size_t i = 0; i < targetType->TypeArguments().size(); i++) { + auto *ourSig = callSignatures_[0]; + auto &ourParams = ourSig->Params(); + auto &theirParams = targetInvokeSig->Params(); + if (ourParams.size() != theirParams.size()) { + return RelationResult::FALSE; + } + for (size_t i = 0; i < theirParams.size(); i++) { relation->Result(RelationResult::FALSE); - callSignatures_[0]->Function()->Params()[i]->TsType()->Cast( - relation, targetParams[i]->AsETSParameterExpression()->Check(relation->GetChecker()->AsETSChecker())); - if (relation->IsTrue()) { - continue; + auto savedBoxFlags = relation->GetNode()->GetBoxingUnboxingFlags(); + relation->IsCastableTo(ourParams[i]->TsType(), theirParams[i]->TsType()); + relation->GetNode()->SetBoxingUnboxingFlags(savedBoxFlags); + if (!relation->IsTrue()) { + return RelationResult::FALSE; } - return RelationResult::FALSE; } return RelationResult::TRUE; } @@ -226,23 +253,39 @@ checker::RelationResult ETSFunctionType::CastFunctionParams(TypeRelation *relati void ETSFunctionType::Cast(TypeRelation *relation, Type *target) { ASSERT(relation->GetNode()->IsArrowFunctionExpression()); + auto *savedNode = relation->GetNode(); + conversion::Forbidden(relation); if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { auto *targetType = target->AsETSObjectType(); - auto *body = targetType->GetDeclNode()->AsTSInterfaceDeclaration()->Body()->AsTSInterfaceBody(); - auto targetParams = body->AsTSInterfaceBody()->Body()[0]->AsMethodDefinition()->Function()->Params(); - if (targetType->HasObjectFlag(ETSObjectFlags::FUNCTIONAL_INTERFACE) && - targetParams.size() == callSignatures_[0]->Function()->Params().size()) { - relation->Result(CastFunctionParams(relation, target)); + if (targetType->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + auto *targetInvokeVar = targetType->GetProperty(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME, + PropertySearchFlags::SEARCH_INSTANCE_METHOD); + if (targetInvokeVar == nullptr || !targetInvokeVar->TsType()->IsETSFunctionType()) { + return; + } + auto *targetInvokeSig = targetInvokeVar->TsType()->AsETSFunctionType()->CallSignatures()[0]; + relation->Result(CastFunctionParams(relation, targetInvokeSig)); + auto *targetReturnType = targetInvokeSig->ReturnType(); + auto savedBoxFlags = relation->GetNode()->GetBoxingUnboxingFlags(); + relation->IsCastableTo(callSignatures_[0]->ReturnType(), targetReturnType); + relation->GetNode()->SetBoxingUnboxingFlags(savedBoxFlags); } - relation->Result(RelationResult::FALSE); - auto targetReturnType = body->Body()[0]->AsMethodDefinition()->Function()->ReturnTypeAnnotation(); - callSignatures_[0]->ReturnType()->Cast(relation, targetReturnType->TsType()); if (relation->IsTrue()) { relation->GetChecker()->AsETSChecker()->CreateLambdaObjectForLambdaReference( relation->GetNode()->AsArrowFunctionExpression(), targetType->AsETSObjectType()); + relation->SetNode(savedNode); return; } } - conversion::Forbidden(relation); +} + +ETSFunctionType *ETSFunctionType::BoxPrimitives(ETSChecker *checker) +{ + auto *allocator = checker->Allocator(); + auto *ret = allocator->New(name_, allocator); + for (auto *sig : callSignatures_) { + ret->AddCallSignature(sig->BoxPrimitives(checker)); + } + return ret; } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsFunctionType.h b/ets2panda/checker/types/ets/etsFunctionType.h index 2d79f87d3c7e77db11b32a4b48956b62ba212c36..71ef246fbc284ca6fad92fe1f67bf1bd3e42e771 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.h +++ b/ets2panda/checker/types/ets/etsFunctionType.h @@ -103,23 +103,24 @@ public: void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override { - ss << "ets.lang.Object"; + UNREACHABLE(); } - void ToDebugInfoType(std::stringstream &ss) const override + void ToDebugInfoType([[maybe_unused]] std::stringstream &ss) const override { - ss << "ets.lang.Object"; + UNREACHABLE(); } Signature *FirstAbstractSignature(); - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; ETSFunctionType *Substitute(TypeRelation *relation, const Substitution *substitution) override; void Cast(TypeRelation *relation, Type *target) override; - checker::RelationResult CastFunctionParams(TypeRelation *relation, Type *target); + checker::RelationResult CastFunctionParams(TypeRelation *relation, Signature *targetInvokeSig); + ETSFunctionType *BoxPrimitives(ETSChecker *checker); private: ArenaVector callSignatures_; diff --git a/ets2panda/checker/types/ets/etsNonNullishType.cpp b/ets2panda/checker/types/ets/etsNonNullishType.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b0ed729beadb590421e371ff164a76c043d99cfa --- /dev/null +++ b/ets2panda/checker/types/ets/etsNonNullishType.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "etsTypeParameter.h" +#include "etsNullishTypes.h" +#include "ir/expressions/identifier.h" +#include "ir/ts/tsTypeParameter.h" +#include "checker/ETSchecker.h" +#include "checker/ets/conversion.h" + +namespace panda::es2panda::checker { + +void ETSNonNullishType::ToString(std::stringstream &ss, bool precise) const +{ + ss << "NonNullable<"; + GetUnderlying()->ToString(ss, precise); + ss << ">"; +} + +void ETSNonNullishType::Identical(TypeRelation *relation, Type *other) +{ + if (other->IsETSNonNullishType()) { + relation->IsIdenticalTo(GetUnderlying(), other->AsETSNonNullishType()->GetUnderlying()); + } +} + +bool ETSNonNullishType::AssignmentSource([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *target) +{ + return relation->IsSupertypeOf(target, this); +} + +void ETSNonNullishType::AssignmentTarget([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *source) +{ + relation->IsSupertypeOf(this, source); +} + +void ETSNonNullishType::Cast(TypeRelation *relation, Type *target) +{ + if (relation->IsSupertypeOf(target, this)) { + relation->RemoveFlags(TypeRelationFlag::UNCHECKED_CAST); + return; + } + if (relation->IsIdenticalTo(GetUnderlying(), target)) { + relation->RemoveFlags(TypeRelationFlag::UNCHECKED_CAST); + return; + } + relation->Result(relation->InCastingContext()); +} + +void ETSNonNullishType::CastTarget(TypeRelation *relation, Type *source) +{ + if (relation->IsSupertypeOf(this, source)) { + relation->RemoveFlags(TypeRelationFlag::UNCHECKED_CAST); + return; + } + if (relation->IsIdenticalTo(source, GetUnderlying())) { + relation->RemoveFlags(TypeRelationFlag::UNCHECKED_CAST); + } + relation->Result(relation->InCastingContext()); +} + +void ETSNonNullishType::IsSupertypeOf([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *source) +{ + relation->Result(false); +} + +void ETSNonNullishType::IsSubtypeOf([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *target) +{ + if (relation->IsSupertypeOf(target, GetUnderlying())) { + return; + } + + relation->Result(false); +} + +Type *ETSNonNullishType::Substitute([[maybe_unused]] TypeRelation *relation, const Substitution *substitution) +{ + auto *substituted = GetUnderlying()->Substitute(relation, substitution); + if (substituted == GetUnderlying()) { + return this; + } + return relation->GetChecker()->AsETSChecker()->GetNonNullishType(substituted); +} + +void ETSNonNullishType::ToAssemblerType(std::stringstream &ss) const +{ + GetUnderlying()->ToAssemblerTypeWithRank(ss); +} + +void ETSNonNullishType::ToDebugInfoType(std::stringstream &ss) const +{ + GetUnderlying()->ToDebugInfoType(ss); +} + +Type *ETSNonNullishType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, + [[maybe_unused]] TypeRelation *relation, + [[maybe_unused]] GlobalTypesHolder *globalTypes) +{ + return allocator->New(GetUnderlying()); +} + +} // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsNonNullishType.h b/ets2panda/checker/types/ets/etsNonNullishType.h new file mode 100644 index 0000000000000000000000000000000000000000..6f9119d266139013bc14325f2fea4fe00e3bc63d --- /dev/null +++ b/ets2panda/checker/types/ets/etsNonNullishType.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_COMPILER_CHECKER_TYPES_ETS_NON_NULLISH_TYPE_H +#define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_NON_NULLISH_TYPE_H + +#include "checker/types/type.h" +#include "ir/astNode.h" + +namespace panda::es2panda::checker { + +class ETSNonNullishType : public Type { +public: + explicit ETSNonNullishType(ETSTypeParameter *tparam) : Type(TypeFlag::ETS_NONNULLISH), tparam_(tparam) {} + + ETSTypeParameter *GetUnderlying() const + { + return tparam_; + } + + void Identical(TypeRelation *relation, Type *other) override; + void AssignmentTarget(TypeRelation *relation, Type *source) override; + bool AssignmentSource(TypeRelation *relation, Type *target) override; + void Cast(TypeRelation *relation, Type *target) override; + void CastTarget(TypeRelation *relation, Type *source) override; + void IsSupertypeOf(TypeRelation *relation, Type *source) override; + void IsSubtypeOf(TypeRelation *relation, Type *target) override; + Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; + + void ToString(std::stringstream &ss, bool precise) const override; + void ToAssemblerType(std::stringstream &ss) const override; + void ToDebugInfoType(std::stringstream &ss) const override; + + Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; + +private: + ETSTypeParameter *const tparam_; +}; + +} // namespace panda::es2panda::checker + +#endif diff --git a/ets2panda/checker/types/ets/etsNullishTypes.cpp b/ets2panda/checker/types/ets/etsNullishTypes.cpp new file mode 100644 index 0000000000000000000000000000000000000000..910da401578a4990556060a77a691d8eb67b6696 --- /dev/null +++ b/ets2panda/checker/types/ets/etsNullishTypes.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "etsNullishTypes.h" +#include "etsTypeParameter.h" +#include "ir/expressions/identifier.h" +#include "ir/ts/tsTypeParameter.h" +#include "checker/ETSchecker.h" +#include "checker/ets/conversion.h" + +namespace panda::es2panda::checker { + +void ETSNullType::Identical(TypeRelation *relation, Type *other) +{ + relation->Result(other->IsETSNullType()); +} + +void ETSNullType::AssignmentTarget(TypeRelation *relation, Type *source) +{ + Identical(relation, source); +} + +bool ETSNullType::AssignmentSource(TypeRelation *relation, Type *target) +{ + return relation->IsSupertypeOf(target, this); +} + +void ETSNullType::Compare([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other) +{ + UNREACHABLE(); +} + +void ETSNullType::Cast(TypeRelation *relation, Type *target) +{ + Identical(relation, target); +} + +void ETSNullType::CastTarget(TypeRelation *relation, Type *source) +{ + relation->IsSupertypeOf(source, this); +} + +void ETSNullType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const +{ + ss << "null"; +} + +void ETSNullType::ToAssemblerType(std::stringstream &ss) const +{ + ss << compiler::Signatures::BUILTIN_OBJECT; +} + +void ETSNullType::ToDebugInfoType(std::stringstream &ss) const +{ + ETSObjectType::DebugInfoTypeFromName(ss, compiler::Signatures::BUILTIN_OBJECT); +} + +Type *ETSNullType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, + [[maybe_unused]] GlobalTypesHolder *globalTypes) +{ + return allocator->New(); +} + +void ETSUndefinedType::Identical(TypeRelation *relation, Type *other) +{ + relation->Result(other->IsETSUndefinedType()); +} + +void ETSUndefinedType::AssignmentTarget(TypeRelation *relation, Type *source) +{ + Identical(relation, source); +} + +bool ETSUndefinedType::AssignmentSource(TypeRelation *relation, Type *target) +{ + return relation->IsSupertypeOf(target, this); +} + +void ETSUndefinedType::Compare([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other) +{ + UNREACHABLE(); +} + +void ETSUndefinedType::Cast(TypeRelation *relation, Type *target) +{ + Identical(relation, target); +} + +void ETSUndefinedType::CastTarget(TypeRelation *relation, Type *source) +{ + relation->IsSupertypeOf(source, this); +} + +void ETSUndefinedType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const +{ + ss << "undefined"; +} + +void ETSUndefinedType::ToAssemblerType(std::stringstream &ss) const +{ + ss << compiler::Signatures::BUILTIN_OBJECT; +} + +void ETSUndefinedType::ToDebugInfoType(std::stringstream &ss) const +{ + ETSObjectType::DebugInfoTypeFromName(ss, compiler::Signatures::BUILTIN_OBJECT); +} + +Type *ETSUndefinedType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, + [[maybe_unused]] GlobalTypesHolder *globalTypes) +{ + return allocator->New(); +} + +} // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsNullishTypes.h b/ets2panda/checker/types/ets/etsNullishTypes.h new file mode 100644 index 0000000000000000000000000000000000000000..898430dcd1fbacf5ffda68ce4ceb18ef6e4bb168 --- /dev/null +++ b/ets2panda/checker/types/ets/etsNullishTypes.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_COMPILER_CHECKER_TYPES_ETS_NULLISH_TYPE_H +#define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_NULLISH_TYPE_H + +#include "checker/types/type.h" +#include "ir/astNode.h" + +namespace panda::es2panda::checker { + +class ETSNullType : public Type { +public: + ETSNullType() : Type(TypeFlag::ETS_NULL) {} + + void Identical(TypeRelation *relation, Type *other) override; + void AssignmentTarget(TypeRelation *relation, Type *source) override; + bool AssignmentSource(TypeRelation *relation, Type *target) override; + void Compare(TypeRelation *relation, Type *other) override; + void Cast(TypeRelation *relation, Type *target) override; + void CastTarget(TypeRelation *relation, Type *source) override; + + void ToString(std::stringstream &ss, bool precise) const override; + void ToAssemblerType(std::stringstream &ss) const override; + void ToDebugInfoType([[maybe_unused]] std::stringstream &ss) const override; + + Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; +}; + +class ETSUndefinedType : public Type { +public: + ETSUndefinedType() : Type(TypeFlag::ETS_UNDEFINED) {} + + void Identical(TypeRelation *relation, Type *other) override; + void AssignmentTarget(TypeRelation *relation, Type *source) override; + bool AssignmentSource(TypeRelation *relation, Type *target) override; + void Compare(TypeRelation *relation, Type *other) override; + void Cast(TypeRelation *relation, Type *target) override; + void CastTarget(TypeRelation *relation, Type *source) override; + + void ToString(std::stringstream &ss, bool precise) const override; + void ToAssemblerType(std::stringstream &ss) const override; + void ToDebugInfoType([[maybe_unused]] std::stringstream &ss) const override; + + Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; +}; + +} // namespace panda::es2panda::checker + +#endif diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 5891c506419167fd360e3a1807ec48e13b105b0c..7da7354486500429441c39325c974229fcc14f30 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -281,14 +281,12 @@ ArenaMap ETSObjectType::Coll return propMap; } -void ETSObjectType::ToString(std::stringstream &ss) const +void ETSObjectType::ToString(std::stringstream &ss, bool precise) const { if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { - if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && - !name_.Empty()) { - ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS); - } - GetFunctionalInterfaceInvokeType()->ToString(ss); + GetFunctionalInterfaceInvokeType()->ToString(ss, precise); + } else if (precise) { + ss << assemblerName_; // NOTE(gogabr): need full qualified name } else { ss << name_; } @@ -296,7 +294,7 @@ void ETSObjectType::ToString(std::stringstream &ss) const if (!typeArguments_.empty()) { ss << compiler::Signatures::GENERIC_BEGIN; for (auto arg = typeArguments_.cbegin(); arg != typeArguments_.cend(); ++arg) { - (*arg)->ToString(ss); + (*arg)->ToString(ss, precise); if (next(arg) != typeArguments_.cend()) { ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_COMMA); @@ -304,24 +302,9 @@ void ETSObjectType::ToString(std::stringstream &ss) const } ss << compiler::Signatures::GENERIC_END; } - - if (IsNullish() && this != GetConstOriginalBaseType() && !name_.Is("NullType") && !IsETSNullLike() && - !name_.Empty()) { - if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { - ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); - } - if (ContainsNull()) { - ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) - << lexer::TokenToString(lexer::TokenType::LITERAL_NULL); - } - if (ContainsUndefined()) { - ss << lexer::TokenToString(lexer::TokenType::PUNCTUATOR_BITWISE_OR) - << lexer::TokenToString(lexer::TokenType::KEYW_UNDEFINED); - } - } } -void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other) +void ETSObjectType::IdenticalUptoTypeArguments(TypeRelation *relation, Type *other) { relation->Result(false); if (!other->IsETSObjectType() || !CheckIdenticalFlags(other->AsETSObjectType()->ObjectFlags())) { @@ -339,57 +322,33 @@ void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other return; } - auto const otherTypeArguments = other->AsETSObjectType()->TypeArguments(); - - if (HasTypeFlag(TypeFlag::GENERIC) || IsNullish()) { - if (!HasTypeFlag(TypeFlag::GENERIC)) { - relation->Result(true); - return; - } - if (typeArguments_.empty() != otherTypeArguments.empty()) { - return; - } + auto const sourceTypeArguments = other->AsETSObjectType()->TypeArguments(); + if (typeArguments_.empty() != sourceTypeArguments.empty()) { + return; + } - auto const argsNumber = typeArguments_.size(); - ASSERT(argsNumber == otherTypeArguments.size()); + relation->Result(true); +} - for (size_t idx = 0U; idx < argsNumber; ++idx) { - if (typeArguments_[idx]->IsWildcardType() || otherTypeArguments[idx]->IsWildcardType()) { - continue; - } +void ETSObjectType::Identical(TypeRelation *relation, Type *other) +{ + IdenticalUptoTypeArguments(relation, other); - // checking the nullishness of type args before getting their original base types - // because most probably GetOriginalBaseType will return the non-nullish version of the type - if (!typeArguments_[idx]->IsNullish() && otherTypeArguments[idx]->IsNullish()) { - return; - } + if (!relation->IsTrue() || !HasTypeFlag(TypeFlag::GENERIC)) { + return; + } - const auto getOriginalBaseTypeOrType = [&relation](Type *const originalType) { - auto *const baseType = relation->GetChecker()->AsETSChecker()->GetOriginalBaseType(originalType); - return baseType == nullptr ? originalType : baseType; - }; + auto const otherTypeArguments = other->AsETSObjectType()->TypeArguments(); - auto *const typeArgType = getOriginalBaseTypeOrType(typeArguments_[idx]); - auto *const otherTypeArgType = getOriginalBaseTypeOrType(otherTypeArguments[idx]); + auto const argsNumber = typeArguments_.size(); + ASSERT(argsNumber == otherTypeArguments.size()); - typeArgType->Identical(relation, otherTypeArgType); - if (!relation->IsTrue()) { - return; - } + for (size_t idx = 0U; idx < argsNumber; ++idx) { + if (typeArguments_[idx]->IsWildcardType() || otherTypeArguments[idx]->IsWildcardType()) { + continue; } - } else { - if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { - auto getInvokeSignature = [](const ETSObjectType *type) { - auto const propInvoke = - type->GetProperty(util::StringView("invoke"), PropertySearchFlags::SEARCH_INSTANCE_METHOD); - ASSERT(propInvoke != nullptr); - return propInvoke->TsType()->AsETSFunctionType()->CallSignatures()[0]; - }; - - auto *const thisInvokeSignature = getInvokeSignature(this); - auto *const otherInvokeSignature = getInvokeSignature(other->AsETSObjectType()); - - relation->IsIdenticalTo(thisInvokeSignature, otherInvokeSignature); + typeArguments_[idx]->Identical(relation, otherTypeArguments[idx]); + if (!relation->IsTrue()) { return; } } @@ -397,14 +356,6 @@ void ETSObjectType::IdenticalUptoNullability(TypeRelation *relation, Type *other relation->Result(true); } -void ETSObjectType::Identical(TypeRelation *relation, Type *other) -{ - if ((ContainsNull() != other->ContainsNull()) || (ContainsUndefined() != other->ContainsUndefined())) { - return; - } - IdenticalUptoNullability(relation, other); -} - bool ETSObjectType::CheckIdenticalFlags(const ETSObjectFlags target) const { constexpr auto FLAGS_TO_REMOVE = ETSObjectFlags::COMPLETELY_RESOLVED | ETSObjectFlags::INCOMPLETE_INSTANTIATION | @@ -420,33 +371,21 @@ bool ETSObjectType::CheckIdenticalFlags(const ETSObjectFlags target) const return cleanedSelfFlags == cleanedTargetFlags; } -bool ETSObjectType::AssignmentSource(TypeRelation *const relation, Type *const target) +bool ETSObjectType::AssignmentSource(TypeRelation *const relation, [[maybe_unused]] Type *const target) { - relation->Result((IsETSNullType() && target->ContainsNull()) || - (IsETSUndefinedType() && target->ContainsUndefined())); - - return relation->IsTrue(); + return relation->Result(false); } void ETSObjectType::AssignmentTarget(TypeRelation *const relation, Type *source) { - if (source->IsETSNullType()) { - relation->Result(ContainsNull()); - return; - } - if (source->IsETSUndefinedType()) { - relation->Result(ContainsUndefined()); - return; - } - - if ((source->ContainsNull() && !ContainsNull()) || (source->ContainsUndefined() && !ContainsUndefined())) { - return; - } - if (HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { EnsurePropertiesInstantiated(); - auto found = properties_[static_cast(PropertyType::INSTANCE_METHOD)].find("invoke"); + auto found = properties_[static_cast(PropertyType::INSTANCE_METHOD)].find( + FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME); ASSERT(found != properties_[static_cast(PropertyType::INSTANCE_METHOD)].end()); + if (source->IsETSFunctionType()) { + source = source->AsETSFunctionType()->BoxPrimitives(relation->GetChecker()->AsETSChecker()); + } relation->IsAssignableTo(source, found->second->TsType()); return; } @@ -474,10 +413,14 @@ bool ETSObjectType::CastWideningNarrowing(TypeRelation *const relation, Type *co bool ETSObjectType::CastNumericObject(TypeRelation *const relation, Type *const target) { - if (this->IsNullish()) { + if (!target->HasTypeFlag(TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT | TypeFlag::LONG | + TypeFlag::FLOAT | TypeFlag::DOUBLE | TypeFlag::ETS_BOOLEAN)) { return false; } - + Identical(relation, target); + if (relation->IsTrue()) { + return true; + } if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_BYTE)) { if (target->HasTypeFlag(TypeFlag::BYTE)) { conversion::Unboxing(relation, this); @@ -493,63 +436,42 @@ bool ETSObjectType::CastNumericObject(TypeRelation *const relation, Type *const return true; } } - TypeFlag unboxFlags = TypeFlag::NONE; - TypeFlag wideningFlags = TypeFlag::NONE; - TypeFlag narrowingFlags = TypeFlag::NONE; - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_SHORT)) { - unboxFlags = TypeFlag::SHORT; - wideningFlags = TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE; - narrowingFlags = TypeFlag::BYTE | TypeFlag::CHAR; - if (CastWideningNarrowing(relation, target, unboxFlags, wideningFlags, narrowingFlags)) { - return true; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_SHORT) && + CastWideningNarrowing(relation, target, TypeFlag::SHORT, + TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE, + TypeFlag::BYTE | TypeFlag::CHAR)) { + return true; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_CHAR)) { - unboxFlags = TypeFlag::CHAR; - wideningFlags = TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE; - narrowingFlags = TypeFlag::BYTE | TypeFlag::SHORT; - if (CastWideningNarrowing(relation, target, unboxFlags, wideningFlags, narrowingFlags)) { - return true; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_CHAR) && + CastWideningNarrowing(relation, target, TypeFlag::CHAR, + TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE, + TypeFlag::BYTE | TypeFlag::SHORT)) { + return true; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_INT)) { - unboxFlags = TypeFlag::INT; - wideningFlags = TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE; - narrowingFlags = TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR; - if (CastWideningNarrowing(relation, target, unboxFlags, wideningFlags, narrowingFlags)) { - return true; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_INT) && + CastWideningNarrowing(relation, target, TypeFlag::INT, TypeFlag::LONG | TypeFlag::FLOAT | TypeFlag::DOUBLE, + TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR)) { + return true; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_LONG)) { - unboxFlags = TypeFlag::LONG; - wideningFlags = TypeFlag::FLOAT | TypeFlag::DOUBLE; - narrowingFlags = TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT; - if (CastWideningNarrowing(relation, target, unboxFlags, wideningFlags, narrowingFlags)) { - return true; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_LONG) && + CastWideningNarrowing(relation, target, TypeFlag::LONG, TypeFlag::FLOAT | TypeFlag::DOUBLE, + TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT)) { + return true; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_FLOAT)) { - unboxFlags = TypeFlag::FLOAT; - wideningFlags = TypeFlag::DOUBLE; - narrowingFlags = TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT | TypeFlag::LONG; - if (CastWideningNarrowing(relation, target, unboxFlags, wideningFlags, narrowingFlags)) { - return true; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_FLOAT) && + CastWideningNarrowing(relation, target, TypeFlag::FLOAT, TypeFlag::DOUBLE, + TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT | TypeFlag::LONG)) { + return true; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_DOUBLE)) { - unboxFlags = TypeFlag::DOUBLE; - wideningFlags = TypeFlag::NONE; - narrowingFlags = + if (auto narrowingFlags = TypeFlag::BYTE | TypeFlag::SHORT | TypeFlag::CHAR | TypeFlag::INT | TypeFlag::LONG | TypeFlag::FLOAT; - if (CastWideningNarrowing(relation, target, unboxFlags, wideningFlags, narrowingFlags)) { - return true; - } + this->HasObjectFlag(ETSObjectFlags::BUILTIN_DOUBLE) && + CastWideningNarrowing(relation, target, TypeFlag::DOUBLE, TypeFlag::NONE, narrowingFlags)) { + return true; } - if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_BOOLEAN)) { - if (target->HasTypeFlag(TypeFlag::ETS_BOOLEAN)) { - conversion::Unboxing(relation, this); - return true; - } + if (this->HasObjectFlag(ETSObjectFlags::BUILTIN_BOOLEAN) && target->HasTypeFlag(TypeFlag::ETS_BOOLEAN)) { + conversion::Unboxing(relation, this); + return true; } if (this->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE)) { if (target->HasTypeFlag(TypeFlag::ETS_OBJECT)) { @@ -584,17 +506,6 @@ void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) return; } - if (this->IsETSNullLike()) { - if (target->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { - relation->GetNode()->SetTsType(target); - relation->Result(true); - return; - } - - conversion::Forbidden(relation); - return; - } - if (CastNumericObject(relation, target)) { return; } @@ -622,6 +533,8 @@ void ETSObjectType::Cast(TypeRelation *const relation, Type *const target) bool ETSObjectType::DefaultObjectTypeChecks(const ETSChecker *const etsChecker, TypeRelation *const relation, Type *const source) { + relation->Result(false); + // 3.8.3 Subtyping among Array Types auto const *const base = GetConstOriginalBaseType(); if (base == etsChecker->GlobalETSObjectType() && source->IsETSArrayType()) { @@ -635,21 +548,20 @@ bool ETSObjectType::DefaultObjectTypeChecks(const ETSChecker *const etsChecker, } if (!source->IsETSObjectType() || - !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::CLASS | ETSObjectFlags::INTERFACE | - ETSObjectFlags::NULL_TYPE)) { + !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::CLASS | ETSObjectFlags::INTERFACE)) { return true; } - if ((!ContainsNull() && source->ContainsNull()) || (!ContainsUndefined() && source->ContainsUndefined())) { - return true; - } // All classes and interfaces are subtypes of Object - if (base == etsChecker->GlobalETSObjectType() || base == etsChecker->GlobalETSNullishObjectType()) { + if (base == etsChecker->GlobalETSObjectType()) { relation->Result(true); return true; } - IdenticalUptoNullability(relation, source); + Identical(relation, source); + if (relation->IsTrue() && HasTypeFlag(TypeFlag::GENERIC)) { + IsGenericSupertypeOf(relation, source); + } return relation->IsTrue(); } @@ -658,17 +570,6 @@ void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) relation->Result(false); auto *const etsChecker = relation->GetChecker()->AsETSChecker(); - if (source->IsETSUnionType()) { - bool res = std::all_of(source->AsETSUnionType()->ConstituentTypes().begin(), - source->AsETSUnionType()->ConstituentTypes().end(), [this, relation](Type *ct) { - relation->Result(false); - IsSupertypeOf(relation, ct); - return relation->IsTrue(); - }); - relation->Result(res); - return; - } - if (DefaultObjectTypeChecks(etsChecker, relation, source)) { return; } @@ -689,6 +590,51 @@ void ETSObjectType::IsSupertypeOf(TypeRelation *relation, Type *source) } } +void ETSObjectType::IsGenericSupertypeOf(TypeRelation *relation, Type *source) +{ + ASSERT(HasTypeFlag(TypeFlag::GENERIC)); + + auto *sourceType = source->AsETSObjectType(); + auto const sourceTypeArguments = sourceType->TypeArguments(); + ASSERT(typeArguments_.size() == sourceTypeArguments.size()); + + ASSERT(declNode_ == sourceType->GetDeclNode()); + + auto *typeParamsDecl = GetTypeParams(); + ASSERT(typeParamsDecl != nullptr || typeArguments_.empty()); + + if (typeParamsDecl == nullptr) { + return; + } + + auto &typeParams = typeParamsDecl->Params(); + ASSERT(typeParams.size() == typeArguments_.size()); + + for (size_t idx = 0; idx < typeArguments_.size(); idx++) { + auto *typeArg = typeArguments_[idx]; + auto *sourceTypeArg = sourceTypeArguments[idx]; + auto *typeParam = typeParams[idx]; + + relation->Result(false); + + if (!(typeArg->IsWildcardType() || sourceTypeArg->IsWildcardType())) { + if (typeParam->IsOut()) { + typeArg->IsSupertypeOf(relation, sourceTypeArg); + } else if (typeParam->IsIn()) { + sourceTypeArg->IsSupertypeOf(relation, typeArg); + } else { + typeArg->Identical(relation, sourceTypeArg); + } + + if (!relation->IsTrue()) { + return; + } + } + } + + relation->Result(true); +} + Type *ETSObjectType::AsSuper(Checker *checker, varbinder::Variable *sourceVar) { if (sourceVar == nullptr) { @@ -761,7 +707,7 @@ Type *ETSObjectType::Instantiate(ArenaAllocator *const allocator, TypeRelation * std::lock_guard guard {*checker->Mutex()}; auto *const base = GetOriginalBaseType(); - if (!relation->TypeInstantiationPossible(base) || IsETSNullLike()) { + if (!relation->TypeInstantiationPossible(base)) { return this; } relation->IncreaseTypeRecursionCount(base); @@ -845,7 +791,7 @@ void ETSObjectType::SetCopiedTypeProperties(TypeRelation *const relation, ETSObj copiedType->substitution_ = substitution; } -Type *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *substitution) +ETSObjectType *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *substitution, bool cache) { if (substitution == nullptr || substitution->empty()) { return this; @@ -864,18 +810,23 @@ Type *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *subs } const util::StringView hash = checker->GetHashFromSubstitution(substitution); - if (auto *inst = GetInstantiatedType(hash); inst != nullptr) { - return inst; + if (cache) { + if (auto *inst = GetInstantiatedType(hash); inst != nullptr) { + return inst; + } } - if (!relation->TypeInstantiationPossible(base) || IsETSNullLike()) { + if (!relation->TypeInstantiationPossible(base)) { return this; } relation->IncreaseTypeRecursionCount(base); auto *const copiedType = checker->CreateNewETSObjectType(name_, declNode_, flags_); SetCopiedTypeProperties(relation, copiedType, newTypeArgs, substitution); - GetInstantiationMap().try_emplace(hash, copiedType); + + if (cache) { + GetInstantiationMap().try_emplace(hash, copiedType); + } if (superType_ != nullptr) { copiedType->SetSuperType(superType_->Substitute(relation, substitution)->AsETSObjectType()); @@ -890,6 +841,11 @@ Type *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *subs return copiedType; } +ETSObjectType *ETSObjectType::Substitute(TypeRelation *relation, const Substitution *substitution) +{ + return Substitute(relation, substitution, true); +} + void ETSObjectType::InstantiateProperties() const { if (baseType_ == nullptr || baseType_ == this) { diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index c59e37eb679af296ad1c42556dfef7ddd35f646d..c87307d89203746886fa0212ec25884854993bad 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -39,14 +39,12 @@ enum class ETSObjectFlags : uint32_t { RESOLVED_SUPER = 1U << 9U, RESOLVED_TYPE_PARAMS = 1U << 10U, CHECKED_COMPATIBLE_ABSTRACTS = 1U << 11U, - NULL_TYPE = 1U << 12U, - STRING = 1U << 13U, - INCOMPLETE_INSTANTIATION = 1U << 14U, - INNER = 1U << 15U, - DYNAMIC = 1U << 16U, - ASYNC_FUNC_RETURN_TYPE = 1U << 17U, - CHECKED_INVOKE_LEGITIMACY = 1U << 18U, - UNDEFINED_TYPE = 1U << 19U, + STRING = 1U << 12U, + INCOMPLETE_INSTANTIATION = 1U << 13U, + INNER = 1U << 14U, + DYNAMIC = 1U << 15U, + ASYNC_FUNC_RETURN_TYPE = 1U << 16U, + CHECKED_INVOKE_LEGITIMACY = 1U << 17U, BUILTIN_BIGINT = 1U << 22U, BUILTIN_STRING = 1U << 23U, @@ -112,6 +110,9 @@ enum class PropertyType { COUNT, }; +/* Invoke method name in functional interfaces */ +constexpr char const *FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME = "invoke0"; + class ETSObjectType : public Type { public: using PropertyMap = ArenaUnorderedMap; @@ -293,6 +294,11 @@ public: return const_cast(GetConstOriginalBaseType()); } + bool IsGlobalETSObjectType() const noexcept + { + return superType_ == nullptr; + } + bool IsPropertyInherited(const varbinder::Variable *var) { if (var->HasFlag(varbinder::VariableFlags::PRIVATE)) { @@ -392,7 +398,7 @@ public: ETSFunctionType *GetFunctionalInterfaceInvokeType() const { ASSERT(HasObjectFlag(ETSObjectFlags::FUNCTIONAL)); - auto *invoke = GetOwnProperty("invoke"); + auto *invoke = GetOwnProperty(FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME); ASSERT(invoke && invoke->TsType() && invoke->TsType()->IsETSFunctionType()); return invoke->TsType()->AsETSFunctionType(); } @@ -414,17 +420,11 @@ public: varbinder::Scope *GetTypeArgumentScope() const { - if (HasObjectFlag(ETSObjectFlags::ENUM) || !HasTypeFlag(TypeFlag::GENERIC)) { + auto *typeParams = GetTypeParams(); + if (typeParams == nullptr) { return nullptr; } - - if (HasObjectFlag(ETSObjectFlags::CLASS)) { - ASSERT(declNode_->IsClassDefinition() && declNode_->AsClassDefinition()->TypeParams()); - return declNode_->AsClassDefinition()->TypeParams()->Scope(); - } - - ASSERT(declNode_->IsTSInterfaceDeclaration() && declNode_->AsTSInterfaceDeclaration()->TypeParams()); - return declNode_->AsTSInterfaceDeclaration()->TypeParams()->Scope(); + return typeParams->Scope(); } InstantiationMap &GetInstantiationMap() @@ -471,7 +471,7 @@ public: bool CheckIdenticalVariable(varbinder::Variable *otherVar) const; void Iterate(const PropertyTraverser &cb) const; - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; @@ -479,7 +479,8 @@ public: bool SubstituteTypeArgs(TypeRelation *relation, ArenaVector &newTypeArgs, const Substitution *substitution); void SetCopiedTypeProperties(TypeRelation *relation, ETSObjectType *copiedType, ArenaVector &newTypeArgs, const Substitution *substitution); - Type *Substitute(TypeRelation *relation, const Substitution *substitution) override; + ETSObjectType *Substitute(TypeRelation *relation, const Substitution *substitution) override; + ETSObjectType *Substitute(TypeRelation *relation, const Substitution *substitution, bool cache); void Cast(TypeRelation *relation, Type *target) override; bool CastNumericObject(TypeRelation *relation, Type *target); bool DefaultObjectTypeChecks(const ETSChecker *etsChecker, TypeRelation *relation, Type *source); @@ -546,9 +547,25 @@ private: } } ArenaMap CollectAllProperties() const; - void IdenticalUptoNullability(TypeRelation *relation, Type *other); bool CastWideningNarrowing(TypeRelation *relation, Type *target, TypeFlag unboxFlags, TypeFlag wideningFlags, TypeFlag narrowingFlags); + void IdenticalUptoTypeArguments(TypeRelation *relation, Type *other); + void IsGenericSupertypeOf(TypeRelation *relation, Type *source); + + ir::TSTypeParameterDeclaration *GetTypeParams() const + { + if (HasObjectFlag(ETSObjectFlags::ENUM) || !HasTypeFlag(TypeFlag::GENERIC)) { + return nullptr; + } + + if (HasObjectFlag(ETSObjectFlags::CLASS)) { + ASSERT(declNode_->IsClassDefinition() && declNode_->AsClassDefinition()->TypeParams()); + return declNode_->AsClassDefinition()->TypeParams(); + } + + ASSERT(declNode_->IsTSInterfaceDeclaration() && declNode_->AsTSInterfaceDeclaration()->TypeParams()); + return declNode_->AsTSInterfaceDeclaration()->TypeParams(); + } ArenaAllocator *allocator_; util::StringView name_; diff --git a/ets2panda/checker/types/ets/etsStringType.h b/ets2panda/checker/types/ets/etsStringType.h index afc3c2dd9f195b96c20f502cc49e7aea94894c18..0d51dc03510d1a6c774bb80b5a550798ba64f4eb 100644 --- a/ets2panda/checker/types/ets/etsStringType.h +++ b/ets2panda/checker/types/ets/etsStringType.h @@ -43,12 +43,12 @@ public: void AssignmentTarget(TypeRelation *relation, Type *source) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << lexer::TokenToString(lexer::TokenType::KEYW_STRING); } - void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const override + void ToAssemblerType(std::stringstream &ss) const override { ss << compiler::Signatures::BUILTIN_STRING; } @@ -60,10 +60,6 @@ public: std::tuple ResolveConditionExpr() const override { - if (IsNullish()) { - return {false, false}; - } - return {IsConstantType(), IsConstantType() ? (GetValue().Length() != 0) : false}; } diff --git a/ets2panda/checker/types/ets/etsTupleType.cpp b/ets2panda/checker/types/ets/etsTupleType.cpp index 1f79e6f99724de0d5f1c2820f9543ee17b0e1085..03a39cbe622050a33629f646db437f63c33dda48 100644 --- a/ets2panda/checker/types/ets/etsTupleType.cpp +++ b/ets2panda/checker/types/ets/etsTupleType.cpp @@ -20,12 +20,12 @@ #include "ir/ets/etsTuple.h" namespace panda::es2panda::checker { -void ETSTupleType::ToString(std::stringstream &ss) const +void ETSTupleType::ToString(std::stringstream &ss, bool precise) const { ss << "["; for (auto it = typeList_.begin(); it != typeList_.end(); it++) { - (*it)->ToString(ss); + (*it)->ToString(ss, precise); if (std::next(it) != typeList_.end()) { ss << ", "; @@ -34,7 +34,7 @@ void ETSTupleType::ToString(std::stringstream &ss) const if (spreadType_ != nullptr) { ss << ", ..."; - spreadType_->ToString(ss); + spreadType_->ToString(ss, precise); ss << "[]"; } @@ -147,7 +147,7 @@ Type *ETSTupleType::Substitute(TypeRelation *relation, const Substitution *subst } auto *newSpreadType = spreadType_ == nullptr ? nullptr : spreadType_->Substitute(relation, substitution); - auto *newElementType = ir::ETSTuple::CalculateLUBForTuple(checker, newTypeList, newSpreadType); + auto *newElementType = ir::ETSTuple::CalculateLUBForTuple(checker, newTypeList, &newSpreadType); return checker->Allocator()->New(std::move(newTypeList), newElementType, newSpreadType); } diff --git a/ets2panda/checker/types/ets/etsTupleType.h b/ets2panda/checker/types/ets/etsTupleType.h index 249dbe58cfb3991dfd171a6c4a632c3d61f7946d..9e593cc3f5e639b9ba565e768d09c2df1dd7ab96 100644 --- a/ets2panda/checker/types/ets/etsTupleType.h +++ b/ets2panda/checker/types/ets/etsTupleType.h @@ -58,7 +58,7 @@ public: return size_ + (spreadType_ == nullptr ? 0 : 1); } - [[nodiscard]] ArenaVector GetTupleTypesList() const + [[nodiscard]] ArenaVector const &GetTupleTypesList() const { return typeList_; } @@ -80,7 +80,7 @@ public: [[nodiscard]] Type *GetTypeAtIndex(int32_t index) const; - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; @@ -90,7 +90,7 @@ public: Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; private: - ArenaVector typeList_; + ArenaVector const typeList_; Type *spreadType_ {}; TupleSizeType size_ {0}; }; diff --git a/ets2panda/checker/types/ets/etsTypeParameter.cpp b/ets2panda/checker/types/ets/etsTypeParameter.cpp index 302f9ce42f07b11e4d28b92ba3813ebca9ab2544..dab20d6ff05c86bb8f65d88a49ed47a5ba30f2ad 100644 --- a/ets2panda/checker/types/ets/etsTypeParameter.cpp +++ b/ets2panda/checker/types/ets/etsTypeParameter.cpp @@ -20,26 +20,19 @@ #include "checker/ets/conversion.h" namespace panda::es2panda::checker { -void ETSTypeParameter::ToString(std::stringstream &ss) const -{ - ss << declNode_->Name()->Name(); - if (IsNullish()) { - if (ContainsNull()) { - ss << "|null"; - } - if (ContainsUndefined()) { - ss << "|undefined"; - } +void ETSTypeParameter::ToString(std::stringstream &ss, bool precise) const +{ + // Need source file name to avoid clashes + if (precise) { + ss << declNode_->Range().start.index << "." << declNode_->Range().start.line << "."; } + ss << declNode_->Name()->Name(); } void ETSTypeParameter::Identical([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *other) { - if ((ContainsNull() != other->ContainsNull()) || (ContainsUndefined() != other->ContainsUndefined())) { - return; - } - + relation->Result(false); if (other->IsETSTypeParameter() && other->AsETSTypeParameter()->GetOriginal() == GetOriginal()) { relation->Result(true); } @@ -52,19 +45,6 @@ bool ETSTypeParameter::AssignmentSource([[maybe_unused]] TypeRelation *relation, void ETSTypeParameter::AssignmentTarget([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] Type *source) { - if (source->IsETSNullType()) { - relation->Result(ContainsNull()); - return; - } - if (source->IsETSUndefinedType()) { - relation->Result(ContainsUndefined()); - return; - } - - if ((source->ContainsNull() && !ContainsNull()) || (source->ContainsUndefined() && !ContainsUndefined())) { - relation->Result(false); - return; - } if (source->IsETSTypeParameter() && source->AsETSTypeParameter()->GetOriginal() == GetOriginal()) { relation->Result(true); return; @@ -125,38 +105,20 @@ Type *ETSTypeParameter::Instantiate([[maybe_unused]] ArenaAllocator *allocator, return copiedType; } -Type *ETSTypeParameter::Substitute(TypeRelation *relation, const Substitution *substitution) +Type *ETSTypeParameter::Substitute([[maybe_unused]] TypeRelation *relation, const Substitution *substitution) { if (substitution == nullptr || substitution->empty()) { return this; } - auto *const checker = relation->GetChecker()->AsETSChecker(); - auto *original = GetOriginal(); - if (auto repl = substitution->find(original); repl != substitution->end()) { - auto *replType = repl->second; - /* Any other flags we need to copy? */ - - /* The check this != base is a kludge to distinguish bare type parameter T - with a nullish constraint (like the default Object?) from explicitly nullish T? - */ - if (this != original && ((ContainsNull() && !replType->ContainsNull()) || - (ContainsUndefined() && !replType->ContainsUndefined()))) { - // this type is explicitly marked as nullish - ASSERT(ETSChecker::IsReferenceType(replType)); - auto nullishFlags = TypeFlag(TypeFlags() & TypeFlag::NULLISH); - auto *newReplType = checker->CreateNullishType(replType, nullishFlags, checker->Allocator(), relation, - checker->GetGlobalTypesHolder()); - replType = newReplType; - } - return replType; + if (auto repl = substitution->find(GetOriginal()); repl != substitution->end()) { + return repl->second; } - return this; } void ETSTypeParameter::ToAssemblerType(std::stringstream &ss) const { - GetConstraintType()->ToAssemblerType(ss); + GetConstraintType()->ToAssemblerTypeWithRank(ss); } void ETSTypeParameter::ToDebugInfoType(std::stringstream &ss) const diff --git a/ets2panda/checker/types/ets/etsTypeParameter.h b/ets2panda/checker/types/ets/etsTypeParameter.h index 63dabb1358eb560a44e56b955f5b8b66028ecff8..f32f0305db571acec465052aa4120bb74c423f7e 100644 --- a/ets2panda/checker/types/ets/etsTypeParameter.h +++ b/ets2panda/checker/types/ets/etsTypeParameter.h @@ -61,7 +61,7 @@ public: return constraint_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; diff --git a/ets2panda/checker/types/ets/etsUnionType.cpp b/ets2panda/checker/types/ets/etsUnionType.cpp index b23981aed59051ab16f3c0313bcc6b9101fdcd90..9c24dbb6c80b6d0736147e1978334102ab3baf73 100644 --- a/ets2panda/checker/types/ets/etsUnionType.cpp +++ b/ets2panda/checker/types/ets/etsUnionType.cpp @@ -14,6 +14,7 @@ */ #include +#include #include "etsUnionType.h" #include "checker/ets/conversion.h" @@ -22,10 +23,10 @@ #include "ir/astNode.h" namespace panda::es2panda::checker { -void ETSUnionType::ToString(std::stringstream &ss) const +void ETSUnionType::ToString(std::stringstream &ss, bool precise) const { for (auto it = constituentTypes_.begin(); it != constituentTypes_.end(); it++) { - (*it)->ToString(ss); + (*it)->ToString(ss, precise); if (std::next(it) != constituentTypes_.end()) { ss << "|"; } @@ -34,19 +35,19 @@ void ETSUnionType::ToString(std::stringstream &ss) const void ETSUnionType::ToAssemblerType(std::stringstream &ss) const { - lubType_->ToAssemblerType(ss); + assemblerLub_->ToAssemblerTypeWithRank(ss); } void ETSUnionType::ToDebugInfoType(std::stringstream &ss) const { - lubType_->ToDebugInfoType(ss); + assemblerLub_->ToDebugInfoType(ss); } ETSUnionType::ETSUnionType(ETSChecker *checker, ArenaVector &&constituentTypes) : Type(TypeFlag::ETS_UNION), constituentTypes_(std::move(constituentTypes)) { ASSERT(constituentTypes_.size() > 1); - lubType_ = ComputeLUB(checker); + assemblerLub_ = ComputeAssemblerLUB(checker, this); } bool ETSUnionType::EachTypeRelatedToSomeType(TypeRelation *relation, ETSUnionType *source, ETSUnionType *target) @@ -61,17 +62,39 @@ bool ETSUnionType::TypeRelatedToSomeType(TypeRelation *relation, Type *source, E [relation, source](auto *t) { return relation->IsIdenticalTo(source, t); }); } -Type *ETSUnionType::ComputeLUB(ETSChecker *checker) const +// This function computes effective runtime representation of union type +Type *ETSUnionType::ComputeAssemblerLUB(ETSChecker *checker, ETSUnionType *un) { - auto lub = constituentTypes_.front(); - for (auto *t : constituentTypes_) { - if (!checker->IsReferenceType(t)) { + auto *const apparent = checker->GetApparentType(un); + if (!apparent->IsETSUnionType()) { + return apparent; + } + if (apparent != un) { + return apparent->AsETSUnionType()->assemblerLub_; + } + un = apparent->AsETSUnionType(); + + Type *lub = nullptr; + for (auto *t : un->ConstituentTypes()) { + ASSERT(t->IsETSReferenceType()); + if (t->IsETSNullType()) { + continue; + } + if (t->IsETSUndefinedType()) { return checker->GetGlobalTypesHolder()->GlobalETSObjectType(); } - if (t->IsETSObjectType() && t->AsETSObjectType()->SuperType() == nullptr) { + if (lub == nullptr) { + lub = t; + continue; + } + if (t->IsETSObjectType() && lub->IsETSObjectType()) { + lub = checker->GetClosestCommonAncestor(lub->AsETSObjectType(), t->AsETSObjectType()); + } else if (t->IsETSArrayType() && lub->IsETSArrayType()) { + // NOTE: can compute "common(lub, t)[]" + return checker->GetGlobalTypesHolder()->GlobalETSObjectType(); + } else { return checker->GetGlobalTypesHolder()->GlobalETSObjectType(); } - lub = checker->FindLeastUpperBound(lub, t); } return lub; } @@ -89,160 +112,215 @@ void ETSUnionType::Identical(TypeRelation *relation, Type *other) relation->Result(false); } -bool ETSUnionType::AssignmentSource(TypeRelation *relation, Type *target) +static void AmbiguousUnionOperation(TypeRelation *relation) { - for (auto *it : constituentTypes_) { - if (!relation->IsAssignableTo(it, target)) { - return false; + auto checker = relation->GetChecker()->AsETSChecker(); + if (!relation->NoThrow()) { + checker->ThrowTypeError({"Ambiguous union type operation"}, relation->GetNode()->Start()); + } + conversion::Forbidden(relation); +} + +template +void ETSUnionType::RelationSource(TypeRelation *relation, Type *target, RelFN const &relFn) +{ + auto *const checker = relation->GetChecker()->AsETSChecker(); + auto *const refTarget = checker->MaybePromotedBuiltinType(target); + + if (target != refTarget && !relation->ApplyUnboxing()) { + relation->Result(false); + return; + } + if (relation->IsSupertypeOf(refTarget, this)) { + if (refTarget != target) { + relation->GetNode()->SetBoxingUnboxingFlags(checker->GetUnboxingFlag(refTarget)); } + return; + } + if (target == refTarget) { + relation->Result(false); + return; } - return relation->Result(true); + int related = 0; + for (auto *ct : ConstituentTypes()) { // NOTE(vpukhov): just test if union is supertype of any numeric + if (!ct->IsETSUnboxableObject()) { + continue; + } + if (!relFn(relation, checker->MaybePrimitiveBuiltinType(ct), target)) { + continue; + } + relation->GetNode()->SetBoxingUnboxingFlags(checker->GetUnboxingFlag(checker->MaybePrimitiveBuiltinType(ct))); + related++; + } + if (related > 1) { + AmbiguousUnionOperation(relation); + } + relation->Result(related == 1); } -void ETSUnionType::AssignmentTarget(TypeRelation *relation, Type *source) +template +void ETSUnionType::RelationTarget(TypeRelation *relation, Type *source, RelFN const &relFn) { auto *const checker = relation->GetChecker()->AsETSChecker(); - auto *const refSource = - source->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) ? checker->PrimitiveTypeAsETSBuiltinType(source) : source; - auto exactType = std::find_if( - constituentTypes_.begin(), constituentTypes_.end(), [checker, relation, source, refSource](Type *ct) { - if (ct == refSource && source->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && ct->IsETSObjectType() && - ct->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE)) { - relation->GetNode()->SetBoxingUnboxingFlags(checker->GetBoxingFlag(ct)); - return relation->IsAssignableTo(refSource, ct); - } - return false; - }); - if (exactType != constituentTypes_.end()) { + auto *const refSource = checker->MaybePromotedBuiltinType(source); + + if (source != refSource && !relation->ApplyBoxing()) { + relation->Result(false); return; } - size_t assignableCount = 0; - for (auto *it : constituentTypes_) { - if (relation->IsAssignableTo(refSource, it)) { - if (refSource != source) { - relation->IsAssignableTo(source, it); - ASSERT(relation->IsTrue()); - } - ++assignableCount; - continue; + if (relation->IsSupertypeOf(this, refSource)) { + if (refSource != source) { + relation->GetNode()->SetBoxingUnboxingFlags(checker->GetBoxingFlag(refSource)); } - bool assignPrimitive = it->IsETSObjectType() && - it->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE) && - source->HasTypeFlag(TypeFlag::ETS_PRIMITIVE); - if (assignPrimitive && relation->IsAssignableTo(source, checker->ETSBuiltinTypeAsPrimitiveType(it))) { - Type *unboxedIt = checker->ETSBuiltinTypeAsPrimitiveType(it); - if (unboxedIt != source) { - relation->GetNode()->SetBoxingUnboxingFlags(checker->GetBoxingFlag(it)); - source->Cast(relation, unboxedIt); - ASSERT(relation->IsTrue()); - } - ++assignableCount; + return; + } + if (source == refSource) { + relation->Result(false); + return; + } + + int related = 0; + for (auto *ct : ConstituentTypes()) { // NOTE(vpukhov): just test if union is supertype of any numeric + if (!relFn(relation, checker->MaybePrimitiveBuiltinType(ct), source)) { + continue; } + relation->GetNode()->SetBoxingUnboxingFlags(checker->GetBoxingFlag(ct)); + related++; + } + if (related > 1) { + AmbiguousUnionOperation(relation); + } + relation->Result(related == 1); +} + +bool ETSUnionType::AssignmentSource(TypeRelation *relation, Type *target) +{ + auto const relFn = []([[maybe_unused]] TypeRelation *rel, [[maybe_unused]] Type *ct, [[maybe_unused]] Type *tgt) { + return false; + }; + RelationSource(relation, target, relFn); + return relation->IsTrue(); +} + +void ETSUnionType::AssignmentTarget(TypeRelation *relation, Type *source) +{ + auto const relFn = [](TypeRelation *rel, Type *ct, Type *src) { return rel->IsAssignableTo(src, ct); }; + RelationTarget(relation, source, relFn); +} + +void ETSUnionType::Cast(TypeRelation *relation, Type *target) +{ + if (relation->InCastingContext() && target->IsETSReferenceType()) { + relation->Result(true); // NOTE(vpukhov): check if types intersect at least + return; + } + auto const relFn = [](TypeRelation *rel, Type *ct, Type *tgt) { return rel->IsCastableTo(ct, tgt); }; + RelationSource(relation, target, relFn); +} + +void ETSUnionType::CastTarget(TypeRelation *relation, Type *source) +{ + if (relation->InCastingContext() && source->IsETSReferenceType()) { + relation->Result(true); // NOTE(vpukhov): check if types intersect at least + return; + } + auto const relFn = [](TypeRelation *rel, Type *ct, Type *src) { return rel->IsCastableTo(src, ct); }; + RelationTarget(relation, source, relFn); +} + +static auto constexpr ETS_NORMALIZABLE_NUMERIC = TypeFlag(TypeFlag::ETS_NUMERIC & ~TypeFlag::CHAR); + +static Type *LargestNumeric(Type *t1, Type *t2) +{ + static_assert(TypeFlag::DOUBLE > TypeFlag::FLOAT); + static_assert(TypeFlag::FLOAT > TypeFlag::LONG); + static_assert(TypeFlag::LONG > TypeFlag::INT); + static_assert(TypeFlag::INT > TypeFlag::SHORT); + static_assert(TypeFlag::SHORT > TypeFlag::BYTE); + + auto v1 = t1->TypeFlags() & ETS_NORMALIZABLE_NUMERIC; + auto v2 = t2->TypeFlags() & ETS_NORMALIZABLE_NUMERIC; + ASSERT(helpers::math::IsPowerOfTwo(v1)); + ASSERT(helpers::math::IsPowerOfTwo(v2)); + return v1 > v2 ? t1 : t2; +} + +static std::optional TryMergeTypes(TypeRelation *relation, Type *const t1, Type *const t2) +{ + auto checker = relation->GetChecker()->AsETSChecker(); + auto never = checker->GetGlobalTypesHolder()->GlobalBuiltinNeverType(); + if (relation->IsSupertypeOf(t1, t2) || t2 == never) { + return t1; } - if (assignableCount > 1) { - checker->ThrowTypeError({"Ambiguous assignment: after union normalization several types are assignable."}, - relation->GetNode()->Start()); + if (relation->IsSupertypeOf(t2, t1) || t1 == never) { + return t2; } - relation->Result(assignableCount != 0U); + // NOTE(vpukhov): numerics - clarification required + return std::nullopt; } -void ETSUnionType::LinearizeAndEraseIdentical(TypeRelation *relation, ArenaVector &constituentTypes) +void ETSUnionType::LinearizeAndEraseIdentical(TypeRelation *relation, ArenaVector &types) { auto *const checker = relation->GetChecker()->AsETSChecker(); - // Firstly, make linearization - ArenaVector copiedConstituents(checker->Allocator()->Adapter()); - for (auto *ct : constituentTypes) { + // Linearize + size_t const initialSz = types.size(); + for (size_t i = 0; i < initialSz; ++i) { + auto *const ct = types[i]; if (ct->IsETSUnionType()) { - auto otherTypes = ct->AsETSUnionType()->ConstituentTypes(); - copiedConstituents.insert(copiedConstituents.end(), otherTypes.begin(), otherTypes.end()); - } else { - copiedConstituents.push_back(ct); + auto const &otherTypes = ct->AsETSUnionType()->ConstituentTypes(); + types.insert(types.end(), otherTypes.begin(), otherTypes.end()); + types[i] = nullptr; } } - constituentTypes = copiedConstituents; - // Removing subtypes should be in the next iteration, especially needed for proper literals removal - auto checkSubtyping = [relation](Type *lhs, Type *rhs) { - if (lhs == rhs) { - return false; + size_t insPos = 0; + for (size_t i = 0; i < types.size(); ++i) { + auto *const ct = types[i]; + if (ct != nullptr) { + types[insPos++] = ct; } - relation->Result(false); - lhs->IsSupertypeOf(relation, rhs); - bool inheritanceRelation = relation->IsTrue(); - rhs->IsSupertypeOf(relation, lhs); - inheritanceRelation = inheritanceRelation || relation->IsTrue(); - return inheritanceRelation; - }; - // Secondly, remove identical types - auto cmpIt = constituentTypes.begin(); - while (cmpIt != constituentTypes.end()) { - auto it = std::next(cmpIt); - while (it != constituentTypes.end()) { - if (relation->IsIdenticalTo(*it, *cmpIt) && !checkSubtyping(*it, *cmpIt)) { - it = constituentTypes.erase(it); + } + types.resize(insPos); + + // Promote primitives and literal types + for (auto &ct : types) { + ct = checker->MaybePromotedBuiltinType(checker->GetNonConstantTypeFromPrimitiveType(ct)); + } + // Reduce subtypes + for (auto cmpIt = types.begin(); cmpIt != types.end(); ++cmpIt) { + for (auto it = std::next(cmpIt); it != types.end();) { + if (auto merged = TryMergeTypes(relation, *cmpIt, *it); merged) { + *cmpIt = *merged; + it = types.erase(it); } else { - ++it; + it++; } } - ++cmpIt; } } -void ETSUnionType::NormalizeTypes(TypeRelation *relation, ArenaVector &constituentTypes) +void ETSUnionType::NormalizeTypes(TypeRelation *relation, ArenaVector &types) { - auto *const checker = relation->GetChecker()->AsETSChecker(); - auto etsObject = std::find(constituentTypes.begin(), constituentTypes.end(), - checker->GetGlobalTypesHolder()->GlobalETSObjectType()); - if (etsObject != constituentTypes.end()) { - constituentTypes.clear(); - constituentTypes.push_back(checker->GetGlobalTypesHolder()->GlobalETSObjectType()); + if (types.size() == 1) { return; } - LinearizeAndEraseIdentical(relation, constituentTypes); - // Find number type to remove other numeric types - auto numberFound = - std::find_if(constituentTypes.begin(), constituentTypes.end(), [](Type *const ct) { - return ct->IsETSObjectType() && ct->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::BUILTIN_DOUBLE); - }) != constituentTypes.end(); - auto cmpIt = constituentTypes.begin(); - while (cmpIt != constituentTypes.end()) { - auto newEnd = std::remove_if( - constituentTypes.begin(), constituentTypes.end(), [relation, checker, cmpIt, numberFound](Type *ct) { - bool bothConstants = (*cmpIt)->HasTypeFlag(TypeFlag::CONSTANT) && ct->HasTypeFlag(TypeFlag::CONSTANT); - relation->IsSupertypeOf((*cmpIt), ct); - bool removeSubtype = ct != *cmpIt && !bothConstants && relation->IsTrue(); - bool removeNumeric = numberFound && ct->IsETSObjectType() && - ct->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE) && - !ct->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::BUILTIN_DOUBLE) && - !ct->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::BUILTIN_BOOLEAN); - bool removeNever = ct == checker->GetGlobalTypesHolder()->GlobalBuiltinNeverType(); - return removeSubtype || removeNumeric || removeNever; - }); - if (newEnd != constituentTypes.end()) { - constituentTypes.erase(newEnd, constituentTypes.end()); - cmpIt = constituentTypes.begin(); - continue; - } - ++cmpIt; + auto const isNumeric = [](auto *ct) { return ct->HasTypeFlag(ETS_NORMALIZABLE_NUMERIC); }; + if (std::all_of(types.begin(), types.end(), isNumeric)) { + types[0] = std::accumulate(std::next(types.begin()), types.end(), types[0], LargestNumeric); + types.resize(1); + return; } + LinearizeAndEraseIdentical(relation, types); } Type *ETSUnionType::Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) { + auto *const checker = relation->GetChecker()->AsETSChecker(); ArenaVector copiedConstituents(allocator->Adapter()); - for (auto *it : constituentTypes_) { - copiedConstituents.push_back(it->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) - ? relation->GetChecker()->AsETSChecker()->PrimitiveTypeAsETSBuiltinType(it) - : it->Instantiate(allocator, relation, globalTypes)); + copiedConstituents.push_back(it->Instantiate(allocator, relation, globalTypes)); } - - ETSUnionType::NormalizeTypes(relation, copiedConstituents); - if (copiedConstituents.size() == 1) { - return copiedConstituents[0]; - } - - return allocator->New(relation->GetChecker()->AsETSChecker(), std::move(copiedConstituents)); + return checker->CreateETSUnionType(std::move(copiedConstituents)); } Type *ETSUnionType::Substitute(TypeRelation *relation, const Substitution *substitution) @@ -255,46 +333,6 @@ Type *ETSUnionType::Substitute(TypeRelation *relation, const Substitution *subst return checker->CreateETSUnionType(std::move(substitutedConstituents)); } -void ETSUnionType::Cast(TypeRelation *relation, Type *target) -{ - auto *const checker = relation->GetChecker()->AsETSChecker(); - auto *const refTarget = - target->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) ? checker->PrimitiveTypeAsETSBuiltinType(target) : target; - auto exactType = - std::find_if(constituentTypes_.begin(), constituentTypes_.end(), [this, relation, refTarget](Type *src) { - if (src == refTarget && relation->IsCastableTo(src, refTarget)) { - GetLeastUpperBoundType()->Cast(relation, refTarget); - ASSERT(relation->IsTrue()); - return true; - } - return false; - }); - if (exactType != constituentTypes_.end()) { - return; - } - for (auto *source : constituentTypes_) { - if (relation->IsCastableTo(source, refTarget)) { - GetLeastUpperBoundType()->Cast(relation, refTarget); - ASSERT(relation->IsTrue()); - if (refTarget != target) { - source->Cast(relation, target); - ASSERT(relation->IsTrue()); - ASSERT(relation->GetNode()->GetBoxingUnboxingFlags() != ir::BoxingUnboxingFlags::NONE); - } - return; - } - bool castPrimitive = source->IsETSObjectType() && - source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE) && - target->HasTypeFlag(TypeFlag::ETS_PRIMITIVE); - if (castPrimitive && relation->IsCastableTo(checker->ETSBuiltinTypeAsPrimitiveType(source), target)) { - ASSERT(relation->IsTrue()); - return; - } - } - - conversion::Forbidden(relation); -} - void ETSUnionType::IsSupertypeOf(TypeRelation *relation, Type *source) { for (auto const &ctype : ConstituentTypes()) { @@ -313,17 +351,6 @@ void ETSUnionType::IsSubtypeOf(TypeRelation *relation, Type *target) } } -void ETSUnionType::CastTarget(TypeRelation *relation, Type *source) -{ - Type *targetType = FindTypeIsCastableToThis(relation->GetNode(), relation, source); - if (targetType != nullptr) { - source->Cast(relation, targetType); - return; - } - - conversion::Forbidden(relation); -} - Type *ETSUnionType::FindTypeIsCastableToThis(ir::Expression *node, TypeRelation *relation, Type *source) const { ASSERT(node); @@ -433,4 +460,17 @@ Type *ETSUnionType::FindExactOrBoxedType(ETSChecker *checker, Type *const type) return nullptr; } +std::tuple ETSUnionType::ResolveConditionExpr() const +{ + if (PossiblyETSString()) { + return {false, false}; + } + if (std::all_of(ConstituentTypes().begin(), ConstituentTypes().end(), + [](checker::Type const *ct) { return ct->DefinitelyETSNullish(); })) { + return {true, false}; + } + // We have to test if union can contain builtin numerics or string types to infer "true" + return {false, false}; +} + } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsUnionType.h b/ets2panda/checker/types/ets/etsUnionType.h index 216c2630c2289fd3b71898320fbf8e60904d083d..ee99d584b6e27a6fad0e4a88cfddc8a97f578f6a 100644 --- a/ets2panda/checker/types/ets/etsUnionType.h +++ b/ets2panda/checker/types/ets/etsUnionType.h @@ -32,7 +32,7 @@ public: return constituentTypes_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void ToAssemblerType(std::stringstream &ss) const override; void ToDebugInfoType(std::stringstream &ss) const override; void Identical(TypeRelation *relation, Type *other) override; @@ -48,38 +48,35 @@ public: Type *FindTypeIsCastableToSomeType(ir::Expression *node, TypeRelation *relation, Type *target) const; Type *FindUnboxableType() const; - Type *GetLeastUpperBoundType() const - { - ASSERT(lubType_ != nullptr); - return lubType_; - } - bool HasObjectType(ETSObjectFlags flag) const; Type *FindExactOrBoxedType(ETSChecker *checker, Type *type) const; - static void NormalizeTypes(TypeRelation *relation, ArenaVector &constituentTypes); + static void NormalizeTypes(TypeRelation *relation, ArenaVector &types); - std::tuple ResolveConditionExpr() const override + std::tuple ResolveConditionExpr() const override; + + // Do not use it anywhere except codegen + Type *GetAssemblerLUB() const { - for (auto const &tp : ConstituentTypes()) { - if (!tp->IsConditionalExprType()) { - return {true, false}; - } - } - return {true, true}; + return assemblerLub_; } private: static bool EachTypeRelatedToSomeType(TypeRelation *relation, ETSUnionType *source, ETSUnionType *target); static bool TypeRelatedToSomeType(TypeRelation *relation, Type *source, ETSUnionType *target); - static void LinearizeAndEraseIdentical(TypeRelation *relation, ArenaVector &constituentTypes); + template + void RelationSource(TypeRelation *relation, Type *target, RelFN const &relFn); + template + void RelationTarget(TypeRelation *relation, Type *source, RelFN const &relFn); + + static void LinearizeAndEraseIdentical(TypeRelation *relation, ArenaVector &types); - Type *ComputeLUB(ETSChecker *checker) const; + static Type *ComputeAssemblerLUB(ETSChecker *checker, ETSUnionType *un); ArenaVector const constituentTypes_; - Type *lubType_ {nullptr}; + Type *assemblerLub_ {nullptr}; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsVoidType.h b/ets2panda/checker/types/ets/etsVoidType.h index ab280f7e2d669cbe6b4c9e2ff96b5a32e7828c63..e6658fc53f0db8ae73440c5c0d99cdbfe986ab6e 100644 --- a/ets2panda/checker/types/ets/etsVoidType.h +++ b/ets2panda/checker/types/ets/etsVoidType.h @@ -27,7 +27,7 @@ public: void AssignmentTarget(TypeRelation *relation, Type *source) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "void"; } diff --git a/ets2panda/checker/types/ets/floatType.h b/ets2panda/checker/types/ets/floatType.h index 68da05d2d0d860f364b4cd27373bbc2b31f13489..6c9b92c1c809707acc1b81f72d5c5ab56dc95145 100644 --- a/ets2panda/checker/types/ets/floatType.h +++ b/ets2panda/checker/types/ets/floatType.h @@ -37,7 +37,7 @@ public: void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "float"; } diff --git a/ets2panda/checker/types/ets/intType.cpp b/ets2panda/checker/types/ets/intType.cpp index 4c8871d8425d7d41d1ea744082c7a97fe5c060d0..7361602c6eb2bc10f84be5aca5a59b286b24749d 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() || target->IsETSUnionType())) { + if (relation->ApplyBoxing() && target->IsETSObjectType()) { relation->GetChecker()->AsETSChecker()->CheckBoxedSourceTypeAssignable(relation, this, target); } diff --git a/ets2panda/checker/types/ets/intType.h b/ets2panda/checker/types/ets/intType.h index 2e9734ccc7560d47e08498d6195d39d3d0fad5f0..fab974a6f0192cdc2223b6b18ebaaf30c70aa628 100644 --- a/ets2panda/checker/types/ets/intType.h +++ b/ets2panda/checker/types/ets/intType.h @@ -37,7 +37,7 @@ public: void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "int"; } diff --git a/ets2panda/checker/types/ets/longType.h b/ets2panda/checker/types/ets/longType.h index e2887d5374200ef53bd5bed45c731a889bad27df..85ee2db7d372550e1dd606492b49e4d319b7bbdd 100644 --- a/ets2panda/checker/types/ets/longType.h +++ b/ets2panda/checker/types/ets/longType.h @@ -37,7 +37,7 @@ public: void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "long"; } diff --git a/ets2panda/checker/types/ets/shortType.h b/ets2panda/checker/types/ets/shortType.h index 85764fff8368b50c13502fd89826f17bc27afa42..7d0788b4bbae52eecba3e3dbf92aec088e85d244 100644 --- a/ets2panda/checker/types/ets/shortType.h +++ b/ets2panda/checker/types/ets/shortType.h @@ -37,7 +37,7 @@ public: void Cast(TypeRelation *relation, Type *target) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; - void ToString(std::stringstream &ss) const override + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override { ss << "short"; } diff --git a/ets2panda/checker/types/ets/types.h b/ets2panda/checker/types/ets/types.h index e9762c93a402f04d96d27f794579cf96c0c47b6d..d0a9efae1504c27277c46dc7711ac257fa3ca3a7 100644 --- a/ets2panda/checker/types/ets/types.h +++ b/ets2panda/checker/types/ets/types.h @@ -36,6 +36,8 @@ #include "etsArrayType.h" #include "wildcardType.h" #include "etsTypeParameter.h" +#include "etsNonNullishType.h" +#include "etsNullishTypes.h" #include "checker/types/signature.h" #endif /* TYPES_H */ diff --git a/ets2panda/checker/types/ets/wildcardType.cpp b/ets2panda/checker/types/ets/wildcardType.cpp index aab9ae80b4bb640f13301f32e514d0ce03a64363..7b99a7b06f2d4b82704665042ef99eea52ef851c 100644 --- a/ets2panda/checker/types/ets/wildcardType.cpp +++ b/ets2panda/checker/types/ets/wildcardType.cpp @@ -16,7 +16,7 @@ #include "wildcardType.h" namespace panda::es2panda::checker { -void WildcardType::ToString(std::stringstream &ss) const +void WildcardType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "wildcard"; } diff --git a/ets2panda/checker/types/ets/wildcardType.h b/ets2panda/checker/types/ets/wildcardType.h index 9db1b04df9994ae3cda0054eafb0d581e9b8f9c9..feb18636ec67a10f19e6c309bae7d62c02999be3 100644 --- a/ets2panda/checker/types/ets/wildcardType.h +++ b/ets2panda/checker/types/ets/wildcardType.h @@ -23,7 +23,7 @@ class WildcardType : public Type { public: WildcardType() : Type(TypeFlag::WILDCARD) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; diff --git a/ets2panda/checker/types/globalTypesHolder.cpp b/ets2panda/checker/types/globalTypesHolder.cpp index 27115ca55964d3b87dbe05ed8f7ee85ea9c57e63..e15b31509cd39f63f00fe1d5e3771f06df58958f 100644 --- a/ets2panda/checker/types/globalTypesHolder.cpp +++ b/ets2panda/checker/types/globalTypesHolder.cpp @@ -44,6 +44,7 @@ #include "checker/types/ets/etsStringType.h" #include "checker/types/ets/etsBigIntType.h" #include "checker/types/ets/etsVoidType.h" +#include "checker/types/ets/etsNullishTypes.h" #include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/wildcardType.h" #include "util/helpers.h" @@ -91,16 +92,8 @@ GlobalTypesHolder::GlobalTypesHolder(ArenaAllocator *allocator) : builtinNameMap globalTypes_[static_cast(GlobalTypeId::CHAR)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::ETS_BOOLEAN)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::ETS_VOID)] = allocator->New(); - auto *globalNullType = allocator->New(allocator); - globalNullType->AsETSObjectType()->AddObjectFlag(ETSObjectFlags::NULL_TYPE); - globalNullType->AsETSObjectType()->SetName("null"); - globalNullType->AsETSObjectType()->SetAssemblerName("null has no symbol!"); - globalTypes_[static_cast(GlobalTypeId::ETS_NULL)] = globalNullType; - auto *globalUndefinedType = allocator->New(allocator); - globalUndefinedType->AsETSObjectType()->AddObjectFlag(ETSObjectFlags::UNDEFINED_TYPE); - globalUndefinedType->AsETSObjectType()->SetName("undefined"); - globalUndefinedType->AsETSObjectType()->SetAssemblerName("undefined has no symbol!"); - globalTypes_[static_cast(GlobalTypeId::ETS_UNDEFINED)] = globalUndefinedType; + globalTypes_[static_cast(GlobalTypeId::ETS_NULL)] = allocator->New(); + globalTypes_[static_cast(GlobalTypeId::ETS_UNDEFINED)] = allocator->New(); globalTypes_[static_cast(GlobalTypeId::ETS_WILDCARD)] = allocator->New(); builtinNameMappings_.emplace("Boolean", GlobalTypeId::ETS_BOOLEAN_BUILTIN); @@ -158,6 +151,18 @@ GlobalTypesHolder::GlobalTypesHolder(ArenaAllocator *allocator) : builtinNameMap builtinNameMappings_.emplace("RegExp", GlobalTypeId::ETS_REGEXP_BUILTIN); builtinNameMappings_.emplace("Set", GlobalTypeId::ETS_SET_BUILTIN); + // ETS functional types + for (size_t id = static_cast(GlobalTypeId::ETS_FUNCTION0_CLASS), nargs = 0; + id < static_cast(GlobalTypeId::ETS_FUNCTIONN_CLASS); id++, nargs++) { + std::stringstream ss; + ss << "Function"; + ss << nargs; + + builtinNameMappings_.emplace(util::UString(ss.str(), allocator).View(), static_cast(id)); + } + + builtinNameMappings_.emplace("FunctionN", GlobalTypeId::ETS_FUNCTIONN_CLASS); + // ETS interop js specific types builtinNameMappings_.emplace("JSRuntime", GlobalTypeId::ETS_INTEROP_JSRUNTIME_BUILTIN); builtinNameMappings_.emplace("JSValue", GlobalTypeId::ETS_INTEROP_JSVALUE_BUILTIN); @@ -613,6 +618,20 @@ Type *GlobalTypesHolder::GlobalBuiltinNeverType() return globalTypes_.at(static_cast(GlobalTypeId::ETS_NEVER_BUILTIN)); } +size_t GlobalTypesHolder::VariadicFunctionTypeThreshold() +{ + return static_cast(GlobalTypeId::ETS_FUNCTIONN_CLASS) - + static_cast(GlobalTypeId::ETS_FUNCTION0_CLASS); +} + +Type *GlobalTypesHolder::GlobalFunctionBuiltinType(size_t nargs) +{ + if (nargs >= VariadicFunctionTypeThreshold()) { + return globalTypes_.at(static_cast(GlobalTypeId::ETS_FUNCTIONN_CLASS)); + } + return globalTypes_.at(static_cast(GlobalTypeId::ETS_FUNCTION0_CLASS) + nargs); +} + void GlobalTypesHolder::InitializeBuiltin(const util::StringView name, Type *type) { const auto typeId = builtinNameMappings_.find(name); diff --git a/ets2panda/checker/types/globalTypesHolder.h b/ets2panda/checker/types/globalTypesHolder.h index c79d375a2512aff489471fa4b5f8d7435c8e0535..3f3fb0746558b7986f34d9e0c4f09cf244b5d368 100644 --- a/ets2panda/checker/types/globalTypesHolder.h +++ b/ets2panda/checker/types/globalTypesHolder.h @@ -112,6 +112,25 @@ enum class GlobalTypeId { ETS_BIG_INT_BUILTIN, ETS_BIG_INT, + ETS_FUNCTION0_CLASS, + ETS_FUNCTION1_CLASS, + ETS_FUNCTION2_CLASS, + ETS_FUNCTION3_CLASS, + ETS_FUNCTION4_CLASS, + ETS_FUNCTION5_CLASS, + ETS_FUNCTION6_CLASS, + ETS_FUNCTION7_CLASS, + ETS_FUNCTION8_CLASS, + ETS_FUNCTION9_CLASS, + ETS_FUNCTION10_CLASS, + ETS_FUNCTION11_CLASS, + ETS_FUNCTION12_CLASS, + ETS_FUNCTION13_CLASS, + ETS_FUNCTION14_CLASS, + ETS_FUNCTION15_CLASS, + ETS_FUNCTION16_CLASS, + ETS_FUNCTIONN_CLASS, + COUNT, }; @@ -204,6 +223,10 @@ public: Type *GlobalDoubleBoxBuiltinType(); Type *GlobalBuiltinNeverType(); + // Functional types + size_t VariadicFunctionTypeThreshold(); + Type *GlobalFunctionBuiltinType(size_t nargs); + // ETS escompat layer Type *GlobalArrayBuiltinType(); Type *GlobalClassOutOfMemoryErrorBuiltinType(); diff --git a/ets2panda/checker/types/signature.cpp b/ets2panda/checker/types/signature.cpp index c9e826acf84026e034c63489ca0a42aa53838a12..01feb8044bcfe7a35b34d05f82e35a2e1090b3e4 100644 --- a/ets2panda/checker/types/signature.cpp +++ b/ets2panda/checker/types/signature.cpp @@ -15,6 +15,7 @@ #include "signature.h" +#include "typeFlag.h" #include "varbinder/scope.h" #include "ir/base/scriptFunction.h" #include "ir/ts/tsTypeParameter.h" @@ -118,12 +119,13 @@ Signature *Signature::Copy(ArenaAllocator *allocator, TypeRelation *relation, Gl return copiedSignature; } -void Signature::ToString(std::stringstream &ss, const varbinder::Variable *variable, bool printAsMethod) const +void Signature::ToString(std::stringstream &ss, const varbinder::Variable *variable, bool printAsMethod, + bool precise) const { if (!signatureInfo_->typeParams.empty()) { ss << "<"; for (auto it = signatureInfo_->typeParams.begin(); it != signatureInfo_->typeParams.end(); ++it) { - (*it)->ToString(ss); + (*it)->ToString(ss, precise); if (std::next(it) != signatureInfo_->typeParams.end()) { ss << ", "; } @@ -142,7 +144,7 @@ void Signature::ToString(std::stringstream &ss, const varbinder::Variable *varia ss << ": "; - (*it)->TsType()->ToString(ss); + (*it)->TsType()->ToString(ss, precise); if (std::next(it) != signatureInfo_->params.end()) { ss << ", "; @@ -157,7 +159,8 @@ void Signature::ToString(std::stringstream &ss, const varbinder::Variable *varia ss << "..."; ss << signatureInfo_->restVar->Name(); ss << ": "; - signatureInfo_->restVar->TsType()->ToString(ss); + signatureInfo_->restVar->TsType()->ToString(ss, precise); + ss << "[]"; } @@ -169,7 +172,14 @@ void Signature::ToString(std::stringstream &ss, const varbinder::Variable *varia ss << " => "; } - returnType_->ToString(ss); + returnType_->ToString(ss, precise); +} + +std::string Signature::ToString() const +{ + std::stringstream ss; + ToString(ss, nullptr); + return ss.str(); } namespace { @@ -190,9 +200,7 @@ std::size_t GetToCheckParamCount(Signature *signature, bool isEts) bool Signature::IdenticalParameter(TypeRelation *relation, Type *type1, Type *type2) { - if (!CheckFunctionalInterfaces(relation, type1, type2)) { - relation->IsIdenticalTo(type1, type2); - } + relation->IsIdenticalTo(type1, type2); return relation->IsTrue(); } @@ -340,4 +348,24 @@ void Signature::AssignmentTarget(TypeRelation *relation, Signature *source) relation->IsAssignableTo(source->RestVar()->TsType(), signatureInfo_->restVar->TsType()); } } + +Signature *Signature::BoxPrimitives(ETSChecker *checker) +{ + auto *allocator = checker->Allocator(); + auto *sigInfo = allocator->New(signatureInfo_, allocator); + for (auto param : sigInfo->params) { + if (param->TsType()->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { + param->SetTsType(checker->PrimitiveTypeAsETSBuiltinType(param->TsType())); + } + } + auto *retType = returnType_->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) + ? checker->PrimitiveTypeAsETSBuiltinType(returnType_) + : returnType_; + + auto *resultSig = allocator->New(sigInfo, retType, func_); + resultSig->flags_ = flags_; + resultSig->SetOwner(Owner()); + resultSig->SetOwnerVar(OwnerVar()); + return resultSig; +} } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/signature.h b/ets2panda/checker/types/signature.h index 295dd1111c72bc314a60d4850aa44811c78aa7d7..ab2bc277fcc51a5cf498cc0ebbe2afbfa3cab70f 100644 --- a/ets2panda/checker/types/signature.h +++ b/ets2panda/checker/types/signature.h @@ -81,6 +81,8 @@ enum class SignatureFlags : uint32_t { THIS_RETURN_TYPE = 1U << 15U, GETTER = 1U << 16U, SETTER = 1U << 17U, + THROWS = 1U << 18U, + RETHROWS = 1U << 19U, INTERNAL_PROTECTED = INTERNAL | PROTECTED, GETTER_OR_SETTER = GETTER | SETTER, @@ -245,10 +247,13 @@ public: Signature *Copy(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes); Signature *Substitute(TypeRelation *relation, const Substitution *substitution); - void ToString(std::stringstream &ss, const varbinder::Variable *variable, bool printAsMethod = false) const; + void ToString(std::stringstream &ss, const varbinder::Variable *variable, bool printAsMethod = false, + bool precise = false) const; + std::string ToString() const; void Identical(TypeRelation *relation, Signature *other); bool CheckFunctionalInterfaces(TypeRelation *relation, Type *source, Type *target); void AssignmentTarget(TypeRelation *relation, Signature *source); + Signature *BoxPrimitives(ETSChecker *checker); private: bool IdenticalParameter(TypeRelation *relation, Type *type1, Type *type2); diff --git a/ets2panda/checker/types/ts/anyType.cpp b/ets2panda/checker/types/ts/anyType.cpp index 8409060e97205aca44075ab32a21ba5bd9d42e36..db2c7f04207d3c58643f4aec71d2d552bc3ad81d 100644 --- a/ets2panda/checker/types/ts/anyType.cpp +++ b/ets2panda/checker/types/ts/anyType.cpp @@ -16,7 +16,7 @@ #include "anyType.h" namespace panda::es2panda::checker { -void AnyType::ToString(std::stringstream &ss) const +void AnyType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "any"; } diff --git a/ets2panda/checker/types/ts/anyType.h b/ets2panda/checker/types/ts/anyType.h index 69c36c85f551be9052bfd885ea95122dda26c0a1..19633bc7a504bea3a6da49ae9c6c6c93a7f05d0c 100644 --- a/ets2panda/checker/types/ts/anyType.h +++ b/ets2panda/checker/types/ts/anyType.h @@ -23,7 +23,7 @@ class AnyType : public Type { public: AnyType() : Type(TypeFlag::ANY) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; diff --git a/ets2panda/checker/types/ts/arrayType.cpp b/ets2panda/checker/types/ts/arrayType.cpp index 8c4e2ac9b752354e21737cf0b8795727369a01e1..2e3457208810c901a93e1f9999627e44b7951c1a 100644 --- a/ets2panda/checker/types/ts/arrayType.cpp +++ b/ets2panda/checker/types/ts/arrayType.cpp @@ -19,13 +19,13 @@ #include "checker/types/ts/objectType.h" namespace panda::es2panda::checker { -void ArrayType::ToString(std::stringstream &ss) const +void ArrayType::ToString(std::stringstream &ss, bool precise) const { bool elemIsUnion = (element_->TypeFlags() == TypeFlag::UNION); if (elemIsUnion) { ss << "("; } - ElementType()->ToString(ss); + ElementType()->ToString(ss, precise); if (elemIsUnion) { ss << ")"; } diff --git a/ets2panda/checker/types/ts/arrayType.h b/ets2panda/checker/types/ts/arrayType.h index 78f6c259941b962ce68e4557492ce96c924604af..d60de37a4d12828ca1cef9a07178a7826f310f8b 100644 --- a/ets2panda/checker/types/ts/arrayType.h +++ b/ets2panda/checker/types/ts/arrayType.h @@ -33,7 +33,7 @@ public: return element_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/bigintLiteralType.cpp b/ets2panda/checker/types/ts/bigintLiteralType.cpp index b378c83fc57c839369b1177dc9438abfb3e14f5e..66235052588ea9eef635d77296915368afb7c58e 100644 --- a/ets2panda/checker/types/ts/bigintLiteralType.cpp +++ b/ets2panda/checker/types/ts/bigintLiteralType.cpp @@ -16,7 +16,7 @@ #include "bigintLiteralType.h" namespace panda::es2panda::checker { -void BigintLiteralType::ToString(std::stringstream &ss) const +void BigintLiteralType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << value_; } diff --git a/ets2panda/checker/types/ts/bigintLiteralType.h b/ets2panda/checker/types/ts/bigintLiteralType.h index 9e02187ffe506f858727b9249d8ad19e5929550e..b3797e5affa0355623896e14f0af58f8c3bdfb12 100644 --- a/ets2panda/checker/types/ts/bigintLiteralType.h +++ b/ets2panda/checker/types/ts/bigintLiteralType.h @@ -36,7 +36,7 @@ public: return negative_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void ToStringAsSrc(std::stringstream &ss) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/bigintType.cpp b/ets2panda/checker/types/ts/bigintType.cpp index 91e816019d653586ad6d32c38f9a45e4c43af992..ee84c0717acc6695430e86467b7b0c739f7aa987 100644 --- a/ets2panda/checker/types/ts/bigintType.cpp +++ b/ets2panda/checker/types/ts/bigintType.cpp @@ -16,7 +16,7 @@ #include "bigintType.h" namespace panda::es2panda::checker { -void BigintType::ToString(std::stringstream &ss) const +void BigintType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "bigint"; } diff --git a/ets2panda/checker/types/ts/bigintType.h b/ets2panda/checker/types/ts/bigintType.h index 17b7526c605661d7c0e351c262ba3533d2dd3bf4..e9b839d3e59fcbcaecc8fe478fbf098ba2b26dbe 100644 --- a/ets2panda/checker/types/ts/bigintType.h +++ b/ets2panda/checker/types/ts/bigintType.h @@ -23,7 +23,7 @@ class BigintType : public Type { public: BigintType() : Type(TypeFlag::BIGINT) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/booleanLiteralType.cpp b/ets2panda/checker/types/ts/booleanLiteralType.cpp index b204f0b5060976567a27cbab45f638097d667f2f..36a06893425d149f434b237533f82f9759dace14 100644 --- a/ets2panda/checker/types/ts/booleanLiteralType.cpp +++ b/ets2panda/checker/types/ts/booleanLiteralType.cpp @@ -16,7 +16,7 @@ #include "booleanLiteralType.h" namespace panda::es2panda::checker { -void BooleanLiteralType::ToString(std::stringstream &ss) const +void BooleanLiteralType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { if (value_) { ss << "true"; diff --git a/ets2panda/checker/types/ts/booleanLiteralType.h b/ets2panda/checker/types/ts/booleanLiteralType.h index 381df49bc45d8cb5be675fc8aa13bb9a7e4aa752..4c04e0cdeaad4ce53f6920d420da70c6623c6f6b 100644 --- a/ets2panda/checker/types/ts/booleanLiteralType.h +++ b/ets2panda/checker/types/ts/booleanLiteralType.h @@ -28,7 +28,7 @@ public: return value_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void ToStringAsSrc(std::stringstream &ss) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/booleanType.cpp b/ets2panda/checker/types/ts/booleanType.cpp index 3ba7501e333db432fb04e7319481ba6117c59a60..3855d633b11b092e6c9ff21103b1955713b32635 100644 --- a/ets2panda/checker/types/ts/booleanType.cpp +++ b/ets2panda/checker/types/ts/booleanType.cpp @@ -16,7 +16,7 @@ #include "booleanType.h" namespace panda::es2panda::checker { -void BooleanType::ToString(std::stringstream &ss) const +void BooleanType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "boolean"; } diff --git a/ets2panda/checker/types/ts/booleanType.h b/ets2panda/checker/types/ts/booleanType.h index b0b54f22330367a8bc95403c58d799f91a7b2991..3dc6c1ece33ef757e992d0621cd87e4efd3066a7 100644 --- a/ets2panda/checker/types/ts/booleanType.h +++ b/ets2panda/checker/types/ts/booleanType.h @@ -23,7 +23,7 @@ class BooleanType : public Type { public: BooleanType() : Type(TypeFlag::BOOLEAN) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/constructorType.cpp b/ets2panda/checker/types/ts/constructorType.cpp index 75596cb0b99b9ae81bfd987dbc11dba0456e40a5..294d1a28a53b0ece3a182ac941f44bcf9bf7e1b5 100644 --- a/ets2panda/checker/types/ts/constructorType.cpp +++ b/ets2panda/checker/types/ts/constructorType.cpp @@ -18,7 +18,7 @@ #include "checker/types/signature.h" namespace panda::es2panda::checker { -void ConstructorType::ToString(std::stringstream &ss) const +void ConstructorType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { if (desc_->constructSignatures.size() > 1) { ss << "{ "; diff --git a/ets2panda/checker/types/ts/constructorType.h b/ets2panda/checker/types/ts/constructorType.h index 4c930cee425ce0e369eee677a3dd9dc3867c3c02..02389c7292771e2085257e0811229b28518e810d 100644 --- a/ets2panda/checker/types/ts/constructorType.h +++ b/ets2panda/checker/types/ts/constructorType.h @@ -23,7 +23,7 @@ class ConstructorType : public ObjectType { public: explicit ConstructorType(ObjectDescriptor *desc) : ObjectType(ObjectType::ObjectTypeKind::FUNCTION, desc) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; }; diff --git a/ets2panda/checker/types/ts/enumLiteralType.cpp b/ets2panda/checker/types/ts/enumLiteralType.cpp index 7cd7c05dc8b3871300b5406a97c0396361974757..0618f2d1c936919c2ef5e7a83da3b3ad4a366095 100644 --- a/ets2panda/checker/types/ts/enumLiteralType.cpp +++ b/ets2panda/checker/types/ts/enumLiteralType.cpp @@ -19,7 +19,7 @@ #include "checker/types/ts/enumType.h" namespace panda::es2panda::checker { -void EnumLiteralType::ToString(std::stringstream &ss) const +void EnumLiteralType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << name_; } diff --git a/ets2panda/checker/types/ts/enumLiteralType.h b/ets2panda/checker/types/ts/enumLiteralType.h index 83a42455efe5a1222ce4c5ccdf7c09c7e9743cd9..19e4e8c9d57cadc99f37ca5d1104850c86b7434f 100644 --- a/ets2panda/checker/types/ts/enumLiteralType.h +++ b/ets2panda/checker/types/ts/enumLiteralType.h @@ -47,7 +47,7 @@ public: return kind_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void ToStringAsSrc(std::stringstream &ss) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/enumType.cpp b/ets2panda/checker/types/ts/enumType.cpp index 0ee4cc675ac9f14d20d1b3c4cdbd58a2b9985384..4a308dda73ebdb778f83e2de770b6392400a17cb 100644 --- a/ets2panda/checker/types/ts/enumType.cpp +++ b/ets2panda/checker/types/ts/enumType.cpp @@ -18,7 +18,7 @@ #include "varbinder/variable.h" namespace panda::es2panda::checker { -void EnumType::ToString(std::stringstream &ss) const +void EnumType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << enumLiteralVar_->Name() << "." << enumVar_->Name(); } diff --git a/ets2panda/checker/types/ts/enumType.h b/ets2panda/checker/types/ts/enumType.h index c1a3a87882a5bc3c5bdf0281e80adf3ab3004b46..ce3da03261a2a763a6f50932e7c02f91dd17f0e6 100644 --- a/ets2panda/checker/types/ts/enumType.h +++ b/ets2panda/checker/types/ts/enumType.h @@ -1,3 +1,4 @@ + /** * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,7 +41,7 @@ public: return enumVar_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/functionType.cpp b/ets2panda/checker/types/ts/functionType.cpp index 3e1897429192a54666fe25d69b6bf804bba72e03..e8a10afe9dfc80a9a85d51e8f396a63fdd8a55c0 100644 --- a/ets2panda/checker/types/ts/functionType.cpp +++ b/ets2panda/checker/types/ts/functionType.cpp @@ -18,7 +18,7 @@ #include "checker/types/signature.h" namespace panda::es2panda::checker { -void FunctionType::ToString(std::stringstream &ss) const +void FunctionType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { static std::unordered_set stack; diff --git a/ets2panda/checker/types/ts/functionType.h b/ets2panda/checker/types/ts/functionType.h index f1b465a54bf29dc70687363036581e95c8d9aac3..b8e36d821d176a95143ad032041d23f8e2e35a14 100644 --- a/ets2panda/checker/types/ts/functionType.h +++ b/ets2panda/checker/types/ts/functionType.h @@ -24,7 +24,7 @@ class FunctionType : public ObjectType { public: explicit FunctionType(ObjectDescriptor *desc) : ObjectType(ObjectType::ObjectTypeKind::FUNCTION, desc) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; }; diff --git a/ets2panda/checker/types/ts/interfaceType.cpp b/ets2panda/checker/types/ts/interfaceType.cpp index 69b95e8ce3fa99201b78e0f45c3a71547cc09dff..633009c8a1c9f2b5e79eaab173cc0403cb14ba17 100644 --- a/ets2panda/checker/types/ts/interfaceType.cpp +++ b/ets2panda/checker/types/ts/interfaceType.cpp @@ -23,7 +23,7 @@ #include namespace panda::es2panda::checker { -void InterfaceType::ToString(std::stringstream &ss) const +void InterfaceType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << name_; diff --git a/ets2panda/checker/types/ts/interfaceType.h b/ets2panda/checker/types/ts/interfaceType.h index cfd1811e4929f73ca6f38afac6c946a4cb988514..210129214b984fe945987e091c35f8e085787f50 100644 --- a/ets2panda/checker/types/ts/interfaceType.h +++ b/ets2panda/checker/types/ts/interfaceType.h @@ -128,7 +128,7 @@ public: return properties; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; void Identical(TypeRelation *relation, Type *other) override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; diff --git a/ets2panda/checker/types/ts/neverType.cpp b/ets2panda/checker/types/ts/neverType.cpp index e4d75b636209194b65062c0225ef856e279dea7e..8add433de854dccac13d148fd0bebbedf0b54a98 100644 --- a/ets2panda/checker/types/ts/neverType.cpp +++ b/ets2panda/checker/types/ts/neverType.cpp @@ -16,7 +16,7 @@ #include "neverType.h" namespace panda::es2panda::checker { -void NeverType::ToString(std::stringstream &ss) const +void NeverType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "never"; } diff --git a/ets2panda/checker/types/ts/neverType.h b/ets2panda/checker/types/ts/neverType.h index 0931b3ae44735a9a18df449e57b1441a0eeadc54..5a5fb981c3a982b714a97ba72fd49d2ce1e28af6 100644 --- a/ets2panda/checker/types/ts/neverType.h +++ b/ets2panda/checker/types/ts/neverType.h @@ -23,7 +23,7 @@ class NeverType : public Type { public: NeverType() : Type(TypeFlag::NEVER) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/nonPrimitiveType.cpp b/ets2panda/checker/types/ts/nonPrimitiveType.cpp index 3c37b7cebf616752f57400ba6cc60ba93c148969..3fb42a30de6324a6b176b4ff3ae39bdfc5ad4bdc 100644 --- a/ets2panda/checker/types/ts/nonPrimitiveType.cpp +++ b/ets2panda/checker/types/ts/nonPrimitiveType.cpp @@ -16,7 +16,7 @@ #include "nonPrimitiveType.h" namespace panda::es2panda::checker { -void NonPrimitiveType::ToString(std::stringstream &ss) const +void NonPrimitiveType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "object"; } diff --git a/ets2panda/checker/types/ts/nonPrimitiveType.h b/ets2panda/checker/types/ts/nonPrimitiveType.h index 2047f5df5758e9cd93c2800663f26de5396ced43..614a658ad564cf7c55c325a8f8d1f4696ef6c73b 100644 --- a/ets2panda/checker/types/ts/nonPrimitiveType.h +++ b/ets2panda/checker/types/ts/nonPrimitiveType.h @@ -23,7 +23,7 @@ class NonPrimitiveType : public Type { public: NonPrimitiveType() : Type(TypeFlag::NON_PRIMITIVE) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/nullType.cpp b/ets2panda/checker/types/ts/nullType.cpp index 786aed31c6edb2cabe6bd3db889c555825a3d8b1..bcd90b3f70038cf0d1c66ee21e1ea09d1edaf72b 100644 --- a/ets2panda/checker/types/ts/nullType.cpp +++ b/ets2panda/checker/types/ts/nullType.cpp @@ -16,7 +16,7 @@ #include "nullType.h" namespace panda::es2panda::checker { -void NullType::ToString(std::stringstream &ss) const +void NullType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "null"; } diff --git a/ets2panda/checker/types/ts/nullType.h b/ets2panda/checker/types/ts/nullType.h index c46dfccb24b06b26942881de22e734eceee7cb84..5d40915809a2715623aef50ba5be3ca4a3d65764 100644 --- a/ets2panda/checker/types/ts/nullType.h +++ b/ets2panda/checker/types/ts/nullType.h @@ -23,7 +23,7 @@ class NullType : public Type { public: NullType() : Type(TypeFlag::NULL_TYPE) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/numberLiteralType.cpp b/ets2panda/checker/types/ts/numberLiteralType.cpp index c4ccc26e3705309d897f318bbac4628356679e73..3bc17ad8bc4dd1b17666589524f270b38b8d2557 100644 --- a/ets2panda/checker/types/ts/numberLiteralType.cpp +++ b/ets2panda/checker/types/ts/numberLiteralType.cpp @@ -20,7 +20,7 @@ #include "checker/types/ts/enumType.h" namespace panda::es2panda::checker { -void NumberLiteralType::ToString(std::stringstream &ss) const +void NumberLiteralType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << util::Helpers::ToString(value_); } diff --git a/ets2panda/checker/types/ts/numberLiteralType.h b/ets2panda/checker/types/ts/numberLiteralType.h index 360060a925771989c3b636a9040115dd3a9389a2..8b738425b7050e7b511e90faae139d7f4682dbee 100644 --- a/ets2panda/checker/types/ts/numberLiteralType.h +++ b/ets2panda/checker/types/ts/numberLiteralType.h @@ -28,7 +28,7 @@ public: return value_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void ToStringAsSrc(std::stringstream &ss) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/numberType.cpp b/ets2panda/checker/types/ts/numberType.cpp index 40916929fd36efa53f8b84f08efbe1e07bbe1ae9..59e90af296985c0e3b1b05ba9410273267f83779 100644 --- a/ets2panda/checker/types/ts/numberType.cpp +++ b/ets2panda/checker/types/ts/numberType.cpp @@ -19,7 +19,7 @@ #include "checker/types/ts/enumType.h" namespace panda::es2panda::checker { -void NumberType::ToString(std::stringstream &ss) const +void NumberType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "number"; } diff --git a/ets2panda/checker/types/ts/numberType.h b/ets2panda/checker/types/ts/numberType.h index a30f48609f8154c91348d1be2bb20ac4500146a9..eedbc33fe040eabef099597cbce2d85f20aeae76 100644 --- a/ets2panda/checker/types/ts/numberType.h +++ b/ets2panda/checker/types/ts/numberType.h @@ -23,7 +23,7 @@ class NumberType : public Type { public: NumberType() : Type(TypeFlag::NUMBER) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/objectLiteralType.cpp b/ets2panda/checker/types/ts/objectLiteralType.cpp index 407454989dfb19651344006e86e4656fa6563514..0bedc56068b34e87c19d40531bcd7328d496f7e4 100644 --- a/ets2panda/checker/types/ts/objectLiteralType.cpp +++ b/ets2panda/checker/types/ts/objectLiteralType.cpp @@ -22,7 +22,7 @@ namespace panda::es2panda::checker { class TSChecker; -void ObjectLiteralType::ToString(std::stringstream &ss) const +void ObjectLiteralType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "{ "; diff --git a/ets2panda/checker/types/ts/objectLiteralType.h b/ets2panda/checker/types/ts/objectLiteralType.h index e9b5695c1c07ce046180a7f0065239b2ee4f9b4f..85feba1c5c619c84a79b76959af7d53fe5c00f57 100644 --- a/ets2panda/checker/types/ts/objectLiteralType.h +++ b/ets2panda/checker/types/ts/objectLiteralType.h @@ -24,7 +24,7 @@ public: explicit ObjectLiteralType(ObjectDescriptor *desc) : ObjectType(ObjectType::ObjectTypeKind::LITERAL, desc) {} ObjectLiteralType() : ObjectType(ObjectType::ObjectTypeKind::LITERAL) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; Type *Instantiate(ArenaAllocator *allocator, TypeRelation *relation, GlobalTypesHolder *globalTypes) override; }; diff --git a/ets2panda/checker/types/ts/stringLiteralType.cpp b/ets2panda/checker/types/ts/stringLiteralType.cpp index 87f8cea1c18409ef9dd31e402f2db895f0c60722..c5e6c80e2eb2e28c8078a65b4c7ba6222faef9e6 100644 --- a/ets2panda/checker/types/ts/stringLiteralType.cpp +++ b/ets2panda/checker/types/ts/stringLiteralType.cpp @@ -16,7 +16,7 @@ #include "stringLiteralType.h" namespace panda::es2panda::checker { -void StringLiteralType::ToString(std::stringstream &ss) const +void StringLiteralType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "\"" << value_ << "\""; } diff --git a/ets2panda/checker/types/ts/stringLiteralType.h b/ets2panda/checker/types/ts/stringLiteralType.h index f18e1cb63b8ebf23dbd2fb2601218702e417efbb..fbca9751a9e5a2a35ee265061110194e777c20c5 100644 --- a/ets2panda/checker/types/ts/stringLiteralType.h +++ b/ets2panda/checker/types/ts/stringLiteralType.h @@ -28,7 +28,7 @@ public: return value_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void ToStringAsSrc(std::stringstream &ss) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/stringType.cpp b/ets2panda/checker/types/ts/stringType.cpp index 9afedd90b61d6c8d86aaf6e5c4b509396400cf26..e0b4a9182b3c4126bfdccd7b5a93eef6d5a047b8 100644 --- a/ets2panda/checker/types/ts/stringType.cpp +++ b/ets2panda/checker/types/ts/stringType.cpp @@ -16,7 +16,7 @@ #include "stringType.h" namespace panda::es2panda::checker { -void StringType::ToString(std::stringstream &ss) const +void StringType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "string"; } diff --git a/ets2panda/checker/types/ts/stringType.h b/ets2panda/checker/types/ts/stringType.h index d37ae5b48ddb3c422b038f2f695a29695190e829..2081adda400843413e3de57ae4ce57a608010320 100644 --- a/ets2panda/checker/types/ts/stringType.h +++ b/ets2panda/checker/types/ts/stringType.h @@ -23,7 +23,7 @@ class StringType : public Type { public: StringType() : Type(TypeFlag::STRING) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/tupleType.cpp b/ets2panda/checker/types/ts/tupleType.cpp index 9e5de1369e137b31bd658a38e5643fe8e3e93637..9efd5ccb6702a871fa7eccd0ead6a5468e12aac1 100644 --- a/ets2panda/checker/types/ts/tupleType.cpp +++ b/ets2panda/checker/types/ts/tupleType.cpp @@ -30,7 +30,7 @@ Type *TupleType::ConvertToArrayType(TSChecker *checker) return checker->Allocator()->New(arrayType); } -void TupleType::ToString(std::stringstream &ss) const +void TupleType::ToString(std::stringstream &ss, bool precise) const { if (readonly_) { ss << "readonly "; @@ -39,7 +39,7 @@ void TupleType::ToString(std::stringstream &ss) const if (namedMembers_.empty()) { for (auto it = desc_->properties.begin(); it != desc_->properties.end(); it++) { - (*it)->TsType()->ToString(ss); + (*it)->TsType()->ToString(ss, precise); if ((*it)->HasFlag(varbinder::VariableFlags::OPTIONAL)) { ss << "?"; } @@ -58,7 +58,7 @@ void TupleType::ToString(std::stringstream &ss) const } ss << ": "; - (*it)->TsType()->ToString(ss); + (*it)->TsType()->ToString(ss, precise); if (std::next(it) != desc_->properties.end()) { ss << ", "; } diff --git a/ets2panda/checker/types/ts/tupleType.h b/ets2panda/checker/types/ts/tupleType.h index 53fc5c47fc0be3cff90c570ee9d979580c334e1e..b638dce06ed1547ba3aba42a06a636e45212b371 100644 --- a/ets2panda/checker/types/ts/tupleType.h +++ b/ets2panda/checker/types/ts/tupleType.h @@ -87,7 +87,7 @@ public: Type *ConvertToArrayType(TSChecker *checker); - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/typeParameter.cpp b/ets2panda/checker/types/ts/typeParameter.cpp index 516b284db4679e82910212114d6e052f7dc768f5..fb297bfbf3e0b084f597349723097fc5c66e5e95 100644 --- a/ets2panda/checker/types/ts/typeParameter.cpp +++ b/ets2panda/checker/types/ts/typeParameter.cpp @@ -16,7 +16,7 @@ #include "typeParameter.h" namespace panda::es2panda::checker { -void TypeParameter::ToString([[maybe_unused]] std::stringstream &ss) const +void TypeParameter::ToString([[maybe_unused]] std::stringstream &ss, [[maybe_unused]] bool precise) const { UNREACHABLE(); } diff --git a/ets2panda/checker/types/ts/typeParameter.h b/ets2panda/checker/types/ts/typeParameter.h index bcc320265a19204985bc0ccded22d64afd7e2069..3de782e2c18d1fa29dd8f8ad8d0114090c5f8c44 100644 --- a/ets2panda/checker/types/ts/typeParameter.h +++ b/ets2panda/checker/types/ts/typeParameter.h @@ -46,7 +46,7 @@ public: default_ = type; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/typeReference.cpp b/ets2panda/checker/types/ts/typeReference.cpp index 579f22f3838cc9aa565200f24009ec7d24c1aaf8..4ec359bb587777c14d2c2a2196b55cf97e1f3e94 100644 --- a/ets2panda/checker/types/ts/typeReference.cpp +++ b/ets2panda/checker/types/ts/typeReference.cpp @@ -16,10 +16,10 @@ #include "typeReference.h" namespace panda::es2panda::checker { -void TypeReference::ToString(std::stringstream &ss) const +void TypeReference::ToString(std::stringstream &ss, bool precise) const { if (*ref_ != nullptr) { - (*ref_)->ToString(ss); + (*ref_)->ToString(ss, precise); } } diff --git a/ets2panda/checker/types/ts/typeReference.h b/ets2panda/checker/types/ts/typeReference.h index 2b4f33fc18a92457104961ce9bf913d338cfd55b..4e3022e7a4e4571faa36f7668c862f3b59e1e952 100644 --- a/ets2panda/checker/types/ts/typeReference.h +++ b/ets2panda/checker/types/ts/typeReference.h @@ -33,7 +33,7 @@ public: return *ref_; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; TypeFacts GetTypeFacts() const override; diff --git a/ets2panda/checker/types/ts/undefinedType.cpp b/ets2panda/checker/types/ts/undefinedType.cpp index 5e7f6aeae367b58dcb5b91a96ca5eed5d8ce0f2b..72e47c96e7eb9ea7fa9eb026aecf498c20502337 100644 --- a/ets2panda/checker/types/ts/undefinedType.cpp +++ b/ets2panda/checker/types/ts/undefinedType.cpp @@ -16,7 +16,7 @@ #include "undefinedType.h" namespace panda::es2panda::checker { -void UndefinedType::ToString(std::stringstream &ss) const +void UndefinedType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "undefined"; } diff --git a/ets2panda/checker/types/ts/undefinedType.h b/ets2panda/checker/types/ts/undefinedType.h index 79fbceeb63fae48f11ea7afbfa30d14e1b2dfab7..93a0db73c9402ef96b07458da936078a89059ff9 100644 --- a/ets2panda/checker/types/ts/undefinedType.h +++ b/ets2panda/checker/types/ts/undefinedType.h @@ -23,7 +23,7 @@ class UndefinedType : public Type { public: UndefinedType() : Type(TypeFlag::UNDEFINED) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/unionType.cpp b/ets2panda/checker/types/ts/unionType.cpp index 1d3f7e92f11954b0e50ec4e6f9b5c1927c967afd..352436e9cf46da823c024a422e2ea598e25f52b8 100644 --- a/ets2panda/checker/types/ts/unionType.cpp +++ b/ets2panda/checker/types/ts/unionType.cpp @@ -19,10 +19,10 @@ #include "checker/types/globalTypesHolder.h" namespace panda::es2panda::checker { -void UnionType::ToString(std::stringstream &ss) const +void UnionType::ToString(std::stringstream &ss, bool precise) const { for (auto it = constituentTypes_.begin(); it != constituentTypes_.end(); it++) { - (*it)->ToString(ss); + (*it)->ToString(ss, precise); if (std::next(it) != constituentTypes_.end()) { ss << " | "; } diff --git a/ets2panda/checker/types/ts/unionType.h b/ets2panda/checker/types/ts/unionType.h index 95d81fc732b3c82d4557f25c8228426fa784852c..93ea3ced44b52f0b537393e7b2799c4df40b2bb6 100644 --- a/ets2panda/checker/types/ts/unionType.h +++ b/ets2panda/checker/types/ts/unionType.h @@ -114,7 +114,7 @@ public: mergedObjectType_ = type; } - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, bool precise) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; diff --git a/ets2panda/checker/types/ts/unknownType.cpp b/ets2panda/checker/types/ts/unknownType.cpp index 554a3b8e0e9bcce45ce7c0046b22995f7f33428f..e3f0af57c5e82629d3883d7f398bdb27e921823a 100644 --- a/ets2panda/checker/types/ts/unknownType.cpp +++ b/ets2panda/checker/types/ts/unknownType.cpp @@ -16,7 +16,7 @@ #include "unknownType.h" namespace panda::es2panda::checker { -void UnknownType::ToString(std::stringstream &ss) const +void UnknownType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "unknown"; } diff --git a/ets2panda/checker/types/ts/unknownType.h b/ets2panda/checker/types/ts/unknownType.h index d1cb778f354f361ec36f7636d52fd1c7c03324d9..5a762dbe7fc0c8a60f361cb6f0180fca01d09f97 100644 --- a/ets2panda/checker/types/ts/unknownType.h +++ b/ets2panda/checker/types/ts/unknownType.h @@ -23,7 +23,7 @@ class UnknownType : public Type { public: UnknownType() : Type(TypeFlag::UNKNOWN) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/ts/voidType.cpp b/ets2panda/checker/types/ts/voidType.cpp index cb2b2fe4035c380b6b3c7762c0f8786476310eef..edab990222dce37ae37ffc8e40a6332da7c60321 100644 --- a/ets2panda/checker/types/ts/voidType.cpp +++ b/ets2panda/checker/types/ts/voidType.cpp @@ -16,7 +16,7 @@ #include "voidType.h" namespace panda::es2panda::checker { -void VoidType::ToString(std::stringstream &ss) const +void VoidType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const { ss << "void"; } diff --git a/ets2panda/checker/types/ts/voidType.h b/ets2panda/checker/types/ts/voidType.h index 47a5ceb8074dc66413fa602c01150f09e195b00c..e7b1b39b494094e641090c7720c6ab61ebc75194 100644 --- a/ets2panda/checker/types/ts/voidType.h +++ b/ets2panda/checker/types/ts/voidType.h @@ -23,7 +23,7 @@ class VoidType : public Type { public: VoidType() : Type(TypeFlag::VOID) {} - void ToString(std::stringstream &ss) const override; + void ToString(std::stringstream &ss, [[maybe_unused]] bool precise) const override; TypeFacts GetTypeFacts() const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; diff --git a/ets2panda/checker/types/type.cpp b/ets2panda/checker/types/type.cpp index 81affaf07a021118950650f48d0f34bb840b6f0d..81f0a26e1470be5112c73fef9edf6c64d6285d61 100644 --- a/ets2panda/checker/types/type.cpp +++ b/ets2panda/checker/types/type.cpp @@ -20,41 +20,6 @@ #include "checker/types/ets/etsObjectType.h" namespace panda::es2panda::checker { -bool Type::IsETSNullType() const -{ - return IsETSObjectType() && AsETSObjectType()->HasObjectFlag(ETSObjectFlags::NULL_TYPE); -} - -bool Type::IsETSUndefinedType() const -{ - 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 { @@ -83,11 +48,37 @@ bool Type::IsLambdaObject() const return false; } +void Type::ToString(std::stringstream &ss) const +{ + ToString(ss, false); +} + void Type::ToStringAsSrc(std::stringstream &ss) const { ToString(ss); } +std::string Type::ToString() const +{ + std::stringstream ss; + ToString(ss); + return ss.str(); +} + +std::string Type::ToStringAsSrc() const +{ + std::stringstream ss; + ToStringAsSrc(ss); + return ss.str(); +} + +std::string Type::ToStringPrecise() const +{ + std::stringstream ss; + ToString(ss, true); + return ss.str(); +} + void Type::Identical(TypeRelation *relation, Type *other) { relation->Result(typeFlags_ == other->TypeFlags()); @@ -140,4 +131,5 @@ Type *Type::Substitute([[maybe_unused]] TypeRelation *relation, [[maybe_unused]] { return this; } + } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/type.h b/ets2panda/checker/types/type.h index 455ec1e227c8a225cbe77ce5efe4b679d154adb3..82ed356e5b1076ec1e755c2997982879fb555274 100644 --- a/ets2panda/checker/types/type.h +++ b/ets2panda/checker/types/type.h @@ -86,14 +86,17 @@ public: bool IsETSStringType() const; bool IsETSBigIntType() const; - bool IsETSNullType() const; - bool IsETSUndefinedType() const; - bool IsETSNullLike() const; + bool IsETSReferenceType() const; bool IsETSAsyncFuncReturnType() const; - bool IsNullish() const; - bool IsNullishOrNullLike() const; - bool ContainsNull() const; - bool ContainsUndefined() const; + bool IsETSUnboxableObject() const; + + bool PossiblyETSNull() const; + bool PossiblyETSUndefined() const; + bool PossiblyETSNullish() const; + bool DefinitelyETSNullish() const; + bool DefinitelyNotETSNullish() const; + + bool PossiblyETSString() const; ETSStringType *AsETSStringType() { @@ -224,15 +227,20 @@ public: } bool IsLambdaObject() const; - virtual void ToString(std::stringstream &ss) const = 0; + virtual void ToString(std::stringstream &ss, bool precise) const = 0; + void ToString(std::stringstream &ss) const; + std::string ToString() const; + std::string ToStringPrecise() const; virtual void ToStringAsSrc(std::stringstream &ss) const; + std::string ToStringAsSrc() const; + virtual TypeFacts GetTypeFacts() const; virtual void ToAssemblerType([[maybe_unused]] std::stringstream &ss) const {}; virtual void ToDebugInfoType([[maybe_unused]] std::stringstream &ss) const {}; virtual void ToAssemblerTypeWithRank([[maybe_unused]] std::stringstream &ss) const { ToAssemblerType(ss); - }; + } virtual uint32_t Rank() const { diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index e4a973560db05f2f57ddb73cdd31c2478d82762e..bcb32999b190cabfacb9dc49579d75d38816b4b7 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -81,10 +81,14 @@ enum class TypeFlag : uint64_t { ETS_EXTENSION_FUNC_HELPER = 1ULL << 56ULL, // ETS Extension Function Helper ETS_UNION = 1ULL << 57ULL, // ETS union ETS_TUPLE = 1ULL << 58ULL, // ETS tuple type + ETS_NULL = 1ULL << 59ULL, // ETS null + ETS_UNDEFINED = 1ULL << 60ULL, // ETS undefined + ETS_NONNULLISH = 1ULL << 61ULL, // ETS nonnullish type parameter ETS_DYNAMIC_TYPE = ETS_OBJECT | ETS_DYNAMIC_FLAG, ETS_DYNAMIC_FUNCTION_TYPE = FUNCTION | ETS_DYNAMIC_FLAG, ETS_TYPE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID | ETS_OBJECT | ETS_ARRAY | - WILDCARD | ETS_TYPE_PARAMETER | ETS_ENUM | ETS_STRING_ENUM | ETS_DYNAMIC_TYPE | ETS_UNION, + WILDCARD | ETS_TYPE_PARAMETER | ETS_ENUM | ETS_STRING_ENUM | ETS_DYNAMIC_TYPE | ETS_UNION | ETS_NULL | + ETS_UNDEFINED | ETS_NONNULLISH, ETS_PRIMITIVE = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_VOID, ETS_PRIMITIVE_RETURN = BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | CHAR | ETS_BOOLEAN | ETS_ENUM, ETS_ARRAY_INDEX = BYTE | SHORT | INT, @@ -109,8 +113,7 @@ 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, - NULLISH = UNDEFINED | NULL_TYPE, - ANY_OR_NULLISH = ANY | NULLISH, + ANY_OR_NULLISH = ANY | UNDEFINED | NULL_TYPE, LITERAL = NUMBER_LITERAL | BOOLEAN_LITERAL | STRING_LITERAL | BIGINT_LITERAL, NUMBER_LIKE = NUMBER | NUMBER_LITERAL, NUMBER_LIKE_ENUM = NUMBER_LIKE | ENUM, @@ -127,10 +130,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 | NULLISH, + UNIT = LITERAL | UNIQUE_SYMBOL | UNDEFINED | NULL_TYPE, GETTER_SETTER = GETTER | SETTER, - CONDITION_EXPRESSION_TYPE = NULLISH | CONSTANT | ETS_OBJECT | BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | - ETS_BOOLEAN | ETS_ARRAY | ETS_ENUM | ETS_STRING_ENUM + CONDITION_EXPRESSION_TYPE = ETS_NULL | ETS_UNDEFINED | ETS_OBJECT | ETS_ARRAY | ETS_UNION | CONSTANT | BYTE | CHAR | + SHORT | INT | LONG | FLOAT | DOUBLE | ETS_BOOLEAN | ETS_ENUM | ETS_STRING_ENUM }; DEFINE_BITOPS(TypeFlag) diff --git a/ets2panda/checker/types/typeMapping.h b/ets2panda/checker/types/typeMapping.h index 12bf57b7d4532a7d23292a1434e1b064f5ef2af2..223d496f094d6c3d9db502bf7131a40dae4b2a73 100644 --- a/ets2panda/checker/types/typeMapping.h +++ b/ets2panda/checker/types/typeMapping.h @@ -50,6 +50,8 @@ _(TypeFlag::CHAR, CharType) \ _(TypeFlag::ETS_BOOLEAN, ETSBooleanType) \ _(TypeFlag::ETS_VOID, ETSVoidType) \ + _(TypeFlag::ETS_NULL, ETSNullType) \ + _(TypeFlag::ETS_UNDEFINED, ETSUndefinedType) \ _(TypeFlag::FUNCTION, ETSFunctionType) \ _(TypeFlag::ETS_OBJECT, ETSObjectType) \ _(TypeFlag::ETS_ARRAY, ETSArrayType) \ @@ -57,6 +59,7 @@ _(TypeFlag::NON_PRIMITIVE, NonPrimitiveType) \ _(TypeFlag::WILDCARD, WildcardType) \ _(TypeFlag::ETS_TYPE_PARAMETER, ETSTypeParameter) \ + _(TypeFlag::ETS_NONNULLISH, ETSNonNullishType) \ _(TypeFlag::ETS_ENUM, ETSEnumType) \ _(TypeFlag::ETS_STRING_ENUM, ETSStringEnumType) \ _(TypeFlag::ETS_EXTENSION_FUNC_HELPER, ETSExtensionFuncHelperType) \ diff --git a/ets2panda/checker/types/typeRelation.h b/ets2panda/checker/types/typeRelation.h index 50a2403bbd56632ef471bcbe4328736c17dc6b57..db8d90a7f64ad960f820ca8b321c34b251b62577 100644 --- a/ets2panda/checker/types/typeRelation.h +++ b/ets2panda/checker/types/typeRelation.h @@ -202,6 +202,11 @@ public: return (flags_ & TypeRelationFlag::UNCHECKED_CAST) != 0; } + [[nodiscard]] bool NoThrow() const noexcept + { + return (flags_ & TypeRelationFlag::NO_THROW) != 0; + } + [[nodiscard]] bool NoThrowGenericTypeAlias() const noexcept { return (flags_ & TypeRelationFlag::NO_THROW_GENERIC_TYPEALIAS) != 0; diff --git a/ets2panda/compiler/base/condition.cpp b/ets2panda/compiler/base/condition.cpp index 8b39ae8638e370f5e0f7119cfcdf875c0123feb1..c83aa5dc6f1b162805f7e370594d7ee3a4df649a 100644 --- a/ets2panda/compiler/base/condition.cpp +++ b/ets2panda/compiler/base/condition.cpp @@ -235,6 +235,13 @@ bool Condition::CompileBinaryExprForBigInt(ETSGen *etsg, const ir::BinaryExpress return true; } +void Condition::CompileInstanceofExpr(ETSGen *etsg, const ir::BinaryExpression *binExpr, Label *falseLabel) +{ + ASSERT(binExpr->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF); + binExpr->Compile(etsg); + etsg->BranchIfFalse(binExpr, falseLabel); +} + bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *binExpr, Label *falseLabel) { if (CompileBinaryExprForBigInt(etsg, binExpr, falseLabel)) { @@ -247,8 +254,7 @@ bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *binE case lexer::TokenType::PUNCTUATOR_LESS_THAN: case lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL: case lexer::TokenType::PUNCTUATOR_GREATER_THAN: - case lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL: - case lexer::TokenType::KEYW_INSTANCEOF: { + case lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL: { auto ttctx = TargetTypeContext(etsg, binExpr->OperationType()); RegScope rs(etsg); @@ -269,6 +275,10 @@ bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *binE CompileLogicalOrExpr(etsg, binExpr, falseLabel); return true; } + case lexer::TokenType::KEYW_INSTANCEOF: { + CompileInstanceofExpr(etsg, binExpr, falseLabel); + return true; + } default: { break; } diff --git a/ets2panda/compiler/base/condition.h b/ets2panda/compiler/base/condition.h index 6d24d5571936c1c1ac171e1a5453f14ac6f2d1fa..d032b3c34e30b3a2f383b48528e282cd6830b062 100644 --- a/ets2panda/compiler/base/condition.h +++ b/ets2panda/compiler/base/condition.h @@ -43,6 +43,7 @@ private: static void CompileLogicalAndExpr(ETSGen *etsg, const ir::BinaryExpression *binExpr, Label *falseLabel); static void CompileLogicalOrExpr(ETSGen *etsg, const ir::BinaryExpression *binExpr, Label *falseLabel); static bool CompileBinaryExprForBigInt(ETSGen *etsg, const ir::BinaryExpression *binExpr, Label *falseLabel); + static void CompileInstanceofExpr(ETSGen *etsg, const ir::BinaryExpression *binExpr, Label *falseLabel); }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/ASTVerifier.cpp b/ets2panda/compiler/core/ASTVerifier.cpp index 405acad229c1357c720e4adf45391f06c60ea615..921d856a990d33e3e3d7fd0282b29760aa0c007f 100644 --- a/ets2panda/compiler/core/ASTVerifier.cpp +++ b/ets2panda/compiler/core/ASTVerifier.cpp @@ -219,7 +219,8 @@ public: ASTVerifier::CheckResult operator()(ASTVerifier::ErrorContext &ctx, const ir::AstNode *ast) { - const auto isEtsScript = ast->IsETSScript(); + const auto isEtsScript = + ast->IsETSScript() || (ast->IsBlockStatement() && ast->AsBlockStatement()->IsProgram()); const auto hasParent = ast->Parent() != nullptr; if (!isEtsScript && !hasParent) { ctx.AddInvariantError("NodeHasParent", "NULL_PARENT", *ast); @@ -361,16 +362,33 @@ public: ASTVerifier::CheckResult operator()(ASTVerifier::ErrorContext &ctx, const ir::AstNode *ast) { + ASSERT(ast != nullptr); + auto result = ASTVerifier::CheckResult::SUCCESS; if (ast->IsETSScript()) { return result; } + ast->Iterate([&](const ir::AstNode *node) { - if (ast != node->Parent()) { + if (ir::AstNode const *parent = node->Parent(); ast != parent) { + // NOTE: Temporary suppress. + // Should be removed after special lowering for lambda-functions will be implemented: #14376 + if ((ast->IsScriptFunction() || ast->IsETSFunctionType()) && parent != nullptr && + parent->IsScriptFunction()) { + return; + } + + // NOTE: Temporary suppress. + // Should be removed after new ENUMs support will be implemented: #14443 + if (ast->IsClassDeclaration() && parent != nullptr && parent->IsETSNewClassInstanceExpression()) { + return; + } + ctx.AddInvariantError("EveryChildHasValidParent", "INCORRECT_PARENT_REF", *node); result = ASTVerifier::CheckResult::FAILED; } }); + return result; } diff --git a/ets2panda/compiler/core/ASTVerifier.h b/ets2panda/compiler/core/ASTVerifier.h index 6602c533f90092723a3f7341b4c60f7a06627dc8..992c007356c923a7dce11d2bcb55509780b1a357 100644 --- a/ets2panda/compiler/core/ASTVerifier.h +++ b/ets2panda/compiler/core/ASTVerifier.h @@ -182,7 +182,8 @@ public: "ImportExportAccessValid", }}; } - const std::set withoutAdditionalChecks = {"PromiseVoidInferencePhase", + const std::set withoutAdditionalChecks = {"OptionalLowering", + "PromiseVoidInferencePhase", "StructLowering", "GenerateTsDeclarationsPhase", "InterfacePropertyDeclarationsPhase", diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index fd2476ce9496e76741c94c109991d3215a2d3eec..d3f9613b23c2e4fdffb59d666de1f74a26c204c0 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -15,14 +15,13 @@ #include "ETSCompiler.h" -#include "checker/types/ets/etsDynamicFunctionType.h" #include "compiler/base/catchTable.h" -#include "checker/types/ts/enumLiteralType.h" #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/ETSGen.h" #include "compiler/core/switchBuilder.h" #include "compiler/function/functionBuilder.h" +#include "checker/types/ets/etsDynamicFunctionType.h" namespace panda::es2panda::compiler { @@ -216,14 +215,14 @@ void ETSCompiler::Compile(const ir::ETSNewArrayInstanceExpression *expr) const compiler::RegScope rs(etsg); compiler::TargetTypeContext ttctx(etsg, etsg->Checker()->GlobalIntType()); - expr->dimension_->Compile(etsg); + expr->Dimension()->Compile(etsg); compiler::VReg arr = etsg->AllocReg(); compiler::VReg dim = etsg->AllocReg(); - etsg->ApplyConversionAndStoreAccumulator(expr, dim, expr->dimension_->TsType()); + etsg->ApplyConversionAndStoreAccumulator(expr, dim, expr->Dimension()->TsType()); etsg->NewArray(expr, arr, dim, expr->TsType()); - if (expr->defaultConstructorSignature_ != nullptr) { + if (expr->Signature() != nullptr) { compiler::VReg countReg = etsg->AllocReg(); auto *startLabel = etsg->AllocLabel(); auto *endLabel = etsg->AllocLabel(); @@ -236,10 +235,10 @@ void ETSCompiler::Compile(const ir::ETSNewArrayInstanceExpression *expr) const etsg->LoadAccumulator(expr, countReg); etsg->StoreAccumulator(expr, indexReg); - const compiler::TargetTypeContext ttctx2(etsg, expr->typeReference_->TsType()); - ArenaVector arguments(expr->allocator_->Adapter()); - etsg->InitObject(expr, expr->defaultConstructorSignature_, arguments); - etsg->StoreArrayElement(expr, arr, indexReg, expr->typeReference_->TsType()); + const compiler::TargetTypeContext ttctx2(etsg, expr->TypeReference()->TsType()); + ArenaVector arguments(GetCodeGen()->Allocator()->Adapter()); + etsg->InitObject(expr, expr->Signature(), arguments); + etsg->StoreArrayElement(expr, arr, indexReg, expr->TypeReference()->TsType()); etsg->IncrementImmediateRegister(expr, countReg, checker::TypeFlag::INT, static_cast(1)); etsg->JumpTo(expr, startLabel); @@ -328,15 +327,13 @@ void ETSCompiler::Compile(const ir::ETSNewClassInstanceExpression *expr) const etsg->InitObject(expr, expr->signature_, expr->GetArguments()); } - if (expr->GetBoxingUnboxingFlags() == ir::BoxingUnboxingFlags::NONE) { - etsg->SetAccumulatorType(expr->TsType()); - } + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile(const ir::ETSNewMultiDimArrayInstanceExpression *expr) const { ETSGen *etsg = GetETSGen(); - etsg->InitObject(expr, expr->signature_, expr->dimensions_); + etsg->InitObject(expr, expr->Signature(), expr->Dimensions()); etsg->SetAccumulatorType(expr->TsType()); } @@ -373,6 +370,18 @@ void ETSCompiler::Compile(const ir::ETSTypeReferencePart *node) const node->Name()->Compile(etsg); } +void ETSCompiler::Compile(const ir::ETSNullType *node) const +{ + (void)node; + UNREACHABLE(); +} + +void ETSCompiler::Compile(const ir::ETSUndefinedType *node) const +{ + (void)node; + UNREACHABLE(); +} + void ETSCompiler::Compile(const ir::ETSUnionType *node) const { (void)node; @@ -471,7 +480,7 @@ void ETSCompiler::Compile(const ir::AwaitExpression *expr) const expr->Argument()->Compile(etsg); etsg->StoreAccumulator(expr, argumentReg); etsg->CallThisVirtual0(expr->Argument(), argumentReg, compiler::Signatures::BUILTIN_PROMISE_AWAIT_RESOLUTION); - etsg->CastToArrayOrObject(expr->Argument(), expr->TsType(), IS_UNCHECKED_CAST); + etsg->CastToReftype(expr->Argument(), expr->TsType(), IS_UNCHECKED_CAST); etsg->SetAccumulatorType(expr->TsType()); } @@ -479,14 +488,14 @@ static void CompileNullishCoalescing(compiler::ETSGen *etsg, ir::BinaryExpressio { auto const compileOperand = [etsg, optype = node->OperationType()](ir::Expression const *expr) { etsg->CompileAndCheck(expr); - etsg->ApplyConversion(expr, optype); + etsg->ApplyConversion(expr, nullptr); }; compileOperand(node->Left()); - if (!etsg->Checker()->MayHaveNulllikeValue(node->Left()->TsType())) { + if (node->Left()->TsType()->DefinitelyNotETSNullish()) { // fallthrough - } else if (node->Left()->TsType()->IsETSNullLike()) { + } else if (node->Left()->TsType()->DefinitelyETSNullish()) { compileOperand(node->Right()); } else { auto *ifLeftNullish = etsg->AllocLabel(); @@ -494,7 +503,7 @@ static void CompileNullishCoalescing(compiler::ETSGen *etsg, ir::BinaryExpressio etsg->BranchIfNullish(node, ifLeftNullish); - etsg->ConvertToNonNullish(node); + etsg->AssumeNonNullish(node, node->OperationType()); etsg->ApplyConversion(node->Left(), node->OperationType()); etsg->JumpTo(node, endLabel); @@ -548,6 +557,28 @@ static void CompileLogical(compiler::ETSGen *etsg, const ir::BinaryExpression *e etsg->SetLabel(expr, endLabel); etsg->SetAccumulatorType(expr->TsType()); + etsg->ApplyConversion(expr, expr->OperationType()); +} + +static void CompileInstanceof(compiler::ETSGen *etsg, const ir::BinaryExpression *expr) +{ + ASSERT(expr->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF); + auto ttctx = compiler::TargetTypeContext(etsg, expr->OperationType()); + compiler::RegScope rs(etsg); + auto lhs = etsg->AllocReg(); + + expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); + + if (expr->Right()->TsType()->IsETSDynamicType()) { + auto rhs = etsg->AllocReg(); + expr->Right()->Compile(etsg); + etsg->StoreAccumulator(expr, rhs); + etsg->IsInstanceDynamic(expr, lhs, rhs); + } else { + etsg->IsInstance(expr, lhs, expr->Right()->TsType()); + } + ASSERT(etsg->GetAccumulatorType() == expr->TsType()); } std::map &GetBigintSignatures() @@ -631,14 +662,16 @@ void ETSCompiler::Compile(const ir::BinaryExpression *expr) const return; } - auto ttctx = compiler::TargetTypeContext(etsg, expr->OperationType()); - if (expr->IsLogical()) { CompileLogical(etsg, expr); - etsg->ApplyConversion(expr, expr->OperationType()); + return; + } + if (expr->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF) { + CompileInstanceof(etsg, expr); return; } + auto ttctx = compiler::TargetTypeContext(etsg, expr->OperationType()); compiler::RegScope rs(etsg); compiler::VReg lhs = etsg->AllocReg(); @@ -659,11 +692,12 @@ void ETSCompiler::Compile(const ir::BinaryExpression *expr) const etsg->Binary(expr, expr->OperatorType(), lhs); } -static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::CallExpression *expr) +static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::CallExpression *expr, + checker::Signature *signature) { - if (expr->Signature()->RestVar() != nullptr) { + if (signature->RestVar() != nullptr) { std::size_t const argumentCount = expr->Arguments().size(); - std::size_t const parameterCount = expr->Signature()->MinArgCount(); + std::size_t const parameterCount = signature->MinArgCount(); ASSERT(argumentCount >= parameterCount); auto &arguments = const_cast &>(expr->Arguments()); @@ -678,13 +712,37 @@ static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::C } auto *arrayExpression = checker->AllocNode(std::move(elements), checker->Allocator()); arrayExpression->SetParent(const_cast(expr)); - arrayExpression->SetTsType(expr->Signature()->RestVar()->TsType()); + arrayExpression->SetTsType(signature->RestVar()->TsType()); arguments.erase(expr->Arguments().begin() + parameterCount, expr->Arguments().end()); arguments.emplace_back(arrayExpression); } } } +void ConvertArgumentsForFunctionalCall(checker::ETSChecker *const checker, const ir::CallExpression *expr) +{ + std::size_t const argumentCount = expr->Arguments().size(); + auto &arguments = const_cast &>(expr->Arguments()); + auto *signature = expr->Signature(); + + for (size_t i = 0; i < argumentCount; i++) { + auto *paramType = checker->MaybeBoxedType( + i < signature->Params().size() ? signature->Params()[i] : signature->RestVar(), checker->Allocator()); + + auto *arg = arguments[i]; + auto *cast = checker->Allocator()->New(arg, nullptr, false); + arguments[i]->SetParent(cast); + cast->SetParent(const_cast(expr)); + cast->SetTsType(paramType); + + if (paramType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + cast->AddBoxingUnboxingFlags(checker->GetBoxingFlag(paramType)); + } + + arguments[i] = cast; + } +} + void ETSCompiler::Compile(const ir::BlockExpression *expr) const { (void)expr; @@ -787,13 +845,15 @@ void ETSCompiler::CompileDynamic(const ir::CallExpression *expr, compiler::VReg etsg->StoreAccumulator(expr, dynParam2); etsg->CallDynamic(expr, calleeReg, dynParam2, expr->Signature(), expr->Arguments()); etsg->SetAccumulatorType(expr->Signature()->ReturnType()); + if (etsg->GetAccumulatorType() != expr->TsType()) { etsg->ApplyConversion(expr, expr->TsType()); } } // Helper function to avoid branching in non optional cases -void ETSCompiler::EmitCall(const ir::CallExpression *expr, compiler::VReg &calleeReg, bool isStatic) const +void ETSCompiler::EmitCall(const ir::CallExpression *expr, compiler::VReg &calleeReg, bool isStatic, + checker::Signature *signature, bool isReference) const { ETSGen *etsg = GetETSGen(); if (expr->Callee()->GetBoxingUnboxingFlags() != ir::BoxingUnboxingFlags::NONE) { @@ -804,12 +864,40 @@ void ETSCompiler::EmitCall(const ir::CallExpression *expr, compiler::VReg &calle } else if (expr->Signature()->HasSignatureFlag(checker::SignatureFlags::PRIVATE) || expr->IsETSConstructorCall() || (expr->Callee()->IsMemberExpression() && expr->Callee()->AsMemberExpression()->Object()->IsSuperExpression())) { - etsg->CallThisStatic(expr, calleeReg, expr->Signature(), expr->Arguments()); + etsg->CallThisStatic(expr, calleeReg, signature, expr->Arguments()); + } else { + etsg->CallThisVirtual(expr, calleeReg, signature, expr->Arguments()); + } + + if (isReference) { + etsg->CheckedReferenceNarrowing(expr, signature->ReturnType()); } else { - etsg->CallThisVirtual(expr, calleeReg, expr->Signature(), expr->Arguments()); + etsg->SetAccumulatorType(signature->ReturnType()); } - etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->OptionalType()); + etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->TsType()); +} + +static checker::Signature *ConvertArgumentsForFunctionReference(ETSGen *etsg, const ir::CallExpression *expr) +{ + checker::Signature *origSignature = expr->Signature(); + + auto *funcType = + origSignature->Owner() + ->GetOwnProperty(checker::FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME) + ->TsType() + ->AsETSFunctionType(); + ASSERT(funcType->CallSignatures().size() == 1); + checker::Signature *signature = funcType->CallSignatures()[0]; + + if (signature->ReturnType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + expr->AddBoxingUnboxingFlags(const_cast(etsg->Checker()->AsETSChecker()) + ->GetUnboxingFlag(signature->ReturnType())); + } + + ConvertArgumentsForFunctionalCall(const_cast(etsg->Checker()->AsETSChecker()), expr); + + return signature; } void ETSCompiler::Compile(const ir::CallExpression *expr) const @@ -829,7 +917,12 @@ void ETSCompiler::Compile(const ir::CallExpression *expr) const bool isReference = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE); bool isDynamic = expr->Callee()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); - ConvertRestArguments(const_cast(etsg->Checker()->AsETSChecker()), expr); + checker::Signature *signature = expr->Signature(); + if (isReference) { + signature = ConvertArgumentsForFunctionReference(etsg, expr); + } + + ConvertRestArguments(const_cast(etsg->Checker()->AsETSChecker()), expr, signature); if (isDynamic) { CompileDynamic(expr, calleeReg); @@ -838,25 +931,23 @@ void ETSCompiler::Compile(const ir::CallExpression *expr) const etsg->LoadThis(expr); etsg->StoreAccumulator(expr, calleeReg); } - EmitCall(expr, calleeReg, isStatic); + EmitCall(expr, calleeReg, isStatic, signature, isReference); } else if (!isReference && expr->Callee()->IsMemberExpression()) { if (!isStatic) { expr->Callee()->AsMemberExpression()->Object()->Compile(etsg); etsg->StoreAccumulator(expr, calleeReg); } - EmitCall(expr, calleeReg, isStatic); + EmitCall(expr, calleeReg, isStatic, signature, isReference); } else if (expr->Callee()->IsSuperExpression() || expr->Callee()->IsThisExpression()) { ASSERT(!isReference && expr->IsETSConstructorCall()); expr->Callee()->Compile(etsg); // ctor is not a value! etsg->SetVRegType(calleeReg, etsg->GetAccumulatorType()); - EmitCall(expr, calleeReg, isStatic); + EmitCall(expr, calleeReg, isStatic, signature, isReference); } else { ASSERT(isReference); etsg->CompileAndCheck(expr->Callee()); etsg->StoreAccumulator(expr, calleeReg); - etsg->EmitMaybeOptional( - expr, [this, expr, isStatic, &calleeReg]() { this->EmitCall(expr, calleeReg, isStatic); }, - expr->IsOptional()); + EmitCall(expr, calleeReg, isStatic, signature, isReference); } } @@ -888,11 +979,7 @@ void ETSCompiler::Compile(const ir::ConditionalExpression *expr) const expr->Alternate()->Compile(etsg); etsg->ApplyConversion(expr->Alternate()); etsg->SetLabel(expr, endLabel); - if (expr->TsType()->IsETSUnionType()) { - etsg->SetAccumulatorType(expr->TsType()->AsETSUnionType()->GetLeastUpperBoundType()); - } else { - etsg->SetAccumulatorType(expr->TsType()); - } + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile([[maybe_unused]] const ir::DirectEvalExpression *expr) const @@ -920,7 +1007,7 @@ void ETSCompiler::Compile(const ir::Identifier *expr) const if (!expr->Variable()->HasFlag(varbinder::VariableFlags::TYPE_ALIAS)) { etsg->LoadVar(expr, expr->Variable()); } else { - etsg->LoadVar(expr, expr->TsType()->Variable()); + etsg->SetAccumulatorType(expr->TsType()); } } @@ -931,38 +1018,31 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::ImportExpression *expr) con static bool CompileComputed(compiler::ETSGen *etsg, const ir::MemberExpression *expr) { - if (expr->IsComputed()) { - auto *const objectType = etsg->Checker()->GetNonNullishType(expr->Object()->TsType()); - - auto ottctx = compiler::TargetTypeContext(etsg, expr->Object()->TsType()); - etsg->CompileAndCheck(expr->Object()); - - auto const loadElement = [expr, etsg, objectType]() { - compiler::VReg objReg = etsg->AllocReg(); - etsg->StoreAccumulator(expr, objReg); + if (!expr->IsComputed()) { + return false; + } + auto *const objectType = expr->Object()->TsType(); - etsg->CompileAndCheck(expr->Property()); - etsg->ApplyConversion(expr->Property(), expr->Property()->TsType()); + auto ottctx = compiler::TargetTypeContext(etsg, expr->Object()->TsType()); + etsg->CompileAndCheck(expr->Object()); - auto ttctx = compiler::TargetTypeContext(etsg, expr->OptionalType()); + compiler::VReg objReg = etsg->AllocReg(); + etsg->StoreAccumulator(expr, objReg); - if (objectType->IsETSDynamicType()) { - etsg->LoadElementDynamic(expr, objReg); - } else { - etsg->LoadArrayElement(expr, objReg); - } + etsg->CompileAndCheck(expr->Property()); + etsg->ApplyConversion(expr->Property(), expr->Property()->TsType()); - if (expr->Object()->TsType()->IsETSTupleType() && (expr->GetTupleConvertedType() != nullptr)) { - etsg->InternalCheckCast(expr, expr->GetTupleConvertedType()); - } - - etsg->ApplyConversion(expr); - }; + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); - etsg->EmitMaybeOptional(expr, loadElement, expr->IsOptional()); - return true; + if (objectType->IsETSDynamicType()) { + etsg->LoadElementDynamic(expr, objReg); + } else { + etsg->LoadArrayElement(expr, objReg); } - return false; + + etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->TsType()); + etsg->ApplyConversion(expr); + return true; } void ETSCompiler::Compile(const ir::MemberExpression *expr) const @@ -977,8 +1057,7 @@ void ETSCompiler::Compile(const ir::MemberExpression *expr) const compiler::RegScope rs(etsg); - auto *const objectType = - checker::ETSChecker::GetApparentType(etsg->Checker()->GetNonNullishType(expr->Object()->TsType())); + auto *const objectType = etsg->Checker()->GetApparentType(expr->Object()->TsType()); if (CompileComputed(etsg, expr)) { return; @@ -990,34 +1069,30 @@ void ETSCompiler::Compile(const ir::MemberExpression *expr) const auto ottctx = compiler::TargetTypeContext(etsg, objectType); etsg->CompileAndCheck(expr->Object()); - auto const loadLength = [expr, etsg]() { - compiler::VReg objReg = etsg->AllocReg(); - etsg->StoreAccumulator(expr, objReg); - - auto ttctx = compiler::TargetTypeContext(etsg, expr->OptionalType()); - etsg->LoadArrayLength(expr, objReg); - etsg->ApplyConversion(expr, expr->TsType()); - }; + compiler::VReg objReg = etsg->AllocReg(); + etsg->StoreAccumulator(expr, objReg); - etsg->EmitMaybeOptional(expr, loadLength, expr->IsOptional()); + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + etsg->LoadArrayLength(expr, objReg); + etsg->ApplyConversion(expr, expr->TsType()); return; } if (objectType->IsETSEnumType() || objectType->IsETSStringEnumType()) { auto const *const enumInterface = [objectType, expr]() -> checker::ETSEnumInterface const * { if (objectType->IsETSEnumType()) { - return expr->OptionalType()->AsETSEnumType(); + return expr->TsType()->AsETSEnumType(); } - return expr->OptionalType()->AsETSStringEnumType(); + return expr->TsType()->AsETSStringEnumType(); }(); - auto ttctx = compiler::TargetTypeContext(etsg, expr->OptionalType()); + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); etsg->LoadAccumulatorInt(expr, enumInterface->GetOrdinal()); return; } if (etsg->Checker()->IsVariableStatic(expr->PropVar())) { - auto ttctx = compiler::TargetTypeContext(etsg, expr->OptionalType()); + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); if (expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { checker::Signature *sig = expr->PropVar()->TsType()->AsETSFunctionType()->FindGetter(); @@ -1027,35 +1102,31 @@ void ETSCompiler::Compile(const ir::MemberExpression *expr) const } util::StringView fullName = etsg->FormClassPropReference(expr->Object()->TsType()->AsETSObjectType(), propName); - etsg->LoadStaticProperty(expr, expr->OptionalType(), fullName); + etsg->LoadStaticProperty(expr, expr->TsType(), fullName); return; } auto ottctx = compiler::TargetTypeContext(etsg, expr->Object()->TsType()); etsg->CompileAndCheck(expr->Object()); - auto const loadProperty = [expr, etsg, propName, objectType]() { - etsg->ApplyConversion(expr->Object()); - compiler::VReg objReg = etsg->AllocReg(); - etsg->StoreAccumulator(expr, objReg); - - auto ttctx = compiler::TargetTypeContext(etsg, expr->OptionalType()); + etsg->ApplyConversion(expr->Object()); + compiler::VReg objReg = etsg->AllocReg(); + etsg->StoreAccumulator(expr, objReg); - if (expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { - checker::Signature *sig = expr->PropVar()->TsType()->AsETSFunctionType()->FindGetter(); - etsg->CallThisVirtual0(expr, objReg, sig->InternalName()); - } else if (objectType->IsETSDynamicType()) { - etsg->LoadPropertyDynamic(expr, expr->OptionalType(), objReg, propName); - } else if (objectType->IsETSUnionType()) { - etsg->LoadUnionProperty(expr, expr->OptionalType(), objReg, propName); - } else { - const auto fullName = etsg->FormClassPropReference(objectType->AsETSObjectType(), propName); - etsg->LoadProperty(expr, expr->OptionalType(), objReg, fullName); - } - etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->OptionalType()); - }; + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); - etsg->EmitMaybeOptional(expr, loadProperty, expr->IsOptional()); + if (expr->PropVar()->TsType()->HasTypeFlag(checker::TypeFlag::GETTER_SETTER)) { + checker::Signature *sig = expr->PropVar()->TsType()->AsETSFunctionType()->FindGetter(); + etsg->CallThisVirtual0(expr, objReg, sig->InternalName()); + } else if (objectType->IsETSDynamicType()) { + etsg->LoadPropertyDynamic(expr, expr->TsType(), objReg, propName); + } else if (objectType->IsETSUnionType()) { + etsg->LoadUnionProperty(expr, expr->TsType(), objReg, propName); + } else { + const auto fullName = etsg->FormClassPropReference(objectType->AsETSObjectType(), propName); + etsg->LoadProperty(expr, expr->TsType(), objReg, fullName); + } + etsg->GuardUncheckedType(expr, expr->UncheckedType(), expr->TsType()); } void ETSCompiler::Compile([[maybe_unused]] const ir::NewExpression *expr) const @@ -1588,11 +1659,13 @@ void ETSCompiler::Compile(const ir::IfStatement *st) const ETSGen *etsg = GetETSGen(); auto res = compiler::Condition::CheckConstantExpr(etsg, st->Test()); if (res == compiler::Condition::Result::CONST_TRUE) { + st->Test()->Compile(etsg); st->Consequent()->Compile(etsg); return; } if (res == compiler::Condition::Result::CONST_FALSE) { + st->Test()->Compile(etsg); if (st->Alternate() != nullptr) { st->Alternate()->Compile(etsg); } @@ -1828,7 +1901,7 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::TSArrayType *node) const void ETSCompiler::CompileCastUnboxable(const ir::TSAsExpression *expr) const { ETSGen *etsg = GetETSGen(); - auto *targetType = expr->TsType(); + auto *targetType = etsg->Checker()->GetApparentType(expr->TsType()); ASSERT(targetType->IsETSObjectType()); switch (targetType->AsETSObjectType()->BuiltInKind()) { @@ -1873,7 +1946,7 @@ void ETSCompiler::CompileCastUnboxable(const ir::TSAsExpression *expr) const void ETSCompiler::CompileCast(const ir::TSAsExpression *expr) const { ETSGen *etsg = GetETSGen(); - auto *targetType = expr->TsType(); + auto *targetType = etsg->Checker()->GetApparentType(expr->TsType()); switch (checker::ETSChecker::TypeKind(targetType)) { case checker::TypeFlag::ETS_BOOLEAN: { @@ -1910,8 +1983,12 @@ void ETSCompiler::CompileCast(const ir::TSAsExpression *expr) const } case checker::TypeFlag::ETS_ARRAY: case checker::TypeFlag::ETS_OBJECT: - case checker::TypeFlag::ETS_TYPE_PARAMETER: { - etsg->CastToArrayOrObject(expr, targetType, expr->isUncheckedCast_); + case checker::TypeFlag::ETS_TYPE_PARAMETER: + case checker::TypeFlag::ETS_NONNULLISH: + case checker::TypeFlag::ETS_UNION: + case checker::TypeFlag::ETS_NULL: + case checker::TypeFlag::ETS_UNDEFINED: { + etsg->CastToReftype(expr, targetType, expr->isUncheckedCast_); break; } case checker::TypeFlag::ETS_DYNAMIC_TYPE: { @@ -1945,7 +2022,7 @@ void ETSCompiler::Compile(const ir::TSAsExpression *expr) const expr->Expr()->Compile(etsg); } - auto *targetType = expr->TsType(); + auto *targetType = etsg->Checker()->GetApparentType(expr->TsType()); if ((expr->Expr()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U) { etsg->ApplyUnboxingConversion(expr->Expr()); @@ -1964,10 +2041,6 @@ void ETSCompiler::Compile(const ir::TSAsExpression *expr) const etsg->ApplyBoxingConversion(expr->Expr()); } - if (targetType->IsETSUnionType()) { - targetType->AsETSUnionType()->FindTypeIsCastableToThis(expr->expression_, etsg->Checker()->Relation(), - expr->expression_->TsType()); - } CompileCast(expr); } @@ -2093,11 +2166,11 @@ void ETSCompiler::Compile(const ir::TSNonNullExpression *expr) const expr->Expr()->Compile(etsg); - if (!etsg->Checker()->MayHaveNulllikeValue(etsg->GetAccumulatorType())) { + if (etsg->GetAccumulatorType()->DefinitelyNotETSNullish()) { return; } - if (etsg->GetAccumulatorType()->IsETSNullLike()) { + if (etsg->GetAccumulatorType()->DefinitelyETSNullish()) { etsg->EmitNullishException(expr); return; } @@ -2113,7 +2186,7 @@ void ETSCompiler::Compile(const ir::TSNonNullExpression *expr) const etsg->SetLabel(expr, endLabel); etsg->LoadAccumulator(expr, arg); - etsg->ConvertToNonNullish(expr); + etsg->AssumeNonNullish(expr, expr->TsType()); } void ETSCompiler::Compile([[maybe_unused]] const ir::TSNullKeyword *node) const diff --git a/ets2panda/compiler/core/ETSCompiler.h b/ets2panda/compiler/core/ETSCompiler.h index 5421dde41f556632d1816b3a6b7d8629a288390a..4e0e04dbd3533afc6f9d663515873a6b8508c7cf 100644 --- a/ets2panda/compiler/core/ETSCompiler.h +++ b/ets2panda/compiler/core/ETSCompiler.h @@ -38,7 +38,8 @@ private: void CompileDynamic(const ir::CallExpression *expr, compiler::VReg &calleeReg) const; void CompileCastUnboxable(const ir::TSAsExpression *expr) const; void CompileCast(const ir::TSAsExpression *expr) const; - void EmitCall(const ir::CallExpression *expr, compiler::VReg &calleeReg, bool isStatic) const; + void EmitCall(const ir::CallExpression *expr, compiler::VReg &calleeReg, bool isStatic, + checker::Signature *signature, bool isReference) const; ETSGen *GetETSGen() const; }; diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 9274234954f7ee0ee3b3571792d2b28c79c2358b..e1f8138eb29db772f7114f533293332298ca1069 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -46,8 +46,10 @@ namespace panda::es2panda::compiler { -static constexpr auto TYPE_FLAG_BYTECODE_REF = - checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION | checker::TypeFlag::ETS_TYPE_PARAMETER; +static constexpr auto TYPE_FLAG_BYTECODE_REF = checker::TypeFlag::ETS_ARRAY | checker::TypeFlag::ETS_OBJECT | + checker::TypeFlag::ETS_UNION | checker::TypeFlag::ETS_TYPE_PARAMETER | + checker::TypeFlag::ETS_NONNULLISH | checker::TypeFlag::ETS_NULL | + checker::TypeFlag::ETS_UNDEFINED; ETSGen::ETSGen(ArenaAllocator *allocator, RegSpiller *spiller, CompilerContext *context, varbinder::FunctionScope *scope, ProgramElement *programElement, AstCompiler *astcompiler) noexcept @@ -90,7 +92,8 @@ void ETSGen::CompileAndCheck(const ir::Expression *expr) return; } - ASSERT(!"Type mismatch after Expression::Compile"); + ASSERT_PRINT(false, std::string("Type mismatch after Expression::Compile: ") + accType->ToString() + + " instead of " + expr->TsType()->ToString()); } const checker::ETSChecker *ETSGen::Checker() const noexcept @@ -749,103 +752,207 @@ void ETSGen::ReturnAcc(const ir::AstNode *node) } } -void ETSGen::EmitIsInstanceNonNullish([[maybe_unused]] const ir::AstNode *const node, - [[maybe_unused]] const VReg objReg, - [[maybe_unused]] checker::ETSObjectType const *clsType) +static bool IsAnyReferenceSupertype(checker::Type const *type) { -#ifdef PANDA_WITH_ETS - auto const objType = GetVRegType(objReg); - // undefined is implemented as Object instance, so "instanceof Object" must be treated carefully - if (!Checker()->MayHaveUndefinedValue(objType) || clsType != Checker()->GlobalETSObjectType()) { - LoadAccumulator(node, objReg); - Sa().Emit(node, clsType->AssemblerName()); - SetAccumulatorType(Checker()->GlobalETSBooleanType()); - return; + if (!type->IsETSUnionType()) { + return false; } + auto const &constituent = type->AsETSUnionType()->ConstituentTypes(); + return constituent.size() == 3U && std::all_of(constituent.begin(), constituent.end(), [](checker::Type *t) { + return t->IsETSNullType() || t->IsETSUndefinedType() || + (t->IsETSObjectType() && t->AsETSObjectType()->IsGlobalETSObjectType()); + }); +} - Label *lundef = AllocLabel(); - Label *lend = AllocLabel(); +void ETSGen::IsInstanceDynamic(const ir::AstNode *const node, const VReg srcReg, [[maybe_unused]] const VReg tgtReg) +{ + ASSERT(Checker()->GetApparentType(GetVRegType(tgtReg))->IsETSDynamicType() && + GetVRegType(srcReg)->IsETSDynamicType()); + Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, srcReg, MoveAccToReg(node)); + SetAccumulatorType(Checker()->GlobalETSBooleanType()); +} - LoadAccumulator(node, objReg); - Sa().Emit(node); - BranchIfTrue(node, lundef); +void ETSGen::TestIsInstanceConstituent(const ir::AstNode *const node, Label *ifTrue, Label *ifFalse, + checker::Type const *target, bool acceptUndefined) +{ + ASSERT(!target->IsETSDynamicType()); - LoadAccumulator(node, objReg); - Sa().Emit(node, clsType->AssemblerName()); - JumpTo(node, lend); + switch (checker::ETSChecker::ETSType(target)) { + case checker::TypeFlag::ETS_NULL: { + BranchIfNull(node, ifTrue); + break; + } + case checker::TypeFlag::ETS_UNDEFINED: { + EmitIsUndefined(node); + BranchIfTrue(node, ifTrue); + break; + } + case checker::TypeFlag::ETS_OBJECT: { + if (!target->AsETSObjectType()->IsGlobalETSObjectType()) { + Sa().Emit(node, ToAssemblerType(target)); + BranchIfTrue(node, ifTrue); + break; + } + if (!acceptUndefined) { + EmitIsUndefined(node); + BranchIfTrue(node, ifFalse); + } + JumpTo(node, ifTrue); + break; + } + case checker::TypeFlag::ETS_ARRAY: { + Sa().Emit(node, ToAssemblerType(target)); + BranchIfTrue(node, ifTrue); + break; + } + default: + UNREACHABLE(); // other types must not appear here + } + SetAccumulatorType(nullptr); +} - SetLabel(node, lundef); - LoadAccumulatorBoolean(node, false); +void ETSGen::BranchIfIsInstance(const ir::AstNode *const node, const VReg srcReg, const checker::Type *target, + Label *ifTrue) +{ + ASSERT(target == Checker()->GetApparentType(target)); + auto ifFalse = AllocLabel(); - SetLabel(node, lend); -#else - UNREACHABLE(); -#endif // PANDA_WITH_ETS + bool const allowUndefined = target->PossiblyETSUndefined(); + if (!target->PossiblyETSNull()) { + LoadAccumulator(node, srcReg); + BranchIfNull(node, ifFalse); + } + + auto const checkType = [this, srcReg, ifTrue, ifFalse, allowUndefined](const ir::AstNode *const n, + checker::Type const *t) { + LoadAccumulator(n, srcReg); + TestIsInstanceConstituent(n, ifTrue, ifFalse, t, allowUndefined); + }; + + if (!target->IsETSUnionType()) { + checkType(node, target); + } else { + for (auto *ct : target->AsETSUnionType()->ConstituentTypes()) { + checkType(node, ct); + } + } + SetLabel(node, ifFalse); + SetAccumulatorType(nullptr); } -void ETSGen::EmitIsInstance([[maybe_unused]] const ir::AstNode *const node, [[maybe_unused]] const VReg objReg) +void ETSGen::IsInstance(const ir::AstNode *const node, const VReg srcReg, const checker::Type *target) { -#ifdef PANDA_WITH_ETS - auto const *rhsType = node->AsBinaryExpression()->Right()->TsType()->AsETSObjectType(); - auto const *lhsType = GetVRegType(objReg); + target = Checker()->GetApparentType(target); + ASSERT(target->IsETSReferenceType()); - if (rhsType->IsETSDynamicType() || lhsType->IsETSDynamicType()) { - ASSERT(rhsType->IsETSDynamicType() && lhsType->IsETSDynamicType()); - Ra().Emit(node, Signatures::BUILTIN_JSRUNTIME_INSTANCE_OF, objReg, MoveAccToReg(node)); - SetAccumulatorType(Checker()->GlobalETSBooleanType()); + if (IsAnyReferenceSupertype(target)) { // should be IsSupertypeOf(target, source) + LoadAccumulatorBoolean(node, true); return; } - - if (!Checker()->MayHaveNulllikeValue(rhsType)) { - EmitIsInstanceNonNullish(node, objReg, rhsType); + if (target->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) && + GetAccumulatorType()->DefinitelyNotETSNullish()) { + InternalIsInstance(node, target); return; } auto ifTrue = AllocLabel(); auto end = AllocLabel(); - LoadAccumulator(node, objReg); - - // Iterate union members - if (Checker()->MayHaveNullValue(rhsType)) { - BranchIfNull(node, ifTrue); - } - if (Checker()->MayHaveUndefinedValue(rhsType)) { - Sa().Emit(node); - BranchIfTrue(node, ifTrue); - LoadAccumulator(node, objReg); - } - if (rhsType->IsETSNullLike()) { - LoadAccumulatorBoolean(node, false); - } else { - EmitIsInstanceNonNullish(node, objReg, Checker()->GetNonNullishType(rhsType)->AsETSObjectType()); - } + BranchIfIsInstance(node, srcReg, target, ifTrue); + LoadAccumulatorBoolean(node, false); JumpTo(node, end); SetLabel(node, ifTrue); LoadAccumulatorBoolean(node, true); SetLabel(node, end); -#else - UNREACHABLE(); -#endif // PANDA_WITH_ETS } +// isinstance can only be used for Object and [] types, ensure source is not nullish! +void ETSGen::InternalIsInstance(const ir::AstNode *node, const es2panda::checker::Type *target) +{ + ASSERT(target->IsETSObjectType() || target->IsETSArrayType()); + if (!target->IsETSObjectType() || !target->AsETSObjectType()->IsGlobalETSObjectType()) { + Sa().Emit(node, ToAssemblerType(target)); + SetAccumulatorType(Checker()->GlobalETSBooleanType()); + } else { + LoadAccumulatorBoolean(node, true); + } +} + +// checkcast can only be used for Object and [] types, ensure source is not nullish! void ETSGen::InternalCheckCast(const ir::AstNode *node, const es2panda::checker::Type *target) { - ASSERT(target->IsETSObjectType() && !target->IsNullishOrNullLike()); - Sa().Emit(node, ToAssemblerType(target)); + ASSERT(target->IsETSObjectType() || target->IsETSArrayType()); + if (!target->IsETSObjectType() || !target->AsETSObjectType()->IsGlobalETSObjectType()) { + Sa().Emit(node, ToAssemblerType(target)); + } SetAccumulatorType(target); } +// optimized specialization for object and [] targets +void ETSGen::CheckedReferenceNarrowingObject(const ir::AstNode *node, const checker::Type *target) +{ + const RegScope rs(this); + const auto srcReg = AllocReg(); + StoreAccumulator(node, srcReg); + + auto isNullish = AllocLabel(); + auto end = AllocLabel(); + bool nullishCheck = false; + + auto *source = GetAccumulatorType(); + if (source->PossiblyETSNull()) { + nullishCheck = true; + BranchIfNull(node, isNullish); + } + if (source->PossiblyETSUndefined() && target->IsETSObjectType() && + target->AsETSObjectType()->IsGlobalETSObjectType()) { + nullishCheck = true; + EmitIsUndefined(node); + BranchIfTrue(node, isNullish); + } + + if (!nullishCheck) { + InternalCheckCast(node, target); + } else { + LoadAccumulator(node, srcReg); + InternalCheckCast(node, target); + JumpTo(node, end); + + SetLabel(node, isNullish); + EmitFailedTypeCastException(node, srcReg, target); + + SetLabel(node, end); + SetAccumulatorType(target); + } +} + void ETSGen::CheckedReferenceNarrowing(const ir::AstNode *node, const checker::Type *target) { - ASSERT(target->HasTypeFlag(TYPE_FLAG_BYTECODE_REF) && !target->IsETSNullLike()); - // NOTE(vpukhov): implement for nulllike and union targets - if (target == Checker()->GlobalETSNullishObjectType()) { + target = Checker()->GetApparentType(target); + ASSERT(target->IsETSReferenceType()); + + if (IsAnyReferenceSupertype(target)) { // should be IsSupertypeOf(target, source) SetAccumulatorType(target); return; } + if (target->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { + CheckedReferenceNarrowingObject(node, target); + return; + } + const RegScope rs(this); + const auto srcReg = AllocReg(); + auto ifTrue = AllocLabel(); + + StoreAccumulator(node, srcReg); + BranchIfIsInstance(node, srcReg, target, ifTrue); + + EmitFailedTypeCastException(node, srcReg, target); + + SetLabel(node, ifTrue); + LoadAccumulator(node, srcReg); + // Verifier can't infer type if isinstance met, help him Sa().Emit(node, ToAssemblerType(target)); SetAccumulatorType(target); } @@ -854,12 +961,24 @@ void ETSGen::GuardUncheckedType(const ir::AstNode *node, const checker::Type *un { if (unchecked != nullptr) { SetAccumulatorType(unchecked); - CheckedReferenceNarrowing(node, target); + CheckedReferenceNarrowing(node, Checker()->MaybePromotedBuiltinType(target)); } else { SetAccumulatorType(target); } } +void ETSGen::EmitFailedTypeCastException(const ir::AstNode *node, const VReg src, checker::Type const *target) +{ + const RegScope rs(this); + const auto errorReg = AllocReg(); + + LoadAccumulatorString(node, util::UString(target->ToString(), Allocator()).View()); + Ra().Emit(node, Signatures::BUILTIN_RUNTIME_FAILED_TYPE_CAST_EXCEPTION, src, 1); + StoreAccumulator(node, errorReg); + EmitThrow(node, errorReg); + SetAccumulatorType(nullptr); +} + void ETSGen::LoadConstantObject(const ir::Expression *node, const checker::Type *type) { if (type->HasTypeFlag(checker::TypeFlag::BIGINT_LITERAL)) { @@ -880,6 +999,7 @@ bool ETSGen::TryLoadConstantExpression(const ir::Expression *node) if (!type->HasTypeFlag(checker::TypeFlag::CONSTANT)) { return false; } + // bug: this should be forbidden for most expression types! auto typeKind = checker::ETSChecker::TypeKind(type); @@ -970,9 +1090,6 @@ void ETSGen::ApplyBoxingConversion(const ir::AstNode *node) void ETSGen::ApplyUnboxingConversion(const ir::AstNode *node) { - if (Checker()->MayHaveNulllikeValue(GetAccumulatorType())) { // NOTE: vpukhov. should be a CTE - EmitNullishGuardian(node); - } EmitUnboxingConversion(node); node->SetBoxingUnboxingFlags(static_cast(node->GetBoxingUnboxingFlags() & ~(ir::BoxingUnboxingFlags::UNBOXING_FLAG))); @@ -1002,11 +1119,6 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe return; } - if (targetType->IsETSUnionType()) { - SetAccumulatorType(targetType); - return; - } - ApplyConversionCast(node, targetType); } @@ -1618,8 +1730,7 @@ void ETSGen::CastToInt(const ir::AstNode *node) SetAccumulatorType(Checker()->GlobalIntType()); } -void ETSGen::CastToArrayOrObject(const ir::AstNode *const node, const checker::Type *const targetType, - const bool unchecked) +void ETSGen::CastToReftype(const ir::AstNode *const node, const checker::Type *const targetType, const bool unchecked) { ASSERT(GetAccumulatorType()->HasTypeFlag(TYPE_FLAG_BYTECODE_REF)); @@ -1629,22 +1740,17 @@ void ETSGen::CastToArrayOrObject(const ir::AstNode *const node, const checker::T CastDynamicToObject(node, targetType); return; } - if (targetType->IsETSDynamicType()) { CastToDynamic(node, targetType->AsETSDynamicType()); return; } - if (!unchecked) { CheckedReferenceNarrowing(node, targetType); return; } - if (targetType->IsETSTypeParameter()) { - CheckedReferenceNarrowing(node, targetType->AsETSTypeParameter()->GetConstraintType()); - } else if (targetType->IsETSObjectType()) { - CheckedReferenceNarrowing(node, targetType->AsETSObjectType()->GetConstOriginalBaseType()); - } + ASSERT(!targetType->IsETSTypeParameter() && !targetType->IsETSNonNullishType()); + CheckedReferenceNarrowing(node, targetType); SetAccumulatorType(targetType); } @@ -1675,7 +1781,9 @@ void ETSGen::CastDynamicToObject(const ir::AstNode *node, const checker::Type *t return; } - if (targetType->IsETSArrayType() || targetType->IsETSObjectType() || targetType->IsETSTypeParameter()) { + // should be valid only for Object and [] types, other are workarounds + if (targetType->IsETSArrayType() || targetType->IsETSObjectType() || targetType->IsETSTypeParameter() || + targetType->IsETSUnionType()) { auto lang = GetAccumulatorType()->AsETSDynamicType()->Language(); auto methodName = compiler::Signatures::Dynamic::GetObjectBuiltin(lang); @@ -1683,14 +1791,14 @@ void ETSGen::CastDynamicToObject(const ir::AstNode *node, const checker::Type *t VReg dynObjReg = AllocReg(); StoreAccumulator(node, dynObjReg); + // try internal checkcast VReg typeReg = AllocReg(); - std::stringstream ss; - targetType->ToAssemblerTypeWithRank(ss); - Sa().Emit(node, util::UString(ss.str(), Allocator()).View()); + auto assemblerType = ToAssemblerType(targetType); + Sa().Emit(node, assemblerType); StoreAccumulator(node, typeReg); Ra().Emit(node, methodName, dynObjReg, typeReg); - Sa().Emit(node, util::UString(ss.str(), Allocator()).View()); // trick verifier + Sa().Emit(node, assemblerType); // trick verifier SetAccumulatorType(targetType); return; } @@ -1704,8 +1812,9 @@ void ETSGen::CastToString(const ir::AstNode *const node) if (sourceType->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { EmitBoxingConversion(node); } else { - ASSERT(sourceType->HasTypeFlag(checker::TypeFlag::ETS_OBJECT)); + ASSERT(sourceType->IsETSReferenceType()); } + // caller must ensure parameter is not null Ra().Emit(node, Signatures::BUILTIN_OBJECT_TO_STRING, dummyReg_, 0); SetAccumulatorType(Checker()->GetGlobalTypesHolder()->GlobalETSStringBuiltinType()); } @@ -1748,15 +1857,13 @@ void ETSGen::CastToDynamic(const ir::AstNode *node, const checker::ETSDynamicTyp break; } case checker::TypeFlag::ETS_OBJECT: - case checker::TypeFlag::ETS_TYPE_PARAMETER: { + case checker::TypeFlag::ETS_TYPE_PARAMETER: + case checker::TypeFlag::ETS_NONNULLISH: + case checker::TypeFlag::ETS_UNION: { // NOTE(vpukhov): refine dynamic type cast rules if (GetAccumulatorType()->IsETSStringType()) { methodName = compiler::Signatures::Dynamic::NewStringBuiltin(type->Language()); break; } - if (GetAccumulatorType()->IsLambdaObject()) { - methodName = Signatures::BUILTIN_JSRUNTIME_CREATE_LAMBDA_PROXY; - break; - } [[fallthrough]]; } case checker::TypeFlag::ETS_ARRAY: { @@ -1967,10 +2074,6 @@ void ETSGen::Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs) BinaryBitwiseArithmetic(node, lhs); break; } - case lexer::TokenType::KEYW_INSTANCEOF: { - EmitIsInstance(node, lhs); - break; - } default: { UNREACHABLE(); } @@ -2006,11 +2109,6 @@ void ETSGen::Condition(const ir::AstNode *node, lexer::TokenType op, VReg lhs, L BinaryRelationCondition(node, lhs, ifFalse); break; } - case lexer::TokenType::KEYW_INSTANCEOF: { - EmitIsInstance(node, lhs); - BranchIfFalse(node, ifFalse); - break; - } default: { UNREACHABLE(); } @@ -2019,104 +2117,57 @@ void ETSGen::Condition(const ir::AstNode *node, lexer::TokenType op, VReg lhs, L void ETSGen::BranchIfNullish([[maybe_unused]] const ir::AstNode *node, [[maybe_unused]] Label *ifNullish) { -#ifdef PANDA_WITH_ETS auto *const type = GetAccumulatorType(); - if (!Checker()->MayHaveNulllikeValue(type)) { - return; - } - if (type->IsETSNullLike()) { + if (type->DefinitelyNotETSNullish()) { + // no action + } else if (type->DefinitelyETSNullish()) { Sa().Emit(node, ifNullish); - return; - } - if (!Checker()->MayHaveUndefinedValue(type)) { + } else if (!type->PossiblyETSUndefined()) { Sa().Emit(node, ifNullish); - return; - } - - Sa().Emit(node, ifNullish); + } else { + RegScope rs(this); + auto tmpObj = AllocReg(); + auto notTaken = AllocLabel(); - auto tmpObj = AllocReg(); - auto notTaken = AllocLabel(); + if (type->PossiblyETSNull()) { + Sa().Emit(node, ifNullish); + } - Sa().Emit(node, tmpObj); - Sa().Emit(node); - Sa().Emit(node, notTaken); + Sa().Emit(node, tmpObj); + EmitIsUndefined(node); + Sa().Emit(node, notTaken); - Sa().Emit(node, tmpObj); - Sa().Emit(node, ifNullish); + Sa().Emit(node, tmpObj); + Sa().Emit(node, ifNullish); - SetLabel(node, notTaken); - Sa().Emit(node, tmpObj); -#else - UNREACHABLE(); -#endif // PANDA_WITH_ETS + SetLabel(node, notTaken); + Sa().Emit(node, tmpObj); + } } void ETSGen::BranchIfNotNullish([[maybe_unused]] const ir::AstNode *node, [[maybe_unused]] Label *ifNotNullish) { -#ifdef PANDA_WITH_ETS - auto *const type = GetAccumulatorType(); - - if (!Checker()->MayHaveNulllikeValue(type)) { - Sa().Emit(node, ifNotNullish); - return; - } - if (type->IsETSNullLike()) { - return; - } - if (!Checker()->MayHaveUndefinedValue(type)) { - Sa().Emit(node, ifNotNullish); - return; - } - - auto end = AllocLabel(); - auto tmpObj = AllocReg(); auto notTaken = AllocLabel(); - - Sa().Emit(node, end); - - Sa().Emit(node, tmpObj); - Sa().Emit(node); - Sa().Emit(node, notTaken); - - Sa().Emit(node, tmpObj); - Sa().Emit(node, ifNotNullish); - + BranchIfNullish(node, notTaken); + JumpTo(node, ifNotNullish); SetLabel(node, notTaken); - Sa().Emit(node, tmpObj); - SetLabel(node, end); -#else - UNREACHABLE(); -#endif // PANDA_WITH_ETS } -void ETSGen::ConvertToNonNullish(const ir::AstNode *node) +void ETSGen::AssumeNonNullish(const ir::AstNode *node, checker::Type const *targetType) { auto const *nullishType = GetAccumulatorType(); - auto const *targetType = Checker()->GetNonNullishType(nullishType); - if (Checker()->MayHaveUndefinedValue(nullishType) && targetType != Checker()->GlobalETSObjectType()) { - CheckedReferenceNarrowing(node, targetType); + if (nullishType->PossiblyETSUndefined() && + ToAssemblerType(targetType) != ToAssemblerType(Checker()->GlobalETSObjectType())) { + // clear 'undefined' union constituent + Sa().Emit(node, ToAssemblerType(targetType)); } SetAccumulatorType(targetType); } -void ETSGen::EmitNullishGuardian(const ir::AstNode *node) -{ - auto const *nullishType = GetAccumulatorType(); - ASSERT(Checker()->MayHaveNulllikeValue(nullishType)); - - compiler::Label *ifNotNullish = AllocLabel(); - BranchIfNotNullish(node, ifNotNullish); - EmitNullishException(node); - - SetLabel(node, ifNotNullish); - SetAccumulatorType(nullishType); - ConvertToNonNullish(node); -} - void ETSGen::EmitNullishException(const ir::AstNode *node) { + RegScope ra(this); VReg exception = StoreException(node); NewObject(node, exception, Signatures::BUILTIN_NULLPOINTER_EXCEPTION); CallThisStatic0(node, exception, Signatures::BUILTIN_NULLPOINTER_EXCEPTION_CTOR); @@ -2135,6 +2186,17 @@ void ETSGen::BinaryEqualityRefDynamic(const ir::AstNode *node, bool testEqual, V } } +static bool MayUseStringEquals(checker::Type const *type) +{ + if (!type->IsETSUnionType()) { + return type->IsETSStringType(); + } + auto const &ct = type->AsETSUnionType()->ConstituentTypes(); + return std::all_of(ct.begin(), ct.end(), + [](auto t) { return t->IsETSStringType() || t->DefinitelyETSNullish(); }) && + std::any_of(ct.begin(), ct.end(), [](auto t) { return t->IsETSStringType(); }); +} + void ETSGen::BinaryEqualityRef(const ir::AstNode *node, bool testEqual, VReg lhs, VReg rhs, Label *ifFalse) { Label *ifTrue = AllocLabel(); @@ -2143,29 +2205,24 @@ void ETSGen::BinaryEqualityRef(const ir::AstNode *node, bool testEqual, VReg lhs return; } - if (GetVRegType(lhs)->IsETSNullLike() || GetVRegType(rhs)->IsETSNullLike()) { - LoadAccumulator(node, GetVRegType(lhs)->IsETSNullLike() ? rhs : lhs); + if (GetVRegType(lhs)->DefinitelyETSNullish() || GetVRegType(rhs)->DefinitelyETSNullish()) { + LoadAccumulator(node, GetVRegType(lhs)->DefinitelyETSNullish() ? rhs : lhs); testEqual ? BranchIfNotNullish(node, ifFalse) : BranchIfNullish(node, ifFalse); } else { Label *ifLhsNullish = AllocLabel(); - auto const rhsNullishType = GetVRegType(rhs); - LoadAccumulator(node, lhs); BranchIfNullish(node, ifLhsNullish); - ConvertToNonNullish(node); - StoreAccumulator(node, lhs); LoadAccumulator(node, rhs); BranchIfNullish(node, testEqual ? ifFalse : ifTrue); - ConvertToNonNullish(node); - StoreAccumulator(node, rhs); LoadAccumulator(node, lhs); - if (GetVRegType(lhs)->IsETSBigIntType()) { + if (GetVRegType(lhs)->IsETSBigIntType()) { // remove CallThisStatic1(node, lhs, Signatures::BUILTIN_BIGINT_EQUALS, rhs); - } else if (GetVRegType(lhs)->IsETSStringType()) { + } else if (MayUseStringEquals(GetVRegType(lhs))) { // workaround check + AssumeNonNullish(node, Checker()->GlobalBuiltinETSStringType()); CallThisStatic1(node, lhs, Signatures::BUILTIN_STRING_EQUALS, rhs); } else { CallThisVirtual1(node, lhs, Signatures::BUILTIN_OBJECT_EQUALS, rhs); @@ -2175,7 +2232,6 @@ void ETSGen::BinaryEqualityRef(const ir::AstNode *node, bool testEqual, VReg lhs SetLabel(node, ifLhsNullish); LoadAccumulator(node, rhs); - SetAccumulatorType(rhsNullishType); testEqual ? BranchIfNotNullish(node, ifFalse) : BranchIfNullish(node, ifFalse); // fallthrough } @@ -2387,13 +2443,8 @@ void ETSGen::StringBuilderAppend(const ir::AstNode *node, VReg builder) signature = Signatures::BUILTIN_STRING_BUILDER_APPEND_BUILTIN_STRING; } - const checker::Type *accumulatorType = GetAccumulatorType(); - bool isNullOrUndefined = accumulatorType->ContainsNull() || accumulatorType->ContainsUndefined(); - bool isETSRefType = accumulatorType->IsETSObjectType() || accumulatorType->IsETSTypeParameter() || - accumulatorType->IsETSArrayType(); - bool isStringType = accumulatorType->IsETSStringType(); - if (isETSRefType && (!isStringType || isNullOrUndefined)) { - if (Checker()->MayHaveNullValue(GetAccumulatorType())) { + if (GetAccumulatorType()->IsETSReferenceType() && !GetAccumulatorType()->IsETSStringType()) { + if (GetAccumulatorType()->PossiblyETSNull()) { Label *ifnull = AllocLabel(); Label *end = AllocLabel(); BranchIfNull(node, ifnull); @@ -2734,7 +2785,7 @@ bool ETSGen::ExtendWithFinalizer(ir::AstNode *node, const ir::AstNode *originalN util::StringView ETSGen::ToAssemblerType(const es2panda::checker::Type *type) const { - ASSERT(type->HasTypeFlag(TYPE_FLAG_BYTECODE_REF) && !type->IsETSNullLike()); + ASSERT(type->IsETSReferenceType()); std::stringstream ss; type->ToAssemblerTypeWithRank(ss); diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index b1c5907351785069c931ff85b42de93fc4fc8891..fceb698a9b72e1df42f619fc4a44cf72fe50f770 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -91,7 +91,10 @@ public: void LoadBuiltinVoid(const ir::AstNode *node); void ReturnAcc(const ir::AstNode *node); - void EmitIsInstance(const ir::AstNode *node, VReg objReg); + void BranchIfIsInstance(const ir::AstNode *node, VReg srcReg, const checker::Type *target, Label *ifTrue); + void IsInstance(const ir::AstNode *node, VReg srcReg, checker::Type const *target); + void IsInstanceDynamic(const ir::AstNode *node, VReg srcReg, VReg tgtReg); + void EmitFailedTypeCastException(const ir::AstNode *node, VReg src, checker::Type const *target); void Binary(const ir::AstNode *node, lexer::TokenType op, VReg lhs); void Unary(const ir::AstNode *node, lexer::TokenType op); @@ -104,8 +107,7 @@ public: template void ResolveConditionalResultFloat(const ir::AstNode *node, Label *realEndLabel) { - auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() - : GetAccumulatorType(); + auto type = GetAccumulatorType(); VReg tmpReg = AllocReg(); StoreAccumulator(node, tmpReg); if (type->IsFloatType()) { @@ -131,9 +133,7 @@ public: template void ResolveConditionalResultNumeric(const ir::AstNode *node, [[maybe_unused]] Label *ifFalse, Label **end) { - auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() - : GetAccumulatorType(); - + auto type = GetAccumulatorType(); auto realEndLabel = [end, ifFalse, this](bool useFalseLabel) { if (useFalseLabel) { return ifFalse; @@ -159,72 +159,53 @@ public: } template - void ResolveConditionalResultObject(const ir::AstNode *node) + void ResolveConditionalResultReference(const ir::AstNode *node) { - auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() - : GetAccumulatorType(); - if (type->IsETSStringType()) { + auto const testString = [this, node]() { LoadStringLength(node); if constexpr (BEFORE_LOGICAL_NOT) { Label *zeroLenth = AllocLabel(); BranchIfFalse(node, zeroLenth); ToBinaryResult(node, zeroLenth); } - } else if (node->IsExpression() && node->AsExpression()->IsIdentifier() && - node->AsExpression()->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::VAR)) { - Label *isString = AllocLabel(); - Label *end = AllocLabel(); - compiler::VReg objReg = AllocReg(); - StoreAccumulator(node, objReg); - - Sa().Emit(node, Checker()->GlobalBuiltinETSStringType()->AsETSStringType()->AssemblerName()); - BranchIfTrue(node, isString); - Sa().Emit(node, 1); - Branch(node, end); - SetLabel(node, isString); - LoadAccumulator(node, objReg); - CastToString(node); - LoadStringLength(node); - if constexpr (BEFORE_LOGICAL_NOT) { - Label *zeroLenth = AllocLabel(); - BranchIfFalse(node, zeroLenth); - ToBinaryResult(node, zeroLenth); - } - SetLabel(node, end); - } else { + }; + + auto type = GetAccumulatorType(); + if (!type->PossiblyETSString()) { Sa().Emit(node, 1); + return; } - } - - template - void ResolveConditionalResultExpression(const ir::AstNode *node, [[maybe_unused]] Label *ifFalse) - { - auto exprNode = node->AsExpression(); - if (Checker()->IsNullLikeOrVoidExpression(exprNode)) { - if constexpr (USE_FALSE_LABEL) { - Branch(node, ifFalse); - } else { - Sa().Emit(node, 0); - } + if (type->IsETSStringType()) { // should also be valid for string|null|undefined + testString(); return; } + + Label *isString = AllocLabel(); + Label *end = AllocLabel(); + compiler::VReg objReg = AllocReg(); + StoreAccumulator(node, objReg); + + Sa().Emit(node, Checker()->GlobalBuiltinETSStringType()->AssemblerName()); + BranchIfTrue(node, isString); + Sa().Emit(node, 1); + Branch(node, end); + SetLabel(node, isString); + LoadAccumulator(node, objReg); + InternalCheckCast(node, Checker()->GlobalBuiltinETSStringType()); // help verifier + testString(); + SetLabel(node, end); } template void ResolveConditionalResult(const ir::AstNode *node, [[maybe_unused]] Label *ifFalse) { - auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() - : GetAccumulatorType(); + auto type = GetAccumulatorType(); if (type->IsETSBooleanType()) { return; } - - if (node->IsExpression()) { - ResolveConditionalResultExpression(node, ifFalse); - } Label *ifNullish {nullptr}; Label *end {nullptr}; - if (Checker()->MayHaveNulllikeValue(type)) { + if (type->PossiblyETSNullish()) { if constexpr (USE_FALSE_LABEL) { BranchIfNullish(node, ifFalse); } else { @@ -233,12 +214,10 @@ public: BranchIfNullish(node, ifNullish); } } - if (type->IsETSArrayType()) { - compiler::VReg objReg = AllocReg(); - StoreAccumulator(node, objReg); - LoadArrayLength(node, objReg); - } else if (type->IsETSObjectType()) { - ResolveConditionalResultObject(node); + if (type->DefinitelyETSNullish()) { + // skip + } else if (type->IsETSReferenceType()) { + ResolveConditionalResultReference(node); } else { ResolveConditionalResultNumeric(node, ifFalse, &end); } @@ -286,7 +265,7 @@ public: void BranchIfNullish(const ir::AstNode *node, Label *ifNullish); void BranchIfNotNullish(const ir::AstNode *node, Label *ifNotNullish); - void ConvertToNonNullish(const ir::AstNode *node); + void AssumeNonNullish(const ir::AstNode *node, checker::Type const *targetType); void JumpTo(const ir::AstNode *node, Label *labelTo) { @@ -299,44 +278,6 @@ public: } void EmitNullishException(const ir::AstNode *node); - void EmitNullishGuardian(const ir::AstNode *node); - - template - void EmitMaybeOptional(const ir::Expression *node, F const &compile, bool isOptional) - { - auto *const type = GetAccumulatorType(); - - if (!Checker()->MayHaveNulllikeValue(type)) { - compile(); - } else if (type->IsETSNullLike()) { - if (isOptional) { - LoadAccumulatorUndefined(node); - } else { // NOTE: vpukhov. should be a CTE - EmitNullishException(node); - LoadAccumulatorUndefined(node); - } - SetAccumulatorType(node->TsType()); - } else if (!isOptional) { // NOTE: vpukhov. should be a CTE - EmitNullishGuardian(node); - compile(); - } else { - compiler::Label *ifNotNullish = AllocLabel(); - compiler::Label *endLabel = AllocLabel(); - - BranchIfNotNullish(node, ifNotNullish); - LoadAccumulatorUndefined(node); - Branch(node, endLabel); - - SetLabel(node, ifNotNullish); - SetAccumulatorType(type); - ConvertToNonNullish(node); - compile(); - ApplyConversion(node, node->TsType()); - SetLabel(node, endLabel); - SetAccumulatorType(node->TsType()); - } - } - void ThrowException(const ir::Expression *expr); bool ExtendWithFinalizer(ir::AstNode *node, const ir::AstNode *originalNode, Label *prevFinnaly = nullptr); @@ -544,9 +485,10 @@ public: void CastToString(const ir::AstNode *node); void CastToDynamic(const ir::AstNode *node, const checker::ETSDynamicType *type); void CastDynamicTo(const ir::AstNode *node, enum checker::TypeFlag typeFlag); - void CastToArrayOrObject(const ir::AstNode *node, const checker::Type *targetType, bool unchecked); + void CastToReftype(const ir::AstNode *node, const checker::Type *targetType, bool unchecked); void CastDynamicToObject(const ir::AstNode *node, const checker::Type *targetType); + void InternalIsInstance(const ir::AstNode *node, const checker::Type *target); void InternalCheckCast(const ir::AstNode *node, const checker::Type *target); void CheckedReferenceNarrowing(const ir::AstNode *node, const checker::Type *target); void GuardUncheckedType(const ir::AstNode *node, const checker::Type *unchecked, const checker::Type *target); @@ -559,7 +501,7 @@ public: void CallBigIntBinaryOperator(const ir::Expression *node, VReg lhs, VReg rhs, util::StringView signature); void CallBigIntBinaryComparison(const ir::Expression *node, VReg lhs, VReg rhs, util::StringView signature); void BuildTemplateString(const ir::TemplateLiteral *node); - void InitObject(const ir::AstNode *node, checker::Signature *signature, + void InitObject(const ir::AstNode *node, checker::Signature const *signature, const ArenaVector &arguments) { CallImpl(node, signature, arguments); @@ -665,7 +607,6 @@ public: private: const VReg dummyReg_ = VReg::RegStart(); - void EmitIsInstanceNonNullish(const ir::AstNode *node, VReg objReg, checker::ETSObjectType const *clsType); void EmitUnboxedCall(const ir::AstNode *node, std::string_view signatureFlag, const checker::Type *targetType, const checker::Type *boxedType); @@ -679,6 +620,18 @@ private: void UnaryDollarDollar(const ir::AstNode *node); util::StringView ToAssemblerType(const es2panda::checker::Type *type) const; + void TestIsInstanceConstituent(const ir::AstNode *node, Label *ifTrue, Label *ifFalse, checker::Type const *target, + bool acceptUndefined); + void CheckedReferenceNarrowingObject(const ir::AstNode *node, const checker::Type *target); + + void EmitIsUndefined([[maybe_unused]] const ir::AstNode *node) + { +#ifdef PANDA_WITH_ETS + Sa().Emit(node); +#else + UNREACHABLE(); +#endif // PANDA_WITH_ETS + } template void StoreValueIntoArray(const ir::AstNode *const node, const VReg arr, const VReg index) @@ -765,18 +718,18 @@ private: template void BinaryEqualityCondition(const ir::AstNode *node, VReg lhs, Label *ifFalse) { + if (targetType_->IsETSReferenceType()) { + RegScope rs(this); + VReg arg0 = AllocReg(); + StoreAccumulator(node, arg0); + BinaryEqualityRef(node, !std::is_same_v, lhs, arg0, ifFalse); + SetAccumulatorType(Checker()->GlobalETSBooleanType()); + return; + } + auto typeKind = checker::ETSChecker::TypeKind(targetType_); switch (typeKind) { - case checker::TypeFlag::ETS_OBJECT: - case checker::TypeFlag::ETS_TYPE_PARAMETER: - case checker::TypeFlag::ETS_DYNAMIC_TYPE: { - RegScope rs(this); - VReg arg0 = AllocReg(); - StoreAccumulator(node, arg0); - BinaryEqualityRef(node, !std::is_same_v, lhs, arg0, ifFalse); - return; - } case checker::TypeFlag::DOUBLE: { BinaryFloatingPointComparison(node, lhs, ifFalse); break; @@ -937,7 +890,7 @@ private: arguments[idx]->Compile(this); \ VReg arg##idx = AllocReg(); \ ApplyConversion(arguments[idx], nullptr); \ - ApplyConversionAndStoreAccumulator(arguments[idx], arg##idx, paramType##idx); + ApplyConversionAndStoreAccumulator(arguments[idx], arg##idx, paramType##idx) template void CallThisImpl(const ir::AstNode *const node, const VReg ctor, checker::Signature *const signature, @@ -970,11 +923,8 @@ private: break; } default: { - for (const auto *arg : arguments) { - auto ttctx = TargetTypeContext(this, arg->TsType()); - VReg argReg = AllocReg(); - arg->Compile(this); - StoreAccumulator(node, argReg); + for (size_t idx = 0; idx < arguments.size(); idx++) { + COMPILE_ARG(idx); } Rra().Emit(node, ctor, arguments.size() + 1, name, ctor); @@ -984,7 +934,7 @@ private: } template - bool ResolveStringFromNullishBuiltin(const ir::AstNode *node, checker::Signature *signature, + bool ResolveStringFromNullishBuiltin(const ir::AstNode *node, checker::Signature const *signature, const ArenaVector &arguments) { if (signature->InternalName() != Signatures::BUILTIN_STRING_FROM_NULLISH_CTOR) { @@ -1004,38 +954,32 @@ private: Label *isNull = AllocLabel(); Label *end = AllocLabel(); -#ifdef PANDA_WITH_ETS Label *isUndefined = AllocLabel(); -#endif COMPILE_ARG(0); LoadAccumulator(node, arg0); - if (argExpr->TsType()->IsNullish()) { + if (argExpr->TsType()->PossiblyETSNullish()) { BranchIfNull(node, isNull); -#ifdef PANDA_WITH_ETS - Sa().Emit(node); + EmitIsUndefined(node); BranchIfTrue(node, isUndefined); -#endif } LoadAccumulator(node, arg0); CastToString(node); StoreAccumulator(node, arg0); Ra().Emit(node, Signatures::BUILTIN_STRING_FROM_STRING_CTOR, arg0, dummyReg_); JumpTo(node, end); - if (argExpr->TsType()->IsNullish()) { + if (argExpr->TsType()->PossiblyETSNullish()) { SetLabel(node, isNull); LoadAccumulatorString(node, "null"); -#ifdef PANDA_WITH_ETS JumpTo(node, end); SetLabel(node, isUndefined); LoadAccumulatorString(node, "undefined"); -#endif } SetLabel(node, end); return true; } template - void CallImpl(const ir::AstNode *node, checker::Signature *signature, + void CallImpl(const ir::AstNode *node, checker::Signature const *signature, const ArenaVector &arguments) { RegScope rs(this); @@ -1078,11 +1022,8 @@ private: default: { VReg argStart = NextReg(); - for (const auto *arg : arguments) { - auto ttctx = TargetTypeContext(this, arg->TsType()); - VReg argReg = AllocReg(); - arg->Compile(this); - StoreAccumulator(node, argReg); + for (size_t idx = 0; idx < arguments.size(); idx++) { + COMPILE_ARG(idx); } Rra().Emit(node, argStart, arguments.size(), name, argStart); @@ -1100,7 +1041,7 @@ private: auto ttctx##idx = TargetTypeContext(this, paramType##idx); \ VReg arg##idx = AllocReg(); \ arguments[idx]->Compile(this); \ - ApplyConversionAndStoreAccumulator(arguments[idx], arg##idx, paramType##idx); + ApplyConversionAndStoreAccumulator(arguments[idx], arg##idx, paramType##idx) template void CallDynamicImpl(const ir::AstNode *node, VReg &obj, VReg ¶m2, checker::Signature *signature, diff --git a/ets2panda/compiler/core/ETSemitter.cpp b/ets2panda/compiler/core/ETSemitter.cpp index 116c3a74327331b1925d5da902f0d1b4d830fbbe..83634dd03370eaf0c3d60888a34a09c6ab5f9b0b 100644 --- a/ets2panda/compiler/core/ETSemitter.cpp +++ b/ets2panda/compiler/core/ETSemitter.cpp @@ -88,6 +88,23 @@ static uint32_t TranslateModifierFlags(ir::ModifierFlags modifierFlags) return accessFlags; } +static pandasm::Type PandasmTypeWithRank(checker::Type const *type) +{ + if (type->IsETSTypeParameter()) { + return PandasmTypeWithRank(type->AsETSTypeParameter()->GetConstraintType()); + } + if (type->IsETSNonNullishType()) { + return PandasmTypeWithRank(type->AsETSNonNullishType()->GetUnderlying()); + } + if (type->IsETSUnionType()) { + return PandasmTypeWithRank(type->AsETSUnionType()->GetAssemblerLUB()); + } + + std::stringstream ss; + type->ToAssemblerType(ss); + return pandasm::Type(ss.str(), type->Rank()); +} + static pandasm::Function GenScriptFunction(CompilerContext const *context, const ir::ScriptFunction *scriptFunc) { auto *funcScope = scriptFunc->Scope(); @@ -98,21 +115,14 @@ static pandasm::Function GenScriptFunction(CompilerContext const *context, const func.params.reserve(paramScope->Params().size()); for (const auto *var : paramScope->Params()) { - std::stringstream ss; - context->Checker()->AsETSChecker()->MaybeBoxedType(var)->ToAssemblerType(ss); - func.params.emplace_back(pandasm::Type(ss.str(), var->TsType()->Rank()), EXTENSION); + func.params.emplace_back(PandasmTypeWithRank(context->Checker()->AsETSChecker()->MaybeBoxedType(var)), + EXTENSION); } - std::stringstream ss; - if (scriptFunc->IsConstructor() || scriptFunc->IsStaticBlock()) { func.returnType = pandasm::Type(Signatures::PRIMITIVE_VOID, 0); } else { - const auto *returnType = scriptFunc->Signature()->ReturnType(); - - returnType->ToAssemblerType(ss); - ASSERT(!ss.str().empty()); - func.returnType = pandasm::Type(ss.str(), returnType->Rank()); + func.returnType = PandasmTypeWithRank(scriptFunc->Signature()->ReturnType()); } if (!scriptFunc->IsStaticBlock()) { @@ -170,16 +180,9 @@ static pandasm::Function GenExternalFunction(checker::Signature *signature, bool auto func = pandasm::Function(signature->InternalName().Mutf8(), EXTENSION); for (auto param : signature->Params()) { - auto *paramType = param->TsType(); - - std::stringstream ss; - paramType->ToAssemblerType(ss); - func.params.emplace_back(pandasm::Type(ss.str(), paramType->Rank()), EXTENSION); + func.params.emplace_back(PandasmTypeWithRank(param->TsType()), EXTENSION); } - - std::stringstream ss; - signature->ReturnType()->ToAssemblerType(ss); - func.returnType = pandasm::Type(ss.str(), signature->ReturnType()->Rank()); + func.returnType = PandasmTypeWithRank(signature->ReturnType()); if (isCtor) { func.metadata->SetAttribute(Signatures::CONSTRUCTOR); @@ -343,11 +346,9 @@ void ETSEmitter::GenField(const checker::Type *tsType, const util::StringView &n uint32_t accesFlags, pandasm::Record &record, bool external) { auto field = pandasm::Field(Program()->lang); - std::stringstream ss; - tsType->ToAssemblerType(ss); field.name = name.Mutf8(); - field.type = pandasm::Type(ss.str(), tsType->Rank()); + field.type = PandasmTypeWithRank(tsType); field.metadata->SetAccessFlags(accesFlags); @@ -388,11 +389,7 @@ void ETSEmitter::GenGlobalArrayRecord(checker::ETSArrayType *arrayType, checker: arrayRecord.metadata->SetAttribute(Signatures::EXTERNAL); Program()->recordTable.emplace(arrayRecord.name, std::move(arrayRecord)); - - std::stringstream ss2; - arrayType->ElementType()->ToAssemblerType(ss2); - panda::pandasm::Type atypePa(ss2.str(), arrayType->Rank()); - Program()->arrayTypes.emplace(std::move(atypePa)); + Program()->arrayTypes.emplace(PandasmTypeWithRank(arrayType)); } void ETSEmitter::GenInterfaceRecord(const ir::TSInterfaceDeclaration *interfaceDecl, bool external) diff --git a/ets2panda/compiler/core/ETSfunction.cpp b/ets2panda/compiler/core/ETSfunction.cpp index 75739a159d7c1b59ae125e4bac3c15f531058c34..8ad11cb7e09ec304e3138e7dbdcdc0f796613afc 100644 --- a/ets2panda/compiler/core/ETSfunction.cpp +++ b/ets2panda/compiler/core/ETSfunction.cpp @@ -146,13 +146,11 @@ void ETSFunction::CompileSourceBlock(ETSGen *etsg, const ir::BlockStatement *blo void ETSFunction::CompileFunction(ETSGen *etsg) { - const auto *decl = etsg->RootNode()->AsScriptFunction(); - - if (decl->IsDeclare()) { - return; + if (const auto *decl = etsg->RootNode()->AsScriptFunction(); !decl->IsDeclare()) { + if (auto *const body = decl->Body(); body != nullptr && body->IsBlockStatement()) { + CompileSourceBlock(etsg, body->AsBlockStatement()); + } } - - CompileSourceBlock(etsg, etsg->RootNode()->AsScriptFunction()->Body()->AsBlockStatement()); } void ETSFunction::Compile(ETSGen *etsg) diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index e7099b97f770c7130fc28909701a701cf02e26d2..b9670d7dc0e57576f809343366daeb5933ec6a9b 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -545,6 +545,18 @@ void JSCompiler::Compile([[maybe_unused]] const ir::ETSTypeReferencePart *expr) UNREACHABLE(); } +void JSCompiler::Compile(const ir::ETSNullType *node) const +{ + (void)node; + UNREACHABLE(); +} + +void JSCompiler::Compile(const ir::ETSUndefinedType *node) const +{ + (void)node; + UNREACHABLE(); +} + void JSCompiler::Compile(const ir::ETSUnionType *node) const { (void)node; diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index a5bc7da17f8c88a8590f7f614c19c2cde78c9772..dfc46cabf36654d55d80455cc9d1a91f999718ef 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -110,11 +110,15 @@ static void Verify(const parser::Program &program, const CompilerContext &contex using NamedProgram = std::tuple; ArenaVector toCheck {program.Allocator()->Adapter()}; toCheck.push_back(std::make_tuple(program.SourceFilePath(), &program)); + + // collect list of checks for (const auto &externalSource : program.ExternalSources()) { for (const auto *external : externalSource.second) { toCheck.push_back(std::make_tuple(external->SourceFilePath(), external)); } } + + // check for (const auto &it : toCheck) { const auto &sourceName = std::get<0>(it); const auto &linkedProgram = std::get<1>(it); @@ -123,6 +127,20 @@ static void Verify(const parser::Program &program, const CompilerContext &contex verificationCtx.IntroduceNewInvariants(phase->Name()); } } + +static void Report(const CompilerContext &context, ASTVerifierContext &verificationCtx) +{ + if (!context.Options()->verifierWarnings.empty()) { + if (auto errors = verificationCtx.DumpWarningsJSON(); errors != "[]") { + LOG(ERROR, ES2PANDA) << errors; + } + } + if (!context.Options()->verifierErrors.empty()) { + if (auto errors = verificationCtx.DumpAssertsJSON(); errors != "[]") { + ASSERT_PRINT(false, errors); + } + } +} #endif using EmitCb = std::function; @@ -169,21 +187,14 @@ static pandasm::Program *CreateCompiler(const CompilationUnit &unit, const Phase return nullptr; } #ifndef NDEBUG - Verify(program, context, phase, verificationCtx); + if (unit.ext == ScriptExtension::ETS) { + Verify(program, context, phase, verificationCtx); + } #endif } #ifndef NDEBUG - if (!context.Options()->verifierWarnings.empty()) { - if (auto errors = verificationCtx.DumpWarningsJSON(); errors != "[]") { - LOG(ERROR, ES2PANDA) << errors; - } - } - if (!context.Options()->verifierErrors.empty()) { - if (auto errors = verificationCtx.DumpAssertsJSON(); errors != "[]") { - ASSERT_PRINT(false, errors); - } - } + Report(context, verificationCtx); #endif emitter.GenAnnotation(); diff --git a/ets2panda/compiler/lowering/ets/expandBrackets.cpp b/ets2panda/compiler/lowering/ets/expandBrackets.cpp index d8936fe26a9f60761cdbd080b6cac0bcf7a2114d..d8640ce6730c9a76ae32072e6de0d3ce14442a95 100644 --- a/ets2panda/compiler/lowering/ets/expandBrackets.cpp +++ b/ets2panda/compiler/lowering/ets/expandBrackets.cpp @@ -18,57 +18,164 @@ #include "checker/ETSchecker.h" #include "compiler/lowering/util.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" -#include "ir/statements/blockStatement.h" -#include "ir/expressions/memberExpression.h" #include "parser/ETSparser.h" #include "varbinder/ETSBinder.h" +#include "varbinder/scope.h" namespace panda::es2panda::compiler { -bool ExpandBracketsPhase::Perform(public_lib::Context *ctx, parser::Program *program) +// NOLINTBEGIN(modernize-avoid-c-arrays) +static constexpr char const FORMAT_NEW_MULTI_DIM_ARRAY_EXPRESSION[] = + "let @@I1: @@T2 = (@@E3);" + "if (!isSafeInteger(@@I4)) {" + " throw new TypeError(\"Fractional part of index expression should be zero.\");" + "};"; +static constexpr char const FORMAT_NEW_ARRAY_EXPRESSION[] = + "let @@I1: @@T2 = (@@E3);" + "if (!isSafeInteger(@@I4)) {" + " throw new TypeError(\"Fractional part of index expression should be zero.\");" + "};" + "(@@E5);"; +static constexpr char const CAST_NEW_DIMENSION_EXPRESSION[] = "@@I1 as int"; +static constexpr char const CAST_OLD_DIMENSION_EXPRESSION[] = "(@@E1) as int"; +// NOLINTEND(modernize-avoid-c-arrays) + +ir::Expression *ExpandBracketsPhase::ProcessNewArrayInstanceExpression( + parser::ETSParser *parser, checker::ETSChecker *checker, + ir::ETSNewArrayInstanceExpression *newInstanceExpression) const { - auto *const checker = ctx->checker->AsETSChecker(); - auto *const allocator = checker->Allocator(); - auto *const parser = ctx->parser->AsETSParser(); + auto *dimension = newInstanceExpression->Dimension(); + auto *dimType = dimension->TsType(); + if (auto *unboxed = checker->ETSBuiltinTypeAsPrimitiveType(dimType); unboxed != nullptr) { + dimType = unboxed; + } + if (!dimType->HasTypeFlag(checker::TypeFlag::ETS_FLOATING_POINT)) { + return newInstanceExpression; + } - program->Ast()->TransformChildrenRecursively([ctx, parser, checker, allocator](ir::AstNode *ast) -> ir::AstNode * { - if (!ast->IsETSNewArrayInstanceExpression()) { - return ast; - } - auto *newExpression = ast->AsETSNewArrayInstanceExpression(); - auto *dimension = newExpression->Dimension(); + auto *scope = NearestScope(newInstanceExpression); + if (scope == nullptr) { + scope = checker->VarBinder()->VarScope() != nullptr ? checker->VarBinder()->VarScope() + : checker->VarBinder()->TopScope(); + } + auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + + auto *ident = Gensym(checker->Allocator()); + auto *exprType = checker->AllocNode(dimType); + auto *const newInstanceParent = newInstanceExpression->Parent(); + + auto *blockExpression = parser->CreateFormattedExpression( + FORMAT_NEW_ARRAY_EXPRESSION, parser::DEFAULT_SOURCE_FILE, ident, exprType, dimension, + ident->Clone(checker->Allocator(), nullptr), newInstanceExpression); + blockExpression->SetParent(newInstanceParent); + + auto *castedDimension = parser->CreateFormattedExpression( + CAST_NEW_DIMENSION_EXPRESSION, parser::DEFAULT_SOURCE_FILE, ident->Clone(checker->Allocator(), nullptr)); + newInstanceExpression->SetDimension(castedDimension); + + newInstanceExpression->SetTsType(nullptr); + InitScopesPhaseETS::RunExternalNode(blockExpression, checker->VarBinder()); + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(blockExpression, scope); + blockExpression->Check(checker); + + return blockExpression; +} + +ir::Expression *ExpandBracketsPhase::ProcessNewMultiDimArrayInstanceExpression( + parser::ETSParser *parser, checker::ETSChecker *checker, + ir::ETSNewMultiDimArrayInstanceExpression *newInstanceExpression) const +{ + ir::BlockExpression *returnExpression = nullptr; + + auto *scope = NearestScope(newInstanceExpression); + if (scope == nullptr) { + scope = checker->VarBinder()->VarScope() != nullptr ? checker->VarBinder()->VarScope() + : checker->VarBinder()->TopScope(); + } + auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + + for (std::size_t i = 0U; i < newInstanceExpression->Dimensions().size(); ++i) { + auto *dimension = newInstanceExpression->Dimensions()[i]; auto *dimType = dimension->TsType(); if (auto *unboxed = checker->ETSBuiltinTypeAsPrimitiveType(dimType); unboxed != nullptr) { dimType = unboxed; } if (!dimType->HasTypeFlag(checker::TypeFlag::ETS_FLOATING_POINT)) { - return ast; + continue; + } + + if (dimension->IsNumberLiteral()) { + auto *castedDimension = parser->CreateFormattedExpression(CAST_OLD_DIMENSION_EXPRESSION, + parser::DEFAULT_SOURCE_FILE, dimension); + castedDimension->SetParent(newInstanceExpression); + newInstanceExpression->Dimensions()[i] = castedDimension; + } else { + auto *ident = Gensym(checker->Allocator()); + auto *exprType = checker->AllocNode(dimType); + + auto *blockExpression = + parser + ->CreateFormattedExpression(FORMAT_NEW_MULTI_DIM_ARRAY_EXPRESSION, parser::DEFAULT_SOURCE_FILE, + ident, exprType, dimension, ident->Clone(checker->Allocator(), nullptr)) + ->AsBlockExpression(); + + if (returnExpression == nullptr) { + returnExpression = blockExpression; + } else { + returnExpression->AddStatements(blockExpression->Statements()); + } + + auto *castedDimension = + parser->CreateFormattedExpression(CAST_NEW_DIMENSION_EXPRESSION, parser::DEFAULT_SOURCE_FILE, + ident->Clone(checker->Allocator(), nullptr)); + castedDimension->SetParent(newInstanceExpression); + newInstanceExpression->Dimensions()[i] = castedDimension; } + } + + if (returnExpression != nullptr) { + return CreateNewMultiDimArrayInstanceExpression(checker, newInstanceExpression, returnExpression, scope); + } + + return newInstanceExpression; +} + +// NOTE: Just to reduce the size of 'ProcessNewMultiDimArrayInstanceExpression' method +ir::Expression *ExpandBracketsPhase::CreateNewMultiDimArrayInstanceExpression( + checker::ETSChecker *checker, ir::ETSNewMultiDimArrayInstanceExpression *newInstanceExpression, + ir::BlockExpression *blockExpression, varbinder::Scope *scope) const +{ + blockExpression->SetParent(newInstanceExpression->Parent()); + newInstanceExpression->SetTsType(nullptr); + blockExpression->AddStatement(checker->AllocNode(newInstanceExpression)); + + InitScopesPhaseETS::RunExternalNode(blockExpression, checker->VarBinder()); + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(blockExpression, scope); + blockExpression->Check(checker); - auto *castedDimension = - parser->CreateFormattedExpression("@@E1 as int", parser::DEFAULT_SOURCE_FILE, dimension); - castedDimension->Check(checker); - castedDimension->SetParent(dimension->Parent()); - newExpression->SetDimension(castedDimension); - - auto *const scope = NearestScope(newExpression); - auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); - auto *ident = Gensym(allocator); - auto *exprType = checker->AllocNode(dimType); - auto *sequenceExpr = parser->CreateFormattedExpression( - "let @@I1 = (@@E2) as @@T3;" - "if (!isSafeInteger(@@I4)) {" - " throw new TypeError(\"Index fractional part should not be different from 0.0\");" - "};" - "(@@E5);", - parser::DEFAULT_SOURCE_FILE, ident, dimension, exprType, ident->Clone(allocator), newExpression); - sequenceExpr->SetParent(newExpression->Parent()); - InitScopesPhaseETS::RunExternalNode(sequenceExpr, ctx->compilerContext->VarBinder()); - checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(sequenceExpr, scope); - sequenceExpr->Check(checker); - - return sequenceExpr; + return blockExpression; +} + +bool ExpandBracketsPhase::Perform(public_lib::Context *ctx, parser::Program *program) +{ + auto *const parser = ctx->parser->AsETSParser(); + ASSERT(parser != nullptr); + auto *const checker = ctx->checker->AsETSChecker(); + ASSERT(checker != nullptr); + + program->Ast()->TransformChildrenRecursively([this, parser, checker](ir::AstNode *const ast) -> ir::AstNode * { + if (ast->IsETSNewArrayInstanceExpression()) { + return ProcessNewArrayInstanceExpression(parser, checker, ast->AsETSNewArrayInstanceExpression()); + } + + if (ast->IsETSNewMultiDimArrayInstanceExpression()) { + return ProcessNewMultiDimArrayInstanceExpression(parser, checker, + ast->AsETSNewMultiDimArrayInstanceExpression()); + } + + return ast; }); + return true; } diff --git a/ets2panda/compiler/lowering/ets/expandBrackets.h b/ets2panda/compiler/lowering/ets/expandBrackets.h index 406d7f28327f0bbcf55d844ae9cf4da4c3d496ae..6b47d2eb6f938f64b8d3cd6cf4b1f05fea076685 100644 --- a/ets2panda/compiler/lowering/ets/expandBrackets.h +++ b/ets2panda/compiler/lowering/ets/expandBrackets.h @@ -28,8 +28,19 @@ public: } bool Perform(public_lib::Context *ctx, parser::Program *program) override; -}; +private: + ir::Expression *ProcessNewArrayInstanceExpression(parser::ETSParser *parser, checker::ETSChecker *checker, + ir::ETSNewArrayInstanceExpression *newInstanceExpression) const; + + ir::Expression *ProcessNewMultiDimArrayInstanceExpression( + parser::ETSParser *parser, checker::ETSChecker *checker, + ir::ETSNewMultiDimArrayInstanceExpression *newInstanceExpression) const; + + ir::Expression *CreateNewMultiDimArrayInstanceExpression( + checker::ETSChecker *checker, ir::ETSNewMultiDimArrayInstanceExpression *newInstanceExpression, + ir::BlockExpression *blockExpression, varbinder::Scope *scope) const; +}; } // namespace panda::es2panda::compiler #endif diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index 97b56809eb6984326651ea51d1dbcee4b8cfb6e9..35a6278c38eaa18ee5e49ff427a86af58543df26 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -45,8 +45,8 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c ArenaVector params(checker->Allocator()->Adapter()); if (isSetter) { - auto paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); - paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator())); + auto paramIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); + paramIdent->SetTsTypeAnnotation(field->TypeAnnotation()->Clone(checker->Allocator(), nullptr)); paramIdent->TypeAnnotation()->SetParent(paramIdent); auto *const paramExpression = checker->AllocNode(paramIdent, nullptr); @@ -61,17 +61,17 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c auto signature = ir::FunctionSignature(nullptr, std::move(params), isSetter ? nullptr : field->TypeAnnotation()); - auto *func = - isSetter - ? checker->AllocNode(std::move(signature), nullptr, ir::ScriptFunctionFlags::SETTER, - flags, true, Language(Language::Id::ETS)) - : checker->AllocNode(std::move(signature), nullptr, ir::ScriptFunctionFlags::GETTER, - flags, true, Language(Language::Id::ETS)); + auto *func = isSetter ? checker->AllocNode( + std::move(signature), nullptr, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::SETTER, flags, true}) + : checker->AllocNode( + std::move(signature), nullptr, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::GETTER, flags, true}); func->SetRange(field->Range()); func->SetScope(functionScope); - auto methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator()); + auto methodIdent = field->Key()->AsIdentifier()->Clone(checker->Allocator(), nullptr); auto *decl = checker->Allocator()->New(field->Key()->AsIdentifier()->Name()); auto var = functionScope->AddDecl(checker->Allocator(), decl, ScriptExtension::ETS); @@ -86,7 +86,7 @@ static ir::MethodDefinition *GenerateGetterOrSetter(checker::ETSChecker *const c method->Id()->SetMutator(); method->SetRange(field->Range()); - method->Function()->SetIdent(method->Id()); + method->Function()->SetIdent(method->Id()->Clone(checker->Allocator(), nullptr)); method->Function()->AddModifier(method->Modifiers()); paramScope->BindNode(func); functionScope->BindNode(func); diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index 9b4bfa606ba31d881cd882c665d28ff3401a5bc1..8253e18c6adf1e7876d37c14c22793d5a69f84e3 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -71,8 +71,21 @@ static lexer::TokenType OpEqualToOp(const lexer::TokenType opEqual) UNREACHABLE(); } -void AdjustBoxingUnboxingFlags(ir::Expression *newExpr, const ir::Expression *oldExpr) +void AdjustBoxingUnboxingFlags(ir::Expression *loweringResult, const ir::Expression *oldExpr) { + ir::AssignmentExpression *newAssignment = nullptr; + if (loweringResult->IsAssignmentExpression()) { + newAssignment = loweringResult->AsAssignmentExpression(); + } else if (loweringResult->IsBlockExpression() && !loweringResult->AsBlockExpression()->Statements().empty()) { + auto *statement = loweringResult->AsBlockExpression()->Statements().back(); + if (statement->IsExpressionStatement() && + statement->AsExpressionStatement()->GetExpression()->IsAssignmentExpression()) { + newAssignment = statement->AsExpressionStatement()->GetExpression()->AsAssignmentExpression(); + } + } else { + UNREACHABLE(); + } + // NOTE: gogabr. make sure that the checker never puts both a boxing and an unboxing flag on the same node. // Then this function will become unnecessary. const ir::BoxingUnboxingFlags oldBoxingFlag {oldExpr->GetBoxingUnboxingFlags() & @@ -80,11 +93,47 @@ void AdjustBoxingUnboxingFlags(ir::Expression *newExpr, const ir::Expression *ol const ir::BoxingUnboxingFlags oldUnboxingFlag {oldExpr->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG}; - if (newExpr->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - newExpr->SetBoxingUnboxingFlags(oldBoxingFlag); - } else if (newExpr->TsType()->IsETSObjectType()) { - newExpr->SetBoxingUnboxingFlags(oldUnboxingFlag); + if (newAssignment->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + newAssignment->SetBoxingUnboxingFlags(oldBoxingFlag); + } else if (newAssignment->TsType()->IsETSObjectType()) { + newAssignment->SetBoxingUnboxingFlags(oldUnboxingFlag); + } +} + +static ir::OpaqueTypeNode *CreateProxyTypeNode(checker::ETSChecker *checker, ir::Expression *expr) +{ + auto *lcType = expr->TsType(); + if (auto *lcTypeAsPrimitive = checker->ETSBuiltinTypeAsPrimitiveType(lcType); lcTypeAsPrimitive != nullptr) { + lcType = lcTypeAsPrimitive; + } + return checker->AllocNode(lcType); +} + +static std::string GenerateStringForLoweredAssignment(lexer::TokenType opEqual, bool hasProperty, ir::Expression *expr) +{ + std::string leftHand = "@@I5"; + std::string rightHand = "@@I7"; + + if (hasProperty) { + auto const kind = expr->AsMemberExpression()->Kind(); + if (kind == ir::MemberExpressionKind::PROPERTY_ACCESS) { + leftHand += ".@@I6"; + rightHand += ".@@I8"; + } else if (kind == ir::MemberExpressionKind::ELEMENT_ACCESS) { + leftHand += "[@@I6]"; + rightHand += "[@@I8]"; + } else { + UNREACHABLE(); + } } + + return leftHand + " = (" + rightHand + ' ' + std::string {lexer::TokenToString(OpEqualToOp(opEqual))} + + " (@@E9)) as @@T10"; +} + +static ir::Identifier *GetClone(ArenaAllocator *allocator, ir::Identifier *node) +{ + return node != nullptr ? node->Clone(allocator, nullptr) : nullptr; } ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker *checker, parser::ETSParser *parser, @@ -136,71 +185,25 @@ ir::Expression *HandleOpAssignment(public_lib::Context *ctx, checker::ETSChecker UNREACHABLE(); } - // Create proxy TypeNode for left hand of assignment expression - auto *lcType = left->TsType(); - if (auto *lcTypeAsPrimitive = checker->ETSBuiltinTypeAsPrimitiveType(lcType); lcTypeAsPrimitive != nullptr) { - lcType = lcTypeAsPrimitive; - } - auto *exprType = checker->AllocNode(lcType); + auto *exprType = CreateProxyTypeNode(checker, left); // Generate ArkTS code string for new lowered assignment expression: - std::string leftHand = "@@I5"; - std::string rightHand = "@@I7"; - - if (ident2 != nullptr) { - if (auto const kind = left->AsMemberExpression()->Kind(); kind == ir::MemberExpressionKind::PROPERTY_ACCESS) { - leftHand += ".@@I6"; - rightHand += ".@@I8"; - } else if (kind == ir::MemberExpressionKind::ELEMENT_ACCESS) { - leftHand += "[@@I6]"; - rightHand += "[@@I8]"; - } else { - UNREACHABLE(); - } - } - - newAssignmentStatements += leftHand + " = (" + rightHand + ' ' + - std::string {lexer::TokenToString(OpEqualToOp(opEqual))} + " (@@E9)) as @@T10"; - // std::cout << "Lowering statements: " << new_assignment_statements << std::endl; + newAssignmentStatements += GenerateStringForLoweredAssignment(opEqual, ident2 != nullptr, left); // Parse ArkTS code string and create and process corresponding AST node(s) auto expressionCtx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); - auto *loweringResult = parser->CreateFormattedExpression( - newAssignmentStatements, parser::DEFAULT_SOURCE_FILE, ident1, object, ident2, property, - ident1->Clone(allocator), ident2 != nullptr ? ident2->Clone(allocator) : nullptr, ident1->Clone(allocator), - ident2 != nullptr ? ident2->Clone(allocator) : nullptr, right, exprType); + auto *loweringResult = + parser->CreateFormattedExpression(newAssignmentStatements, parser::DEFAULT_SOURCE_FILE, ident1, object, ident2, + property, GetClone(allocator, ident1), GetClone(allocator, ident2), + GetClone(allocator, ident1), GetClone(allocator, ident2), right, exprType); loweringResult->SetParent(assignment->Parent()); InitScopesPhaseETS::RunExternalNode(loweringResult, ctx->compilerContext->VarBinder()); checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(loweringResult, scope); loweringResult->Check(checker); - // Adjust [un]boxing flag - ir::AssignmentExpression *newAssignment; - if (loweringResult->IsAssignmentExpression()) { - newAssignment = loweringResult->AsAssignmentExpression(); - } else if (loweringResult->IsBlockExpression() && !loweringResult->AsBlockExpression()->Statements().empty() && - loweringResult->AsBlockExpression()->Statements().back()->IsExpressionStatement() && - loweringResult->AsBlockExpression() - ->Statements() - .back() - ->AsExpressionStatement() - ->GetExpression() - ->IsAssignmentExpression()) { - newAssignment = loweringResult->AsBlockExpression() - ->Statements() - .back() - ->AsExpressionStatement() - ->GetExpression() - ->AsAssignmentExpression(); - } else { - UNREACHABLE(); - } - - // NOTE(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. - // Then this code will become unnecessary. - AdjustBoxingUnboxingFlags(newAssignment, assignment); + AdjustBoxingUnboxingFlags(loweringResult, assignment); return loweringResult; } diff --git a/ets2panda/compiler/lowering/ets/optionalLowering.cpp b/ets2panda/compiler/lowering/ets/optionalLowering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dfcd1b081d6616853bfcfe5e7c7b9720259f7eb0 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/optionalLowering.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "optionalLowering.h" +#include "checker/ETSchecker.h" +#include "compiler/lowering/util.h" +#include "compiler/lowering/scopesInit/scopesInitPhase.h" +#include "ir/statements/blockStatement.h" +#include "ir/expressions/memberExpression.h" +#include "parser/ETSparser.h" +#include "varbinder/ETSBinder.h" + +namespace panda::es2panda::compiler { + +std::string_view OptionalLowering::Name() +{ + return "OptionalLowering"; +} + +static ir::AstNode *RefineSourceRanges(ir::AstNode *node) +{ + auto const isDummyLoc = [](lexer::SourceRange const &range) { + return range.start.index == 0 && range.start.line == 0; + }; + + auto const refine = [isDummyLoc](ir::AstNode *n) { + if (isDummyLoc(n->Range())) { + n->SetRange(n->Parent()->Range()); + }; + }; + + refine(node); + node->IterateRecursively(refine); + return node; +} + +template +static ir::AstNode *LowerOptionalExpr(GetSource const &getSource, SetSource const &setSource, public_lib::Context *ctx, + Expr *const expr, ir::ChainExpression *const chain) +{ + auto *const allocator = ctx->allocator; + auto *const parser = ctx->parser->AsETSParser(); + auto *const varbinder = ctx->compilerContext->VarBinder(); + + auto expressionCtx = varbinder::LexicalScope::Enter(varbinder, NearestScope(expr)); + auto *tmpIdent = Gensym(allocator); + + // '0's act as placeholders + auto *sequenceExpr = parser->CreateFormattedExpression( + "let @@I1 = 0;" + "(@@I2 == null ? undefined : 0);", + parser::DEFAULT_SOURCE_FILE, tmpIdent, tmpIdent->Clone(allocator, nullptr)); + sequenceExpr->SetParent(chain->Parent()); + InitScopesPhaseETS::RunExternalNode(sequenceExpr, ctx->compilerContext->VarBinder()); + + auto const &stmts = sequenceExpr->AsBlockExpression()->Statements(); + stmts[0]->AsVariableDeclaration()->Declarators()[0]->SetInit(getSource(expr)); + stmts[1]->AsExpressionStatement()->GetExpression()->AsConditionalExpression()->SetAlternate(chain->GetExpression()); + + setSource(expr, parser->CreateFormattedExpression("@@I1!", parser::DEFAULT_SOURCE_FILE, + tmpIdent->Clone(allocator, nullptr))); + return sequenceExpr; +} + +static ir::AstNode *LowerExpression(public_lib::Context *ctx, ir::MemberExpression *const expr, + ir::ChainExpression *chain) +{ + ASSERT(expr->IsOptional()); + expr->ClearOptional(); + return LowerOptionalExpr([](auto *e) { return e->Object(); }, + [](auto *e, auto *obj) { e->SetObject(obj); }, ctx, expr, chain); +} + +static ir::AstNode *LowerExpression(public_lib::Context *ctx, ir::CallExpression *const expr, + ir::ChainExpression *chain) +{ + ASSERT(expr->IsOptional()); + expr->ClearOptional(); + return LowerOptionalExpr([](auto *e) { return e->Callee(); }, + [](auto *e, auto *callee) { e->SetCallee(callee); }, ctx, expr, chain); +} + +static ir::Expression *FindOptionalInChain(ir::Expression *expr) +{ + if (expr->IsMemberExpression()) { + auto typed = expr->AsMemberExpression(); + return typed->IsOptional() ? typed : FindOptionalInChain(typed->Object()); + } + if (expr->IsCallExpression()) { + auto typed = expr->AsCallExpression(); + return typed->IsOptional() ? typed : FindOptionalInChain(typed->Callee()); + } + if (expr->IsTSNonNullExpression()) { + return FindOptionalInChain(expr->AsTSNonNullExpression()->Expr()); + } + UNREACHABLE(); +} + +static ir::AstNode *LowerChain(public_lib::Context *ctx, ir::ChainExpression *const chain) +{ + auto optional = FindOptionalInChain(chain->GetExpression()); + if (optional->IsMemberExpression()) { + return LowerExpression(ctx, optional->AsMemberExpression(), chain); + } + if (optional->IsCallExpression()) { + return LowerExpression(ctx, optional->AsCallExpression(), chain); + } + UNREACHABLE(); +} + +bool OptionalLowering::Perform(public_lib::Context *ctx, parser::Program *program) +{ + for (auto &[_, ext_programs] : program->ExternalSources()) { + (void)_; + for (auto *extProg : ext_programs) { + Perform(ctx, extProg); + } + } + + program->Ast()->TransformChildrenRecursively([ctx](ir::AstNode *const node) -> ir::AstNode * { + if (node->IsChainExpression()) { + return RefineSourceRanges(LowerChain(ctx, node->AsChainExpression())); + } + return node; + }); + + return true; +} + +bool OptionalLowering::Postcondition(public_lib::Context *ctx, const parser::Program *program) +{ + for (auto &[_, ext_programs] : program->ExternalSources()) { + (void)_; + for (auto *extProg : ext_programs) { + if (!Postcondition(ctx, extProg)) { + return false; + } + } + } + + return !program->Ast()->IsAnyChild([](const ir::AstNode *node) { + return node->IsChainExpression() || (node->IsMemberExpression() && node->AsMemberExpression()->IsOptional()) || + (node->IsCallExpression() && node->AsCallExpression()->IsOptional()); + }); +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/optionalLowering.h b/ets2panda/compiler/lowering/ets/optionalLowering.h new file mode 100644 index 0000000000000000000000000000000000000000..4ba752d2ecb239dfd765d568d0f30ef655c31576 --- /dev/null +++ b/ets2panda/compiler/lowering/ets/optionalLowering.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_COMPILER_LOWERING_OPTIONAL_LOWERING_H +#define ES2PANDA_COMPILER_LOWERING_OPTIONAL_LOWERING_H + +#include "compiler/lowering/phase.h" + +namespace panda::es2panda::compiler { + +class OptionalLowering : public Phase { +public: + std::string_view Name() override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; + bool Postcondition(public_lib::Context *ctx, const parser::Program *program) override; +}; + +} // namespace panda::es2panda::compiler + +#endif diff --git a/ets2panda/compiler/lowering/ets/tupleLowering.cpp b/ets2panda/compiler/lowering/ets/tupleLowering.cpp index 5d81de89d92defb083849f27f1ce2981cb5b398c..67132fed0935af2176618ed5b64411a6a99e739e 100644 --- a/ets2panda/compiler/lowering/ets/tupleLowering.cpp +++ b/ets2panda/compiler/lowering/ets/tupleLowering.cpp @@ -81,13 +81,16 @@ static ir::Expression *ConvertTupleUpdate(checker::ETSChecker *const checker, ir // Clone argument of update expression (conversion flag might be added to it, so we need to duplicate it to not make // conversions on 'line 3', that belongs to 'line 1' ) auto *const memberExpr = argument->AsMemberExpression(); - auto *const argumentClone = - checker->AllocNode(memberExpr->Object(), memberExpr->Property(), memberExpr->Kind(), - memberExpr->IsComputed(), memberExpr->IsOptional()); - argumentClone->SetPropVar(memberExpr->PropVar()); - argumentClone->SetParent(memberExpr->Parent()); + auto *const argumentClone = memberExpr->Clone(checker->Allocator(), memberExpr->Parent()); + argumentClone->Object()->SetTsType(memberExpr->Object()->TsType()); + if (argumentClone->Object()->IsIdentifier()) { + argumentClone->Object()->AsIdentifier()->SetVariable(memberExpr->Object()->AsIdentifier()->Variable()); + } + argumentClone->Property()->SetTsType(memberExpr->Property()->TsType()); + if (argumentClone->Property()->IsIdentifier()) { + argumentClone->Property()->AsIdentifier()->SetVariable(memberExpr->Property()->AsIdentifier()->Variable()); + } argumentClone->SetTsType(memberExpr->TsType()); - argumentClone->SetObjectType(memberExpr->ObjType()); // -------------- // Generate temporary symbols @@ -113,20 +116,29 @@ static ir::Expression *ConvertTupleUpdate(checker::ETSChecker *const checker, ir // -------------- // make node: let gensym2 = (gensym)++; - auto *gensymUpdate = checker->AllocNode(gensym, update->OperatorType(), update->IsPrefix()); + auto *identClone = gensym->Clone(checker->Allocator(), nullptr); + identClone->SetTsType(tmpVar->TsType()); + auto *gensymUpdate = + checker->AllocNode(identClone, update->OperatorType(), update->IsPrefix()); auto *const gensym2Assignment = checker->AllocNode(gensym2, gensymUpdate, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); // -------------- // make node: tuple[n] = (gensym as ) as ; - auto *gensymAs = checker->AllocNode(gensym, tupleTypeAtIdxNode, false); + identClone = gensym->Clone(checker->Allocator(), nullptr); + identClone->SetTsType(tmpVar->TsType()); + auto *gensymAs = checker->AllocNode( + identClone, tupleTypeAtIdxNode->Clone(checker->Allocator(), nullptr), false); auto *gensymAsTupleTypeAtIdx = checker->AllocNode(gensymAs, tupleElementTypeNode, false); auto *const tupleAssignment = checker->AllocNode( argument, gensymAsTupleTypeAtIdx, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); // -------------- // make node: gensym2 as ; - auto *const finalTupleNode = checker->AllocNode(gensym2, tupleTypeAtIdxNode, false); + identClone = gensym2->Clone(checker->Allocator(), nullptr); + identClone->SetTsType(tmpVar2->TsType()); + auto *const finalTupleNode = checker->AllocNode( + identClone, tupleTypeAtIdxNode->Clone(checker->Allocator(), nullptr), false); // -------------- // Construct sequence expression order diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index ef64447b6944d8ca51ff118cfb8fa9bacefa6218..55311115c4951bf62de12b204ebfbdf48d312f9c 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -20,8 +20,10 @@ #include "checker/ETSchecker.h" #include "checker/ets/conversion.h" #include "checker/ets/boxingConverter.h" +#include "checker/ets/unboxingConverter.h" #include "compiler/core/compilerContext.h" #include "compiler/lowering/util.h" +#include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "ir/base/classDefinition.h" #include "ir/base/classProperty.h" #include "ir/astNode.h" @@ -82,11 +84,11 @@ varbinder::LocalVariable *CreateUnionFieldClassProperty(checker::ETSChecker *che } // Create field name for synthetic class - auto *fieldIdent = allocator->New(propName, allocator); + auto *fieldIdent = checker->AllocNode(propName, allocator); // Create the synthetic class property node auto *field = - allocator->New(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, allocator, false); + checker->AllocNode(fieldIdent, nullptr, nullptr, ir::ModifierFlags::NONE, allocator, false); // Add the declaration to the scope auto [decl, var] = varbinder->NewVarDecl(fieldIdent->Start(), fieldIdent->Name()); @@ -105,6 +107,11 @@ varbinder::LocalVariable *CreateUnionFieldClassProperty(checker::ETSChecker *che void HandleUnionPropertyAccess(checker::ETSChecker *checker, varbinder::VarBinder *vbind, ir::MemberExpression *expr) { ASSERT(expr->PropVar() == nullptr); + auto parent = expr->Parent(); + if (parent->IsCallExpression() && + !parent->AsCallExpression()->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE)) { + return; + } expr->SetPropVar( CreateUnionFieldClassProperty(checker, vbind, expr->TsType(), expr->Property()->AsIdentifier()->Name())); ASSERT(expr->PropVar() != nullptr); @@ -116,7 +123,6 @@ ir::TSAsExpression *GenAsExpression(checker::ETSChecker *checker, checker::Type auto *const typeNode = checker->AllocNode(opaqueType); auto *const asExpression = checker->AllocNode(node, typeNode, false); asExpression->SetParent(parent); - node->SetParent(asExpression); asExpression->Check(checker); return asExpression; } @@ -131,13 +137,7 @@ ir::TSAsExpression *UnionCastToPrimitive(checker::ETSChecker *checker, checker:: checker::Type *unboxedPrim, ir::Expression *unionNode) { auto *const unionAsRefExpression = GenAsExpression(checker, unboxableRef, unionNode, nullptr); - unionAsRefExpression->SetBoxingUnboxingFlags(checker->GetUnboxingFlag(unboxedPrim)); - unionNode->SetParent(unionAsRefExpression); - - auto *const refAsPrimExpression = GenAsExpression(checker, unboxedPrim, unionAsRefExpression, unionNode->Parent()); - unionAsRefExpression->SetParent(refAsPrimExpression); - - return refAsPrimExpression; + return GenAsExpression(checker, unboxedPrim, unionAsRefExpression, unionNode->Parent()); } ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *checker, ir::TSAsExpression *expr) @@ -164,36 +164,15 @@ ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *checker, ir: return expr; } -ir::BinaryExpression *GenInstanceofExpr(checker::ETSChecker *checker, ir::Expression *unionNode, +ir::BinaryExpression *GenInstanceofExpr(checker::ETSChecker *checker, ir::Identifier *unionNode, checker::Type *constituentType) { - auto *const lhsExpr = unionNode->Clone(checker->Allocator())->AsExpression(); + auto *const lhsExpr = unionNode->Clone(checker->Allocator(), nullptr)->AsExpression(); lhsExpr->Check(checker); lhsExpr->SetBoxingUnboxingFlags(unionNode->GetBoxingUnboxingFlags()); - auto *rhsType = constituentType; - if (!constituentType->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { - checker->Relation()->SetNode(unionNode); - rhsType = checker::conversion::Boxing(checker->Relation(), constituentType); - checker->Relation()->SetNode(nullptr); - } - if (constituentType->IsETSStringType()) { - rhsType = checker->GlobalBuiltinETSStringType(); - } - ir::Expression *rhsExpr; - if (rhsType->IsETSUndefinedType()) { - rhsExpr = checker->Allocator()->New(); - } else if (rhsType->IsETSNullType()) { - rhsExpr = checker->Allocator()->New(); - } else { - rhsExpr = checker->Allocator()->New(rhsType->AsETSObjectType()->Name(), checker->Allocator()); - auto rhsVar = NearestScope(unionNode)->Find(rhsExpr->AsIdentifier()->Name()); - rhsExpr->AsIdentifier()->SetVariable(rhsVar.variable); - } + auto *const rhsExpr = checker->AllocNode(constituentType); auto *const instanceofExpr = - checker->Allocator()->New(rhsExpr, rhsExpr, lexer::TokenType::KEYW_INSTANCEOF); - rhsExpr->SetParent(instanceofExpr); - rhsExpr->SetParent(instanceofExpr); - rhsExpr->SetTsType(rhsType); + checker->AllocNode(lhsExpr, rhsExpr, lexer::TokenType::KEYW_INSTANCEOF); instanceofExpr->SetOperationType(checker->GlobalETSObjectType()); instanceofExpr->SetTsType(checker->GlobalETSBooleanType()); return instanceofExpr; @@ -212,6 +191,9 @@ ir::VariableDeclaration *GenVariableDeclForBinaryExpr(checker::ETSChecker *check varId->SetTsType(var->TsType()); auto declarator = checker->AllocNode(ir::VariableDeclaratorFlag::LET, varId); + declarator->SetInit( + checker->AllocNode(expr->OperatorType() != lexer::TokenType::PUNCTUATOR_EQUAL)); + declarator->Init()->Check(checker); ArenaVector declarators(checker->Allocator()->Adapter()); declarators.push_back(declarator); @@ -240,7 +222,6 @@ ir::BlockStatement *GenBlockStmtForAssignmentBinary(checker::ETSChecker *checker stmts.push_back(stmt); auto *const localBlockStmt = checker->AllocNode(checker->Allocator(), std::move(stmts)); localBlockStmt->SetScope(localCtx.GetScope()); - stmt->SetParent(localBlockStmt); localBlockStmt->SetRange(stmt->Range()); localCtx.GetScope()->BindNode(localBlockStmt); return localBlockStmt; @@ -249,8 +230,9 @@ ir::BlockStatement *GenBlockStmtForAssignmentBinary(checker::ETSChecker *checker ir::Expression *SetBoxFlagOrGenAsExpression(checker::ETSChecker *checker, checker::Type *constituentType, ir::Expression *otherNode) { - if (constituentType->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::UNBOXABLE_TYPE) && - !otherNode->IsETSUnionType() && otherNode->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + if (constituentType->IsETSObjectType() && + constituentType->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::UNBOXABLE_TYPE) && + otherNode->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { auto *unboxedConstituentType = checker->ETSBuiltinTypeAsPrimitiveType(constituentType); if (unboxedConstituentType != otherNode->TsType()) { auto *const primAsExpression = @@ -267,25 +249,18 @@ ir::Expression *SetBoxFlagOrGenAsExpression(checker::ETSChecker *checker, checke return otherNode; } -ir::Expression *ProcessOperandsInBinaryExpr(checker::ETSChecker *checker, ir::BinaryExpression *expr, - checker::Type *constituentType) +ir::Expression *ProcessOperandsInBinaryExpr(checker::ETSChecker *checker, ir::BinaryExpression *expr, bool isLhsUnion, + checker::ETSObjectType *constituentType) { ASSERT(expr->OperatorType() == lexer::TokenType::PUNCTUATOR_EQUAL || expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NOT_EQUAL); - bool isLhsUnion = false; - ir::Expression *unionNode = (isLhsUnion = expr->Left()->TsType()->IsETSUnionType()) ? expr->Left() : expr->Right(); - checker::Type *typeToCast = constituentType->IsETSNullLike() - ? unionNode->TsType()->AsETSUnionType()->GetLeastUpperBoundType() - : constituentType; - auto *const asExpression = GenAsExpression(checker, typeToCast, unionNode, expr); if (isLhsUnion) { - expr->SetLeft(asExpression); - expr->SetRight(SetBoxFlagOrGenAsExpression(checker, constituentType, expr->Right())); + expr->SetLeft(UnionCastToPrimitive(checker, constituentType, expr->Right()->TsType(), expr->Left())); } else { - expr->SetRight(asExpression); - expr->SetLeft(SetBoxFlagOrGenAsExpression(checker, constituentType, expr->Left())); + expr->SetRight(UnionCastToPrimitive(checker, constituentType, expr->Left()->TsType(), expr->Right())); } - expr->SetOperationType(checker->GlobalETSObjectType()); + ASSERT(expr->Right()->TsType() == expr->Left()->TsType()); + expr->SetOperationType(expr->Right()->TsType()); expr->SetTsType(checker->GlobalETSBooleanType()); return expr; } @@ -300,8 +275,7 @@ ir::Statement *FindStatementFromNode(ir::Expression *expr) return node->AsStatement(); } -void InsertInstanceofTreeBeforeStmt(ir::Statement *stmt, ir::VariableDeclaration *binaryVarDecl, - ir::Statement *instanceofTree) +static void InsertAfterStmt(ir::Statement *stmt, ir::Statement *ins) { if (stmt->IsVariableDeclarator()) { ASSERT(stmt->Parent()->IsVariableDeclaration()); @@ -309,71 +283,128 @@ void InsertInstanceofTreeBeforeStmt(ir::Statement *stmt, ir::VariableDeclaration } ASSERT(stmt->Parent()->IsBlockStatement()); auto *block = stmt->Parent()->AsBlockStatement(); - binaryVarDecl->SetParent(block); - instanceofTree->SetParent(block); + ins->SetParent(block); auto itStmt = std::find(block->Statements().begin(), block->Statements().end(), stmt); - block->Statements().insert(itStmt, {binaryVarDecl, instanceofTree}); + block->Statements().insert(itStmt, ins); +} + +static ir::Identifier *CreatePrecomputedTemporary(public_lib::Context *ctx, ir::Statement *pos, ir::Expression *expr) +{ + auto *const allocator = ctx->allocator; + auto *const checker = ctx->checker->AsETSChecker(); + auto *const parser = ctx->parser->AsETSParser(); + auto *const varbinder = ctx->compilerContext->VarBinder(); + + auto expressionCtx = varbinder::LexicalScope::Enter(varbinder, NearestScope(expr)); + + auto *const temp = Gensym(allocator); + + auto *const vardecl = parser->CreateFormattedStatements("let @@I1: @@T2;", parser::DEFAULT_SOURCE_FILE, temp, + checker->AllocNode(expr->TsType()))[0]; + + InsertAfterStmt(pos, vardecl); + InitScopesPhaseETS::RunExternalNode(vardecl, varbinder); + vardecl->AsVariableDeclaration()->Declarators()[0]->SetInit(expr); + vardecl->Check(checker); + + auto *cloned = temp->Clone(allocator, nullptr); + cloned->Check(checker); + return cloned; } -ir::BlockStatement *ReplaceBinaryExprInStmt(checker::ETSChecker *checker, ir::Expression *unionNode, - ir::BlockStatement *block, ir::BinaryExpression *expr) +static ir::BlockStatement *ReplaceBinaryExprInStmt(public_lib::Context *ctx, ir::BlockStatement *block, + ir::BinaryExpression *expr) { + auto *const checker = ctx->checker->AsETSChecker(); + auto *stmt = FindStatementFromNode(expr); ASSERT(stmt->IsVariableDeclarator() || block == stmt->Parent()); // statement with union auto *const binaryVarDecl = GenVariableDeclForBinaryExpr(checker, NearestScope(stmt), expr); auto *const varDeclId = binaryVarDecl->Declarators().front()->Id(); // only one declarator was generated ir::IfStatement *instanceofTree = nullptr; + + expr->SetLeft(CreatePrecomputedTemporary(ctx, stmt, expr->Left())); + expr->SetRight(CreatePrecomputedTemporary(ctx, stmt, expr->Right())); + + bool isLhsUnion = expr->Left()->TsType()->IsETSUnionType(); + auto *const unionNode = isLhsUnion ? expr->Left() : expr->Right(); + for (auto *uType : unionNode->TsType()->AsETSUnionType()->ConstituentTypes()) { - auto *const test = GenInstanceofExpr(checker, unionNode, uType); + if (!uType->IsETSObjectType() || + !uType->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::UNBOXABLE_TYPE)) { + continue; + } + auto *const test = GenInstanceofExpr(checker, unionNode->AsIdentifier(), uType); auto *clonedBinary = expr->Clone(checker->Allocator(), expr->Parent())->AsBinaryExpression(); clonedBinary->Check(checker); auto *const consequent = GenBlockStmtForAssignmentBinary( - checker, varDeclId->AsIdentifier(), ProcessOperandsInBinaryExpr(checker, clonedBinary, uType)); - instanceofTree = checker->Allocator()->New(test, consequent, instanceofTree); - test->SetParent(instanceofTree); - consequent->SetParent(instanceofTree); - if (instanceofTree->Alternate() != nullptr) { - instanceofTree->Alternate()->SetParent(instanceofTree); - } + checker, varDeclId->AsIdentifier()->Clone(checker->Allocator(), nullptr), + ProcessOperandsInBinaryExpr(checker, clonedBinary, isLhsUnion, uType->AsETSObjectType())); + instanceofTree = checker->AllocNode(test, consequent, instanceofTree); } ASSERT(instanceofTree != nullptr); // Replacing a binary expression with an identifier // that was set in one of the branches of the `instanceof_tree` tree - stmt->TransformChildrenRecursively([varDeclId](ir::AstNode *ast) -> ir::AstNode * { + stmt->TransformChildrenRecursively([varDeclId, checker](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsBinaryExpression() && ast->AsBinaryExpression()->OperationType() != nullptr && ast->AsBinaryExpression()->OperationType()->IsETSUnionType()) { - return varDeclId; + auto cloned = varDeclId->Clone(checker->Allocator(), ast->Parent()); + cloned->Check(checker); + return cloned; } return ast; }); - InsertInstanceofTreeBeforeStmt(stmt, binaryVarDecl, instanceofTree); + InsertAfterStmt(stmt, binaryVarDecl); + InsertAfterStmt(stmt, instanceofTree); return block; } -ir::BlockStatement *HandleBlockWithBinaryAndUnion(checker::ETSChecker *checker, ir::BlockStatement *block, +ir::BlockStatement *HandleBlockWithBinaryAndUnion(public_lib::Context *ctx, ir::BlockStatement *block, ir::BinaryExpression *binExpr) { if (binExpr->OperatorType() != lexer::TokenType::PUNCTUATOR_EQUAL && binExpr->OperatorType() != lexer::TokenType::PUNCTUATOR_NOT_EQUAL) { - checker->ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", - binExpr->Start()); + ctx->checker->ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", + binExpr->Start()); } - ir::Expression *unionNode = binExpr->Left()->TsType()->IsETSUnionType() ? binExpr->Left() : binExpr->Right(); - return ReplaceBinaryExprInStmt(checker, unionNode, block, binExpr); + return ReplaceBinaryExprInStmt(ctx, block, binExpr); } -ir::BlockStatement *HandleBlockWithBinaryAndUnions(checker::ETSChecker *checker, ir::BlockStatement *block, +ir::BlockStatement *HandleBlockWithBinaryAndUnions(public_lib::Context *ctx, ir::BlockStatement *block, const ir::NodePredicate &handleBinary) { ir::BlockStatement *modifiedAstBlock = block; while (modifiedAstBlock->IsAnyChild(handleBinary)) { modifiedAstBlock = HandleBlockWithBinaryAndUnion( - checker, modifiedAstBlock, modifiedAstBlock->FindChild(handleBinary)->AsBinaryExpression()); + ctx, modifiedAstBlock, modifiedAstBlock->FindChild(handleBinary)->AsBinaryExpression()); } return modifiedAstBlock; } +static bool BinaryLoweringAppliable(const ir::AstNode *astNode) +{ + if (!astNode->IsBinaryExpression()) { + return false; + } + auto *binary = astNode->AsBinaryExpression(); + if (binary->OperatorType() == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { + return false; + } + auto *const lhsType = binary->Left()->TsType(); + auto *const rhsType = binary->Right()->TsType(); + if (lhsType == nullptr || rhsType == nullptr) { + return false; + } + if (lhsType->IsETSReferenceType() && rhsType->IsETSReferenceType()) { + return false; + } + if (!lhsType->IsETSUnionType() && !rhsType->IsETSUnionType()) { + return false; + } + return binary->OperationType() != nullptr && binary->OperationType()->IsETSUnionType(); +} + bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) { for (auto &[_, ext_programs] : program->ExternalSources()) { @@ -385,11 +416,14 @@ bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *ast) -> ir::AstNode * { - if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && - ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType()) { - HandleUnionPropertyAccess(checker, checker->VarBinder(), ast->AsMemberExpression()); - return ast; + program->Ast()->TransformChildrenRecursively([checker, ctx](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr) { + auto *objType = + checker->GetApparentType(checker->GetNonNullishType(ast->AsMemberExpression()->Object()->TsType())); + if (objType->IsETSUnionType()) { + HandleUnionPropertyAccess(checker, checker->VarBinder(), ast->AsMemberExpression()); + return ast; + } } if (ast->IsTSAsExpression() && ast->AsTSAsExpression()->Expr()->TsType() != nullptr && @@ -399,12 +433,8 @@ bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) return HandleUnionCastToPrimitive(checker, ast->AsTSAsExpression()); } - auto handleBinary = [](const ir::AstNode *astNode) { - return astNode->IsBinaryExpression() && astNode->AsBinaryExpression()->OperationType() != nullptr && - astNode->AsBinaryExpression()->OperationType()->IsETSUnionType(); - }; - if (ast->IsBlockStatement() && ast->IsAnyChild(handleBinary)) { - return HandleBlockWithBinaryAndUnions(checker, ast->AsBlockStatement(), handleBinary); + if (ast->IsBlockStatement() && ast->IsAnyChild(BinaryLoweringAppliable)) { + return HandleBlockWithBinaryAndUnions(ctx, ast->AsBlockStatement(), BinaryLoweringAppliable); } return ast; @@ -415,10 +445,19 @@ bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) bool UnionLowering::Postcondition(public_lib::Context *ctx, const parser::Program *program) { - 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; + bool current = !program->Ast()->IsAnyChild([checker = ctx->checker->AsETSChecker()](ir::AstNode *ast) { + if (!ast->IsMemberExpression() || ast->AsMemberExpression()->Object()->TsType() == nullptr) { + return false; + } + auto *objType = + checker->GetApparentType(checker->GetNonNullishType(ast->AsMemberExpression()->Object()->TsType())); + auto *parent = ast->Parent(); + if (parent != nullptr && // #15040 + !(parent->IsCallExpression() && + parent->AsCallExpression()->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE))) { + return false; + } + return objType->IsETSUnionType() && ast->AsMemberExpression()->PropVar() == nullptr; }); if (!current || ctx->compilerContext->Options()->compilationMode != CompilationMode::GEN_STD_LIB) { return current; diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index ad5e543ef4c462570c22f989d4e505cbbbdb8398..042e449a3c2a7602d382a31625c95a58a01b1ce1 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -30,6 +30,7 @@ #include "compiler/lowering/ets/tupleLowering.h" #include "compiler/lowering/ets/unionLowering.h" #include "compiler/lowering/ets/structLowering.h" +#include "compiler/lowering/ets/optionalLowering.h" #include "public/es2panda_lib.h" #include "compiler/lowering/ets/promiseVoid.h" #include "utils/json_builder.h" @@ -52,6 +53,7 @@ static OpAssignmentLowering g_opAssignmentLowering; static ObjectIndexLowering g_objectIndexLowering; static TupleLowering g_tupleLowering; // Can be only applied after checking phase, and OP_ASSIGNMENT_LOWERING phase static UnionLowering g_unionLowering; +static OptionalLowering g_optionalLowering; static ExpandBracketsPhase g_expandBracketsPhase; static PromiseVoidInferencePhase g_promiseVoidInferencePhase; static StructLowering g_structLowering; @@ -69,11 +71,14 @@ static InitScopesPhaseJs g_initScopesPhaseJs; std::vector GetETSPhaseList() { return { - &g_pluginsAfterParse, &g_initScopesPhaseEts, &g_promiseVoidInferencePhase, - &g_structLowering, &g_lambdaConstructionPhase, &g_interfacePropDeclPhase, - &g_checkerPhase, &g_pluginsAfterCheck, &g_generateTsDeclarationsPhase, - &g_opAssignmentLowering, &g_objectIndexLowering, &g_tupleLowering, - &g_unionLowering, &g_expandBracketsPhase, &g_pluginsAfterLowerings, + &g_pluginsAfterParse, &g_initScopesPhaseEts, + &g_optionalLowering, &g_promiseVoidInferencePhase, + &g_structLowering, &g_lambdaConstructionPhase, + &g_interfacePropDeclPhase, &g_checkerPhase, + &g_pluginsAfterCheck, &g_generateTsDeclarationsPhase, + &g_opAssignmentLowering, &g_objectIndexLowering, + &g_tupleLowering, &g_unionLowering, + &g_expandBracketsPhase, &g_pluginsAfterLowerings, }; } diff --git a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp index 736ba8c6cdf4bc7beef7a3a4389db2618998c8e9..3c4e61f9717db87ee81e80fdafda7d6df918f19d 100644 --- a/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp +++ b/ets2panda/compiler/lowering/scopesInit/scopesInitPhase.cpp @@ -400,7 +400,7 @@ void ScopesInitPhase::VisitFunctionExpression(ir::FunctionExpression *funcExpr) auto id = funcExpr->Id(); auto *funcParamScope = func->Scope()->ParamScope(); funcParamScope->BindName(Allocator(), id->Name()); - func->SetIdent(id); + func->SetIdent(id->Clone(Allocator(), nullptr)); } } @@ -734,16 +734,22 @@ void InitScopesPhaseETS::VisitImportNamespaceSpecifier(ir::ImportNamespaceSpecif Iterate(importSpec); } -void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) +// Auxiliary method to avoid extra nested levels and too large function size +void AddOverload(ir::MethodDefinition *overload, varbinder::Variable *variable) noexcept { - const auto methodName = method->Id(); + auto *currentNode = variable->Declaration()->Node(); + currentNode->AsMethodDefinition()->AddOverload(overload); + overload->Id()->SetVariable(variable); +} +void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) +{ ASSERT(VarBinder()->GetScope()->IsClassScope()); - if (method->AsMethodDefinition()->Function()->IsDefaultParamProxy()) { return; } + const auto methodName = method->Id(); auto *const clsScope = VarBinder()->GetScope()->AsClassScope(); if (clsScope->FindLocal(methodName->Name(), varbinder::ResolveBindingOptions::VARIABLES | varbinder::ResolveBindingOptions::DECLARATION) != nullptr) { @@ -758,18 +764,10 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) } auto *found = targetScope->FindLocal(methodName->Name(), varbinder::ResolveBindingOptions::BINDINGS); - auto addOverload = [](ir::MethodDefinition *overload, varbinder::Variable *of) { - auto *currentNode = of->Declaration()->Node(); - currentNode->AsMethodDefinition()->AddOverload(overload); - overload->Id()->SetVariable(of); - overload->SetParent(currentNode); - }; - if (found == nullptr) { auto classCtx = varbinder::LexicalScope::Enter(VarBinder(), targetScope); - auto [_, var] = VarBinder()->NewVarDecl(methodName->Start(), Allocator(), - methodName->Name(), method); - (void)_; + [[maybe_unused]] auto [_, var] = VarBinder()->NewVarDecl( + methodName->Start(), Allocator(), methodName->Name(), method); var->SetScope(clsScope); var->AddFlag(varbinder::VariableFlags::METHOD); methodName->SetVariable(var); @@ -782,13 +780,13 @@ void InitScopesPhaseETS::DeclareClassMethod(ir::MethodDefinition *method) if (methodName->Name().Is(compiler::Signatures::MAIN) && clsScope->Parent()->IsGlobalScope()) { ThrowSyntaxError("Main overload is not enabled", methodName->Start()); } - addOverload(method, found); + AddOverload(method, found); method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); // default params proxy for (auto *overload : method->Overloads()) { ASSERT(overload->Function()->IsDefaultParamProxy()); - addOverload(overload, found); + AddOverload(overload, found); } method->ClearOverloads(); } diff --git a/ets2panda/compiler/lowering/util.cpp b/ets2panda/compiler/lowering/util.cpp index cab0d07614b40166d81e52ebd0a9519aad041dd2..a558ce5136ab6181c840aebcf4a3434bff7a8023 100644 --- a/ets2panda/compiler/lowering/util.cpp +++ b/ets2panda/compiler/lowering/util.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ -#include - #include "util.h" #include "ir/expressions/identifier.h" @@ -23,16 +21,11 @@ namespace panda::es2panda::compiler { varbinder::Scope *NearestScope(const ir::AstNode *ast) { - if (ast == nullptr) { - return nullptr; - } - - while (!ast->IsScopeBearer()) { + while (ast != nullptr && !ast->IsScopeBearer()) { ast = ast->Parent(); - ASSERT(ast != nullptr); } - return ast->Scope(); + return ast == nullptr ? nullptr : ast->Scope(); } ir::Identifier *Gensym(ArenaAllocator *const allocator) diff --git a/ets2panda/compiler/scripts/signatures.yaml b/ets2panda/compiler/scripts/signatures.yaml index c0797950622c2fd8f0b8e17cf44e2c24bc607b68..cac849fc1ae7c7774f832e370a01d9c99e0f4864 100644 --- a/ets2panda/compiler/scripts/signatures.yaml +++ b/ets2panda/compiler/scripts/signatures.yaml @@ -263,6 +263,9 @@ builtins: - name: AssertionError package: PKG_ESCOMPAT ref: BUILTIN_ASSERTION_ERROR + - name: Runtime + package: PKG_STD_CORE + ref: BUILTIN_RUNTIME - name: JSRuntime package: PKG_STD_INTEROP_JS ref: BUILTIN_JSRUNTIME @@ -296,6 +299,60 @@ builtins: - name: DoubleBox package: PKG_STD_CORE ref: BUILTIN_DOUBLE_BOX + - name: Function0 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION0 + - name: Function1 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION1 + - name: Function2 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION2 + - name: Function3 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION3 + - name: Function4 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION4 + - name: Function5 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION5 + - name: Function6 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION6 + - name: Function7 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION7 + - name: Function8 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION8 + - name: Function9 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION9 + - name: Function10 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION10 + - name: Function11 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION11 + - name: Function12 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION12 + - name: Function13 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION13 + - name: Function14 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION14 + - name: Function15 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION15 + - name: Function16 + package: PKG_STD_CORE + ref: BUILTIN_FUNCTION16 + - name: FunctionN + package: PKG_STD_CORE + ref: BUILTIN_FUNCTIONN signatures: - callee: BUILTIN_OBJECT @@ -352,6 +409,12 @@ signatures: return_type: PRIMITIVE_VOID ref: BUILTIN_ASSERTION_ERROR_CTOR + - callee: BUILTIN_RUNTIME + method_name: failedTypeCastException + params: [BUILTIN_OBJECT, BUILTIN_STRING] + return_type: BUILTIN_CLASS_CAST_EXCEPTION + ref: BUILTIN_RUNTIME_FAILED_TYPE_CAST_EXCEPTION + - callee: BUILTIN_BIGINT method_name: $CTOR params: [BUILTIN_STRING] @@ -492,7 +555,7 @@ signatures: - callee: BUILTIN_CLASS_CAST_EXCEPTION method_name: $CTOR - params: [] + params: [BUILTIN_STRING] return_type: PRIMITIVE_VOID ref: BUILTIN_CLASS_CAST_EXCEPTION_CTOR @@ -1030,12 +1093,6 @@ signatures: return_type: BUILTIN_VOID ref: BUILTIN_JSRUNTIME_INIT_DYNAMIC_NEW_CLASS - - callee: BUILTIN_JSRUNTIME - method_name: __createLambdaProxy - params: [BUILTIN_OBJECT] - return_type: BUILTIN_JSVALUE - ref: BUILTIN_JSRUNTIME_CREATE_LAMBDA_PROXY - - callee: BUILTIN_JSRUNTIME method_name: loadModule params: [BUILTIN_STRING] diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 4b20f93db346cc953bcf72a36e663d1400b190c3..9b7741d350a14614ace814ece7c2ceaa4250a84c 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -326,16 +326,6 @@ public: return (flags_ & ModifierFlags::NATIVE) != 0; } - [[nodiscard]] bool IsNullAssignable() const noexcept - { - return (flags_ & ModifierFlags::NULL_ASSIGNABLE) != 0; - } - - [[nodiscard]] bool IsUndefinedAssignable() const noexcept - { - return (flags_ & ModifierFlags::UNDEFINED_ASSIGNABLE) != 0; - } - [[nodiscard]] bool IsConst() const noexcept { return (flags_ & ModifierFlags::CONST) != 0; @@ -484,9 +474,8 @@ public: [[nodiscard]] ir::BlockStatement *GetTopStatement(); [[nodiscard]] const ir::BlockStatement *GetTopStatement() const; - // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] virtual AstNode *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) + [[maybe_unused]] AstNode *const parent) { UNREACHABLE(); } diff --git a/ets2panda/ir/astNodeFlags.h b/ets2panda/ir/astNodeFlags.h index fb74be021bc80d3c8a18e49082a594d858a9cc10..5121701dbc436715b471f3f0f37e85f96c242e78 100644 --- a/ets2panda/ir/astNodeFlags.h +++ b/ets2panda/ir/astNodeFlags.h @@ -47,11 +47,9 @@ enum class ModifierFlags : uint32_t { IN = 1U << 17U, OUT = 1U << 18U, INTERNAL = 1U << 19U, - NULL_ASSIGNABLE = 1U << 20U, - UNDEFINED_ASSIGNABLE = 1U << 21U, - EXPORT = 1U << 22U, - SETTER = 1U << 23U, - DEFAULT_EXPORT = 1U << 24U, + EXPORT = 1U << 20U, + SETTER = 1U << 21U, + DEFAULT_EXPORT = 1U << 22U, 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 94ad053988f63309c9fbf4ce6a132a28d7c48d63..e7c242cb30432f2253312ddb3b833b706d5b9edc 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -76,6 +76,8 @@ _(SCRIPT_FUNCTION, ScriptFunction) \ _(SEQUENCE_EXPRESSION, SequenceExpression) \ _(STRING_LITERAL, StringLiteral) \ + _(ETS_NULL_TYPE, ETSNullType) \ + _(ETS_UNDEFINED_TYPE, ETSUndefinedType) \ _(ETS_FUNCTION_TYPE, ETSFunctionType) \ _(ETS_WILDCARD_TYPE, ETSWildcardType) \ _(ETS_PRIMITIVE_TYPE, ETSPrimitiveType) \ diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index cfb7ac8dc8e3fad80cfdd96a3f50e5f338dd6d33..94b77be1b6577a18913e0aecb3d66c34b26a1d07 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -117,6 +117,14 @@ void ClassDefinition::Iterate(const NodeTraverser &cb) const } } +void ClassDefinition::SetIdent(ir::Identifier *ident) noexcept +{ + ident_ = ident; + if (ident_ != nullptr) { + ident_->SetParent(this); + } +} + void ClassDefinition::Dump(ir::AstDumper *dumper) const { auto propFilter = [](AstNode *prop) -> bool { diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index 49d1237bf1e0fe3badf2223a99e4d65cd0b3a110..7161da90078b82d2d9b26951094e4ea54a6e31a1 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -123,10 +123,7 @@ public: return ident_; } - void SetIdent(ir::Identifier *ident) noexcept - { - ident_ = ident; - } + void SetIdent(ir::Identifier *ident) noexcept; [[nodiscard]] const util::StringView &PrivateId() const noexcept { @@ -156,6 +153,9 @@ public: void SetSuper(Expression *superClass) { superClass_ = superClass; + if (superClass_ != nullptr) { + superClass_->SetParent(this); + } } [[nodiscard]] bool IsGlobal() const noexcept diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index 62b0ebb1003ff02519fe98bdc74c1bd7df759be1..8e41ec34c7b174c3b10275162c65778f9417bb16 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -22,12 +22,12 @@ namespace panda::es2panda::ir { Identifier *ClassElement::Id() noexcept { - return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; + return key_ != nullptr && key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } const Identifier *ClassElement::Id() const noexcept { - return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; + return key_ != nullptr && key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } bool ClassElement::IsPrivateElement() const noexcept diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 9d97cafadaaca1b8a9b4419360f297fc280b21e9..12c6583b73f02fc4efe12432354d63408947ae52 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -17,15 +17,10 @@ #include "checker/ETSchecker.h" #include "checker/TSchecker.h" -#include "checker/types/ets/etsObjectType.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/base/decorator.h" -#include "ir/typeNode.h" -#include "ir/expression.h" -#include "ir/expressions/identifier.h" namespace panda::es2panda::ir { void ClassProperty::TransformChildren(const NodeTransformer &cb) @@ -136,12 +131,11 @@ checker::Type *ClassProperty::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ClassProperty *ClassProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_->Clone(allocator)->AsExpression(); - auto *const value = value_->Clone(allocator)->AsExpression(); - auto *const typeAnnotation = typeAnnotation_->Clone(allocator, this); + auto *const key = key_->Clone(allocator, nullptr)->AsExpression(); + auto *const value = value_->Clone(allocator, nullptr)->AsExpression(); + auto *const typeAnnotation = typeAnnotation_->Clone(allocator, nullptr); if (auto *const clone = allocator->New(key, value, typeAnnotation, flags_, allocator, isComputed_); clone != nullptr) { diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 25ac075f90cbaa9e1067f59b33793e39b4782f2b..0f2c7d5ba3e7209501f2321143cb631403433c6b 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -51,8 +51,7 @@ public: return isStatic ? PrivateFieldKind::STATIC_FIELD : PrivateFieldKind::FIELD; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index eed3b5f6db795245ea5de04beba6a767083be7d1..4ae382fa2522f2d26eb74ffc4cbcd88a0aa40244 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -65,10 +65,9 @@ checker::Type *Decorator::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsExpression() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/base/decorator.h b/ets2panda/ir/base/decorator.h index dfbcc9027c1a169d64f2a3ca4333b90588b76964..779e08c90c021fce01569291af01d97c444ff6bb 100644 --- a/ets2panda/ir/base/decorator.h +++ b/ets2panda/ir/base/decorator.h @@ -36,8 +36,7 @@ public: return expr_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index a5208db90f2428856a38f8611feab9b44c39c97d..bf4cb3a214e08eca54977902b3f6ad861ee613e0 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -71,7 +71,6 @@ checker::Type *MetaProperty::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MetaProperty *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(kind_); clone != nullptr) { diff --git a/ets2panda/ir/base/metaProperty.h b/ets2panda/ir/base/metaProperty.h index c5eb1bb8448c390cfcb2393bddb5107357585de5..369b6ba66bab9b54992b9b087cd70aa31899cafe 100644 --- a/ets2panda/ir/base/metaProperty.h +++ b/ets2panda/ir/base/metaProperty.h @@ -43,8 +43,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index 9ab31f5844ea2a82ebc8dc12763a240f4dac9829..3f6be2a26aa24d15fc45f03304c27c7b85c6ddbc 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -15,7 +15,6 @@ #include "methodDefinition.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" @@ -52,7 +51,7 @@ PrivateFieldKind MethodDefinition::ToPrivateFieldKind(bool const isStatic) const } } -void MethodDefinition::Iterate(const NodeTraverser &cb) const +void MethodDefinition::ResolveReferences(const NodeTraverser &cb) const { cb(key_); cb(value_); @@ -66,6 +65,22 @@ void MethodDefinition::Iterate(const NodeTraverser &cb) const } } +void MethodDefinition::Iterate(const NodeTraverser &cb) const +{ + cb(key_); + cb(value_); + + for (auto *it : overloads_) { + if (it->Parent() == this) { + cb(it); + } + } + + for (auto *it : decorators_) { + cb(it); + } +} + void MethodDefinition::TransformChildren(const NodeTransformer &cb) { key_ = cb(key_)->AsExpression(); @@ -192,11 +207,10 @@ checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MethodDefinition *MethodDefinition::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(kind_, key, value, flags_, allocator, isComputed_); clone != nullptr) { diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index d3a314df0bfbbeccde183a29cf17a35367026937..bf0f208af96c46172eb182b83fdf0641e3e97c42 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -45,6 +45,7 @@ public: kind_(kind), overloads_(allocator->Adapter()) { + ASSERT(key_ != nullptr && value_ != nullptr); } // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields @@ -65,16 +66,6 @@ public: return kind_ == MethodDefinitionKind::EXTENSION_METHOD; } - Expression const *Key() const - { - return key_; - } - - Expression const *Value() const - { - return value_; - } - [[nodiscard]] const OverloadsT &Overloads() const noexcept { return overloads_; @@ -104,12 +95,13 @@ public: const ScriptFunction *Function() const; PrivateFieldKind ToPrivateFieldKind(bool isStatic) const override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void ResolveReferences(const NodeTraverser &cb) const; + void Dump(ir::AstDumper *dumper) const override; void Dump(ir::SrcDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index c6811cba023796fca9a5ae456c424d75ddf66dcc..d70ba1108c4dd066706e7287d9a42585739a189e 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -31,11 +31,10 @@ Property::Property([[maybe_unused]] Tag const tag, Property const &other, Expres value_ = value; } -// NOLINTNEXTLINE(google-default-arguments) Property *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, key, value); clone != nullptr) { if (key != nullptr) { diff --git a/ets2panda/ir/base/property.h b/ets2panda/ir/base/property.h index d643644cfb1c6931e1955b05b4aeade0024680e3..ccfdde132f384de1ccd30baa191da01f4d877a79 100644 --- a/ets2panda/ir/base/property.h +++ b/ets2panda/ir/base/property.h @@ -102,8 +102,7 @@ public: return kind == PropertyKind::GET || kind == PropertyKind::SET; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent) override; bool ConvertibleToPatternProperty(); ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index b033e6749cc8fe68808da58153043f796ae91f6e..8c99eda9f0b1f4347f1d6dde08ffa71058e0cbd5 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -15,7 +15,6 @@ #include "scriptFunction.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" @@ -24,6 +23,27 @@ namespace panda::es2panda::ir { +ScriptFunction::ScriptFunction(FunctionSignature &&signature, AstNode *body, ScriptFunctionData &&data) + : AstNode(AstNodeType::SCRIPT_FUNCTION, data.flags), + irSignature_(std::move(signature)), + body_(body), + funcFlags_(data.funcFlags), + declare_(data.declare), + lang_(data.lang) +{ + for (auto *param : irSignature_.Params()) { + param->SetParent(this); + } + + if (auto *returnType = irSignature_.ReturnType(); returnType != nullptr) { + returnType->SetParent(this); + } + + if (auto *typeParams = irSignature_.TypeParams(); typeParams != nullptr) { + typeParams->SetParent(this); + } +} + std::size_t ScriptFunction::FormalParamsLength() const noexcept { std::size_t length = 0U; @@ -39,6 +59,12 @@ std::size_t ScriptFunction::FormalParamsLength() const noexcept return length; } +void ScriptFunction::SetIdent(Identifier *id) noexcept +{ + id_ = id; + id_->SetParent(this); +} + void ScriptFunction::TransformChildren(const NodeTransformer &cb) { if (id_ != nullptr) { @@ -61,6 +87,12 @@ void ScriptFunction::Iterate(const NodeTraverser &cb) const } } +void ScriptFunction::SetReturnTypeAnnotation(TypeNode *node) noexcept +{ + irSignature_.SetReturnType(node); + node->SetParent(this); +} + void ScriptFunction::Dump(ir::AstDumper *dumper) const { dumper->Add({{"type", "ScriptFunction"}, diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 36e35e5461e0e9b8b7cf6c4d8f4a4b28e538a428..3104009fe127181fd9030f18215c35510bdef928 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -36,31 +36,25 @@ class TypeNode; class ScriptFunction : public AstNode { public: + // Need to reduce the number of constructor parameters to pass OHOS CI code check + struct ScriptFunctionData { + ir::ScriptFunctionFlags funcFlags = ir::ScriptFunctionFlags::NONE; + ir::ModifierFlags flags = ir::ModifierFlags::NONE; + bool declare = false; + panda::es2panda::Language lang {Language::Id::ETS}; + }; + ScriptFunction() = delete; ~ScriptFunction() override = default; NO_COPY_SEMANTIC(ScriptFunction); NO_MOVE_SEMANTIC(ScriptFunction); - explicit ScriptFunction(FunctionSignature &&signature, AstNode *body, ir::ScriptFunctionFlags funcFlags, - bool declare, Language lang) - : AstNode(AstNodeType::SCRIPT_FUNCTION), - irSignature_(std::move(signature)), - body_(body), - funcFlags_(funcFlags), - declare_(declare), - lang_(lang) - { - } + explicit ScriptFunction(FunctionSignature &&signature, AstNode *body, ScriptFunctionData &&data); explicit ScriptFunction(FunctionSignature &&signature, AstNode *body, ir::ScriptFunctionFlags funcFlags, - ir::ModifierFlags flags, bool declare, Language lang) - : AstNode(AstNodeType::SCRIPT_FUNCTION, flags), - irSignature_(std::move(signature)), - body_(body), - funcFlags_(funcFlags), - declare_(declare), - lang_(lang) + bool declare, Language lang) + : ScriptFunction(std::move(signature), body, {funcFlags, {}, declare, lang}) { } @@ -129,10 +123,7 @@ public: return irSignature_.ReturnType(); } - void SetReturnTypeAnnotation(TypeNode *node) noexcept - { - irSignature_.SetReturnType(node); - } + void SetReturnTypeAnnotation(TypeNode *node) noexcept; [[nodiscard]] bool IsEntryPoint() const noexcept { @@ -254,10 +245,7 @@ public: return funcFlags_; } - void SetIdent(Identifier *id) noexcept - { - id_ = id; - } + void SetIdent(Identifier *id) noexcept; void SetSignature(checker::Signature *signature) noexcept { diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index f66d00367927fc317b84b8286791c4d5ac87997f..c9d519118ee99bf463612d87d32de69e77149e69 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -42,7 +42,6 @@ SpreadElement::SpreadElement([[maybe_unused]] Tag const tag, SpreadElement const } } -// NOLINTNEXTLINE(google-default-arguments) SpreadElement *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/base/spreadElement.h b/ets2panda/ir/base/spreadElement.h index 939f60c97555d0ea9f290adb29a3f10ebf7ee7cf..40c8b0dbe6cb8d1a1933c7cf388ab9ad8504798b 100644 --- a/ets2panda/ir/base/spreadElement.h +++ b/ets2panda/ir/base/spreadElement.h @@ -78,8 +78,7 @@ public: optional_ = optional; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToRest(bool isDeclaration, bool allowPattern = true); diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 8816ba413cc58502d302ef49f5cb7e747013707e..09a61236abb4273092028aaf38ca63b0df794dc4 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -58,7 +58,6 @@ checker::Type *TemplateElement::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TemplateElement *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(raw_, cooked_); clone != nullptr) { diff --git a/ets2panda/ir/base/templateElement.h b/ets2panda/ir/base/templateElement.h index 85154cdd14255dc18b8e3572d3d5ba44e9bac7aa..45f96e6202073b2f8e28b472abed0b7c5333bd0b 100644 --- a/ets2panda/ir/base/templateElement.h +++ b/ets2panda/ir/base/templateElement.h @@ -44,8 +44,7 @@ public: return cooked_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index c85adb93c74056577ed34accc8c954f0cd8097b4..a878eeb13a400fcb470413c7fdfa467b696f7e12 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -72,11 +72,10 @@ checker::Type *TSIndexSignature::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TSIndexSignature *TSIndexSignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const param = param_ != nullptr ? param_->Clone(allocator)->AsExpression() : nullptr; - auto *const typeAnnotation = typeAnnotation_->Clone(allocator); + auto *const param = param_ != nullptr ? param_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const typeAnnotation = typeAnnotation_->Clone(allocator, nullptr); if (auto *const clone = allocator->New(param, typeAnnotation, readonly_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/tsIndexSignature.h b/ets2panda/ir/base/tsIndexSignature.h index cff8d5fd215fb78e5d876c5e5f03a42397813caf..9b1b1c1d29b4f5af3c0c05dfa4703f775442be45 100644 --- a/ets2panda/ir/base/tsIndexSignature.h +++ b/ets2panda/ir/base/tsIndexSignature.h @@ -60,8 +60,7 @@ public: [[nodiscard]] TSIndexSignatureKind Kind() const noexcept; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index 4dd052b5d6dedbe87310d771da7c4df6aa0c02a2..49c0ac995c3382d5f0c7f5bb1a14933143734235 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -74,11 +74,10 @@ checker::Type *TSPropertySignature::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TSPropertySignature *TSPropertySignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; - auto *const typeAnnotation = TypeAnnotation()->Clone(allocator); + auto *const key = key_ != nullptr ? key_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const typeAnnotation = TypeAnnotation()->Clone(allocator, nullptr); if (auto *const clone = allocator->New(key, typeAnnotation, computed_, optional_, readonly_); clone != nullptr) { diff --git a/ets2panda/ir/base/tsPropertySignature.h b/ets2panda/ir/base/tsPropertySignature.h index c3a0f73429f7d6bb7dfa5d5fc4eee149dcee43e3..8171be38e4d6550beaaaceb22c50c3d0bd6e7266 100644 --- a/ets2panda/ir/base/tsPropertySignature.h +++ b/ets2panda/ir/base/tsPropertySignature.h @@ -63,8 +63,7 @@ public: return readonly_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index ad0eabe30565db726b6ce609ef4152c5157c70ad..787e96b37780c004b53ede450dd43332c772ee64 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -62,10 +62,9 @@ checker::Type *ETSClassLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index 592f3536fdab61e8af1a6f23c36c7db931883e49..d52bf955f66ec2cf059fc0eef2bb0f707fa553d8 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -38,8 +38,7 @@ public: explicit ETSClassLiteral(ir::TypeNode *const expr) : Expression(AstNodeType::ETS_CLASS_LITERAL), expr_(expr) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields friend class checker::ETSAnalyzer; diff --git a/ets2panda/ir/ets/etsFunctionType.cpp b/ets2panda/ir/ets/etsFunctionType.cpp index 0eec9494ff1873f520f4a08759076ad54634a057..7ff4c9b59d3c5df28aa383a330363bf6de21c7bd 100644 --- a/ets2panda/ir/ets/etsFunctionType.cpp +++ b/ets2panda/ir/ets/etsFunctionType.cpp @@ -97,20 +97,20 @@ checker::Type *ETSFunctionType::GetType(checker::ETSChecker *checker) return Check(checker); } -// NOLINTNEXTLINE(google-default-arguments) ETSFunctionType *ETSFunctionType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { ArenaVector paramsClone(allocator->Adapter()); for (auto *const param : signature_.Params()) { - paramsClone.emplace_back(param->Clone(allocator)->AsExpression()); + paramsClone.emplace_back(param->Clone(allocator, nullptr)->AsExpression()); } - auto *const typeParamsClone = signature_.TypeParams() != nullptr - ? signature_.TypeParams()->Clone(allocator)->AsTSTypeParameterDeclaration() - : nullptr; + auto *const typeParamsClone = + signature_.TypeParams() != nullptr + ? signature_.TypeParams()->Clone(allocator, nullptr)->AsTSTypeParameterDeclaration() + : nullptr; auto *const returnTypeClone = - signature_.ReturnType() != nullptr ? signature_.ReturnType()->Clone(allocator)->AsTypeNode() : nullptr; + signature_.ReturnType() != nullptr ? signature_.ReturnType()->Clone(allocator, nullptr)->AsTypeNode() : nullptr; if (auto *const clone = allocator->New( FunctionSignature(typeParamsClone, std::move(paramsClone), returnTypeClone), funcFlags_); @@ -123,6 +123,10 @@ ETSFunctionType *ETSFunctionType::Clone(ArenaAllocator *const allocator, AstNode returnTypeClone->SetParent(clone); } + for (auto *param : clone->Params()) { + param->SetParent(clone); + } + if (parent != nullptr) { clone->SetParent(parent); } diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index 42f7323db5f68c696d1a719df092521ba6937f1c..6dbe8554843321a68b413cf5a511567486fc5c3a 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -93,6 +93,11 @@ public: return (funcFlags_ & ir::ScriptFunctionFlags::THROWS) != 0; } + bool IsRethrowing() const + { + return (funcFlags_ & ir::ScriptFunctionFlags::RETHROWS) != 0; + } + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; @@ -109,8 +114,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSFunctionType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: varbinder::Scope *scope_ {}; diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index a492c7c3f23c6b867d27358dcac6bb5403e62d73..0ac08f618599788288766afba71ad35ff2b5ee44 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -75,18 +75,20 @@ bool ETSLaunchExpression::IsStaticCall() const return expr_->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); } -// NOLINTNEXTLINE(google-default-arguments) ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { expr->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index 5f41d342c81945a35e8e70c640bd38d2c7cb8000..eee51886e92688ef25ccd9806ffbc6c771844bd3 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -44,8 +44,7 @@ public: friend class checker::ETSAnalyzer; friend class compiler::ETSCompiler; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index 71277d93848ce75adca9d42bbcadc2042662cfce..4f3f013c77822086775335db46016930f41dce40 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -72,24 +72,28 @@ checker::Type *ETSNewArrayInstanceExpression::Check(checker::ETSChecker *checker return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSNewArrayInstanceExpression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const typeRef = typeReference_ != nullptr ? typeReference_->Clone(allocator) : nullptr; - auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator)->AsExpression() : nullptr; + auto *const typeRef = typeReference_ != nullptr ? typeReference_->Clone(allocator, nullptr) : nullptr; + auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator, nullptr)->AsExpression() : nullptr; - if (auto *const clone = allocator->New(allocator, typeRef, dimension); - clone != nullptr) { + if (auto *const clone = allocator->New(typeRef, dimension); clone != nullptr) { if (typeRef != nullptr) { typeRef->SetParent(clone); } + if (dimension != nullptr) { dimension->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->defaultConstructorSignature_ = defaultConstructorSignature_; + clone->SetRange(Range()); + return clone; } diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index e1f121eaee960d5a1ac0edbecfac12e2509e5c72..bf744f17b4aff4041a7be66d03503863ed32abd9 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -37,45 +37,57 @@ public: NO_COPY_SEMANTIC(ETSNewArrayInstanceExpression); NO_MOVE_SEMANTIC(ETSNewArrayInstanceExpression); - explicit ETSNewArrayInstanceExpression(ArenaAllocator *allocator, ir::TypeNode *const typeReference, - ir::Expression *const dimension) + explicit ETSNewArrayInstanceExpression(ir::TypeNode *const typeReference, ir::Expression *const dimension) : Expression(AstNodeType::ETS_NEW_ARRAY_INSTANCE_EXPRESSION), typeReference_(typeReference), - dimension_(dimension), - allocator_(allocator) + dimension_(dimension) { } - // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields - friend class checker::ETSAnalyzer; - friend class compiler::ETSCompiler; - ir::TypeNode *TypeReference() + [[nodiscard]] ir::TypeNode *TypeReference() noexcept { return typeReference_; } - ir::TypeNode const *TypeReference() const + [[nodiscard]] ir::TypeNode const *TypeReference() const noexcept { return typeReference_; } - ir::Expression *Dimension() + [[nodiscard]] ir::Expression *Dimension() noexcept { return dimension_; } - ir::Expression const *Dimension() const + [[nodiscard]] ir::Expression const *Dimension() const noexcept { return dimension_; } - void SetDimension(ir::Expression *dimension) + [[nodiscard]] checker::Signature *Signature() const noexcept + { + return defaultConstructorSignature_; + } + + [[nodiscard]] checker::Signature *Signature() noexcept + { + return defaultConstructorSignature_; + } + + void SetDimension(ir::Expression *dimension) noexcept { dimension_ = dimension; + if (dimension_ != nullptr) { + dimension_->SetParent(this); + } + } + + void SetSignature(checker::Signature *signature) noexcept + { + defaultConstructorSignature_ = signature; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -95,7 +107,6 @@ private: ir::TypeNode *typeReference_; ir::Expression *dimension_; checker::Signature *defaultConstructorSignature_ {}; - ArenaAllocator *allocator_; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index c85d7639ca48255dc4d9caa5bcc9e3cd9d1b88fd..0a6c95d2147eb240d1f4c446d425b6dcbf0ff55a 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -96,15 +96,15 @@ ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstance ArenaAllocator *const allocator) : Expression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_) { - typeReference_ = other.typeReference_->Clone(allocator, this)->AsExpression(); - classDef_ = other.classDef_->Clone(allocator, this)->AsClassDefinition(); + typeReference_ = + other.typeReference_ != nullptr ? other.typeReference_->Clone(allocator, this)->AsExpression() : nullptr; + classDef_ = other.classDef_ != nullptr ? other.classDef_->Clone(allocator, this)->AsClassDefinition() : nullptr; for (auto *const argument : other.arguments_) { arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } } -// NOLINTNEXTLINE(google-default-arguments) ETSNewClassInstanceExpression *ETSNewClassInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index 6cbef0d1232afe31ba19868368b88596ad34beda..4df829352a1597312b223aa52e0a7f1dcd1749e6 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -85,8 +85,7 @@ public: signature_ = signature; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 4b2bc1500d9ce02d0b8257bc60374f03ae65a900..e9de7f927bbeac14e04eb432f63ecd2d1d0d89a4 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -90,7 +90,6 @@ ETSNewMultiDimArrayInstanceExpression::ETSNewMultiDimArrayInstanceExpression( } } -// NOLINTNEXTLINE(google-default-arguments) ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { @@ -98,6 +97,8 @@ ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Cl if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h index 825aae727d29910e573c58d102a043e7587c9a61..2f284625dcd7be77a5786ef60d95da9afb9e3215 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h @@ -44,29 +44,26 @@ public: dimensions_(std::move(dimensions)) { } - // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields - friend class checker::ETSAnalyzer; - friend class compiler::ETSCompiler; explicit ETSNewMultiDimArrayInstanceExpression(ETSNewMultiDimArrayInstanceExpression const &other, ArenaAllocator *allocator); - ir::TypeNode *TypeReference() + [[nodiscard]] ir::TypeNode *TypeReference() noexcept { return typeReference_; } - ir::TypeNode const *TypeReference() const + [[nodiscard]] ir::TypeNode const *TypeReference() const noexcept { return typeReference_; } - ArenaVector &Dimensions() + [[nodiscard]] ArenaVector &Dimensions() noexcept { return dimensions_; } - ArenaVector const &Dimension() const + [[nodiscard]] ArenaVector const &Dimensions() const noexcept { return dimensions_; } @@ -81,9 +78,12 @@ public: return signature_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, - AstNode *parent = nullptr) override; + void SetSignature(checker::Signature *signature) noexcept + { + signature_ = signature; + } + + [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNullishTypes.cpp b/ets2panda/ir/ets/etsNullishTypes.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9a02fcdf21f17079e7e0e49e62a5f181e583b5d --- /dev/null +++ b/ets2panda/ir/ets/etsNullishTypes.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "etsNullishTypes.h" + +#include "checker/ETSchecker.h" +#include "ir/astDump.h" + +namespace panda::es2panda::ir { +void ETSUndefinedType::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} + +void ETSUndefinedType::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} + +void ETSUndefinedType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSUndefinedType"}}); +} + +void ETSUndefinedType::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("undefined"); +} + +void ETSUndefinedType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + UNREACHABLE(); +} + +checker::Type *ETSUndefinedType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + UNREACHABLE(); +} + +checker::Type *ETSUndefinedType::Check([[maybe_unused]] checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSUndefinedType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + SetTsType(checker->GlobalETSUndefinedType()); + return TsType(); +} + +void ETSNullType::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} + +void ETSNullType::Iterate([[maybe_unused]] const NodeTraverser &cb) const {} + +void ETSNullType::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "ETSNullType"}}); +} + +void ETSNullType::Dump(ir::SrcDumper *dumper) const +{ + dumper->Add("null"); +} + +void ETSNullType::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + UNREACHABLE(); +} + +checker::Type *ETSNullType::Check([[maybe_unused]] checker::TSChecker *checker) +{ + UNREACHABLE(); +} + +checker::Type *ETSNullType::Check([[maybe_unused]] checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ETSNullType::GetType([[maybe_unused]] checker::ETSChecker *checker) +{ + SetTsType(checker->GlobalETSNullType()); + return TsType(); +} + +} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNullishTypes.h b/ets2panda/ir/ets/etsNullishTypes.h new file mode 100644 index 0000000000000000000000000000000000000000..efbadd086c96e69d10b468233f413f972b963158 --- /dev/null +++ b/ets2panda/ir/ets/etsNullishTypes.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ES2PANDA_IR_ETS_NULLISH_TYPES_H +#define ES2PANDA_IR_ETS_NULLISH_TYPES_H + +#include "ir/typeNode.h" + +namespace panda::es2panda::ir { + +class ETSNullType : public TypeNode { +public: + explicit ETSNullType() : TypeNode(AstNodeType::ETS_NULL_TYPE) {} + + void TransformChildren(const NodeTransformer &cb) override; + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Dump(ir::SrcDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; + + void Accept(ASTVisitorT *v) override + { + v->Accept(this); + } +}; + +class ETSUndefinedType : public TypeNode { +public: + explicit ETSUndefinedType() : TypeNode(AstNodeType::ETS_UNDEFINED_TYPE) {} + + void TransformChildren(const NodeTransformer &cb) override; + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Dump(ir::SrcDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; + + void Accept(ASTVisitorT *v) override + { + v->Accept(this); + } +}; + +} // namespace panda::es2panda::ir + +#endif diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index 27a44e419c25a17abcac4bbef2d311b10f7f4661..1af22f1a87ff3067bed7179f8d19cc0361b942d5 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -64,10 +64,9 @@ checker::Type *ETSPackageDeclaration::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSPackageDeclaration *ETSPackageDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto const name = name_ != nullptr ? name_->Clone(allocator, this)->AsExpression() : nullptr; + auto const name = name_ != nullptr ? name_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(name); clone != nullptr) { if (name != nullptr) { name->SetParent(clone); diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 88d51f0c08ef9f2c1672532ca4b3abb1334fda04..98463a9102685ec3e2b08b86bd4b463fad11f98f 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -33,8 +33,7 @@ public: { } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index 7b808c79c3d5db489990c301f5855ed7d6747d6a..ec2682f77615ce514b8a606bf5f07822c635d310 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -32,6 +32,7 @@ ETSParameterExpression::ETSParameterExpression(AnnotatedExpression *const identO : Expression(AstNodeType::ETS_PARAMETER_EXPRESSION), initializer_(initializer) { ASSERT(identOrSpread != nullptr); + identOrSpread->SetParent(this); if (identOrSpread->IsIdentifier()) { ident_ = identOrSpread->AsIdentifier(); @@ -187,12 +188,12 @@ checker::Type *ETSParameterExpression::Check(checker::ETSChecker *const checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const identOrSpread = spread_ != nullptr ? spread_->Clone(allocator)->AsAnnotatedExpression() - : ident_->Clone(allocator)->AsAnnotatedExpression(); - auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator)->AsExpression() : nullptr; + auto *const identOrSpread = spread_ != nullptr ? spread_->Clone(allocator, nullptr)->AsAnnotatedExpression() + : ident_->Clone(allocator, nullptr)->AsAnnotatedExpression(); + auto *const initializer = + initializer_ != nullptr ? initializer_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(identOrSpread, initializer); clone != nullptr) { identOrSpread->SetParent(clone); diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index aedc3e7166a1c3079d162b5d2c8793cfc041ced6..ec6fde41a59b2dd9392ffa6f145442ba9419fbad 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -78,8 +78,7 @@ public: extraValue_ = value; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void TransformChildren(const NodeTransformer &cb) override; diff --git a/ets2panda/ir/ets/etsPrimitiveType.cpp b/ets2panda/ir/ets/etsPrimitiveType.cpp index bfc3562cfad72ea422ce2db83a378064d1a62ae3..be255ddd3abdd8d7de76490791dcce937da28ef5 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.cpp +++ b/ets2panda/ir/ets/etsPrimitiveType.cpp @@ -132,7 +132,6 @@ checker::Type *ETSPrimitiveType::GetType([[maybe_unused]] checker::ETSChecker *c } } -// NOLINTNEXTLINE(google-default-arguments) ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(type_); clone != nullptr) { @@ -140,6 +139,7 @@ ETSPrimitiveType *ETSPrimitiveType::Clone(ArenaAllocator *const allocator, AstNo clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/ets/etsPrimitiveType.h b/ets2panda/ir/ets/etsPrimitiveType.h index b2ad1451dfa0abbb2cc0729962d0a5fa69004057..2fb0d551728ddcd9b49d157b8c885ce960b89b19 100644 --- a/ets2panda/ir/ets/etsPrimitiveType.h +++ b/ets2panda/ir/ets/etsPrimitiveType.h @@ -46,8 +46,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSPrimitiveType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSPrimitiveType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: PrimitiveType type_; diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index 37026f4a624b1ec9c717e63a4a15b39a11ebd36d..873c13499fcb7fef5ff579cf848b6d0c4c55926f 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -75,10 +75,9 @@ checker::Type *ETSStructDeclaration::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ETSStructDeclaration *ETSStructDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const def = def_ != nullptr ? def_->Clone(allocator, this)->AsClassDefinition() : nullptr; + auto *const def = def_ != nullptr ? def_->Clone(allocator, nullptr)->AsClassDefinition() : nullptr; if (auto *const clone = allocator->New(def, allocator); clone != nullptr) { for (auto *const decorator : decorators_) { diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index b7d6176e72ec0af562f262aed793e09b8c883c5b..f16200a8dd5ebc55b09299d331c855666bbbd9c5 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -67,8 +67,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsTuple.cpp b/ets2panda/ir/ets/etsTuple.cpp index 929fce73a100541867a2a46ed767aaca7fcacac0..ea229c15ba6de4c18339744f826dfc19e60a37e0 100644 --- a/ets2panda/ir/ets/etsTuple.cpp +++ b/ets2panda/ir/ets/etsTuple.cpp @@ -78,64 +78,19 @@ checker::Type *ETSTuple::Check([[maybe_unused]] checker::ETSChecker *const check return GetType(checker); } -checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) -{ - if (TsType() != nullptr) { - return TsType(); - } - - ArenaVector typeList(checker->Allocator()->Adapter()); - - for (auto *const typeAnnotation : GetTupleTypeAnnotationsList()) { - auto *const checkedType = checker->GetTypeFromTypeAnnotation(typeAnnotation); - typeList.emplace_back(checkedType); - } - - if (HasSpreadType()) { - ASSERT(spreadType_->IsTSArrayType()); - auto *const arrayType = spreadType_->GetType(checker); - ASSERT(arrayType->IsETSArrayType()); - spreadType_->SetTsType(arrayType->AsETSArrayType()->ElementType()); - } - - auto *const spreadElementType = spreadType_ != nullptr ? spreadType_->TsType() : nullptr; - - auto *const tupleType = checker->Allocator()->New( - typeList, CalculateLUBForTuple(checker, typeList, spreadElementType), spreadElementType); - - SetTsType(tupleType); - return TsType(); -} - -static void SetNullUndefinedFlags(std::pair &containsNullOrUndefined, const checker::Type *const type) -{ - if (type->HasTypeFlag(checker::TypeFlag::NULLISH)) { - containsNullOrUndefined.first = true; - } - - if (type->HasTypeFlag(checker::TypeFlag::UNDEFINED)) { - containsNullOrUndefined.second = true; - } -} - checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker, - ArenaVector &typeList, checker::Type *const spreadType) + ArenaVector &typeList, checker::Type **spreadTypePtr) { + auto &spreadType = *spreadTypePtr; if (typeList.empty()) { return spreadType == nullptr ? checker->GlobalETSObjectType() : spreadType; } - std::pair containsNullOrUndefined = {false, false}; - - bool allElementsAreSame = - std::all_of(typeList.begin(), typeList.end(), - [&checker, &typeList, &containsNullOrUndefined](checker::Type *const element) { - SetNullUndefinedFlags(containsNullOrUndefined, element); - return checker->Relation()->IsIdenticalTo(typeList[0], element); - }); + bool allElementsAreSame = std::all_of(typeList.begin(), typeList.end(), [&checker, &typeList](auto *element) { + return checker->Relation()->IsIdenticalTo(typeList[0], element); + }); if (spreadType != nullptr) { - SetNullUndefinedFlags(containsNullOrUndefined, spreadType); allElementsAreSame = allElementsAreSame && checker->Relation()->IsIdenticalTo(typeList[0], spreadType); } @@ -147,41 +102,45 @@ checker::Type *ETSTuple::CalculateLUBForTuple(checker::ETSChecker *const checker if (allElementsAreSame) { return typeList[0]; } + // Other case - promote element types + // NOTE(vpukhov): #15570 normalization happens or not? + std::for_each(typeList.begin(), typeList.end(), [checker](auto &t) { t = checker->MaybePromotedBuiltinType(t); }); - auto getBoxedTypeOrType = [&checker](checker::Type *const type) { - auto *const boxedType = checker->PrimitiveTypeAsETSBuiltinType(type); - return boxedType == nullptr ? type : boxedType; - }; + auto ctypes = typeList; + if (spreadType != nullptr) { + spreadType = checker->MaybePromotedBuiltinType(spreadType); + ctypes.push_back(spreadType); + } + return checker->CreateETSUnionType(std::move(ctypes)); +} - checker::Type *lubType = getBoxedTypeOrType(typeList[0]); +checker::Type *ETSTuple::GetType(checker::ETSChecker *const checker) +{ + if (TsType() != nullptr) { + return TsType(); + } - for (std::size_t idx = 1; idx < typeList.size(); ++idx) { - if (typeList[idx]->IsETSTypeParameter()) { - lubType = typeList[idx]->AsETSTypeParameter()->GetConstraintType(); - continue; - } - lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(typeList[idx])); + ArenaVector typeList(checker->Allocator()->Adapter()); + + for (auto *const typeAnnotation : GetTupleTypeAnnotationsList()) { + auto *const checkedType = typeAnnotation->GetType(checker); + typeList.emplace_back(checkedType); } - if (spreadType != nullptr) { - if (spreadType->IsETSTypeParameter()) { - lubType = spreadType->AsETSTypeParameter()->GetConstraintType(); - } else { - lubType = checker->FindLeastUpperBound(lubType, getBoxedTypeOrType(spreadType)); - } + if (HasSpreadType()) { + ASSERT(spreadType_->IsTSArrayType()); + auto *const arrayType = spreadType_->GetType(checker); + ASSERT(arrayType->IsETSArrayType()); + spreadType_->SetTsType(arrayType->AsETSArrayType()->ElementType()); } - const auto nullishUndefinedFlags = - (containsNullOrUndefined.first ? checker::TypeFlag::NULLISH | checker::TypeFlag::NULL_TYPE - : checker::TypeFlag::NONE) | - (containsNullOrUndefined.second ? checker::TypeFlag::UNDEFINED : checker::TypeFlag::NONE); + auto *spreadElementType = spreadType_ != nullptr ? spreadType_->TsType() : nullptr; - if (nullishUndefinedFlags != checker::TypeFlag::NONE) { - lubType = checker->CreateNullishType(lubType, nullishUndefinedFlags, checker->Allocator(), checker->Relation(), - checker->GetGlobalTypesHolder()); - } + auto *const tupleType = checker->Allocator()->New( + typeList, CalculateLUBForTuple(checker, typeList, &spreadElementType), spreadElementType); - return lubType; + SetTsType(tupleType); + return TsType(); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsTuple.h b/ets2panda/ir/ets/etsTuple.h index 43379d92130bbf0729b773276bc80a71aa5b6f3c..fcca6a2d9975468dba77aa1dd092608d11175b67 100644 --- a/ets2panda/ir/ets/etsTuple.h +++ b/ets2panda/ir/ets/etsTuple.h @@ -76,14 +76,15 @@ public: checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::ETSChecker *checker) override; - static checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector &typeList, - checker::Type *spreadType); - void Accept(ASTVisitorT *v) override { v->Accept(this); } + // NOTE(vpukhov): hide in TypeCreation + static checker::Type *CalculateLUBForTuple(checker::ETSChecker *checker, ArenaVector &typeList, + checker::Type **spreadTypePtr); + private: ArenaVector typeAnnotationList_; TypeNode *spreadType_ {}; diff --git a/ets2panda/ir/ets/etsTypeReference.cpp b/ets2panda/ir/ets/etsTypeReference.cpp index b65b9a68d67e56a5f28b6f68eefde831004ba563..0247cbcd4ae0062c424a9b4ce4d400dc2cab63f0 100644 --- a/ets2panda/ir/ets/etsTypeReference.cpp +++ b/ets2panda/ir/ets/etsTypeReference.cpp @@ -90,27 +90,15 @@ checker::Type *ETSTypeReference::Check(checker::ETSChecker *checker) checker::Type *ETSTypeReference::GetType(checker::ETSChecker *checker) { - if (TsType() != nullptr) { - return TsType(); + if (TsType() == nullptr) { + SetTsType(part_->GetType(checker)); } - - checker::Type *type = part_->GetType(checker); - if (IsNullAssignable() || IsUndefinedAssignable()) { - auto nullishFlags = (IsNullAssignable() ? checker::TypeFlag::NULL_TYPE : checker::TypeFlag(0)) | - (IsUndefinedAssignable() ? checker::TypeFlag::UNDEFINED : checker::TypeFlag(0)); - - type = checker->CreateNullishType(type, nullishFlags, checker->Allocator(), checker->Relation(), - checker->GetGlobalTypesHolder()); - } - - SetTsType(type); - return type; + return TsType(); } -// NOLINTNEXTLINE(google-default-arguments) ETSTypeReference *ETSTypeReference::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const partClone = part_ != nullptr ? part_->Clone(allocator)->AsETSTypeReferencePart() : nullptr; + auto *const partClone = part_ != nullptr ? part_->Clone(allocator, nullptr)->AsETSTypeReferencePart() : nullptr; if (auto *const clone = allocator->New(partClone); clone != nullptr) { if (partClone != nullptr) { @@ -123,6 +111,7 @@ ETSTypeReference *ETSTypeReference::Clone(ArenaAllocator *const allocator, AstNo clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/ets/etsTypeReference.h b/ets2panda/ir/ets/etsTypeReference.h index d67d7f49ac4b51c2789cc6f603fe0248791bcace..dfcecf74bbe2f6483a52a11907108d84f483a634 100644 --- a/ets2panda/ir/ets/etsTypeReference.h +++ b/ets2panda/ir/ets/etsTypeReference.h @@ -53,8 +53,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSTypeReference *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSTypeReference *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: ir::ETSTypeReferencePart *part_; diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index 792e942e8ce8737c4f2060ac5b61480a38a2ef19..21cb3dbbf724b938c32d446aa4aae8d8fa7ab4db 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -110,13 +110,12 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) return checker->GetReferencedTypeFromBase(baseType, name_); } -// NOLINTNEXTLINE(google-default-arguments) ETSTypeReferencePart *ETSTypeReferencePart::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const nameClone = name_ != nullptr ? name_->Clone(allocator)->AsExpression() : nullptr; + auto *const nameClone = name_ != nullptr ? name_->Clone(allocator, nullptr)->AsExpression() : nullptr; auto *const typeParamsClone = - typeParams_ != nullptr ? typeParams_->Clone(allocator)->AsTSTypeParameterInstantiation() : nullptr; - auto *const prevClone = prev_ != nullptr ? prev_->Clone(allocator)->AsETSTypeReferencePart() : nullptr; + typeParams_ != nullptr ? typeParams_->Clone(allocator, nullptr)->AsTSTypeParameterInstantiation() : nullptr; + auto *const prevClone = prev_ != nullptr ? prev_->Clone(allocator, nullptr)->AsETSTypeReferencePart() : nullptr; if (auto *const clone = allocator->New(nameClone, typeParamsClone, prevClone); clone != nullptr) { if (nameClone != nullptr) { @@ -135,6 +134,7 @@ ETSTypeReferencePart *ETSTypeReferencePart::Clone(ArenaAllocator *const allocato clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/ets/etsTypeReferencePart.h b/ets2panda/ir/ets/etsTypeReferencePart.h index ab785f6f9cb59cb1e429c112b870040cc4eed2cb..4493d5630783c65c83b9beeabd25ed87f029fc4a 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.h +++ b/ets2panda/ir/ets/etsTypeReferencePart.h @@ -70,8 +70,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ETSTypeReferencePart *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSTypeReferencePart *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: ir::Expression *name_; diff --git a/ets2panda/ir/expression.h b/ets2panda/ir/expression.h index 3598a17231930b97582ca44e40fc6e1bfceabe02..98531abb80489f7b2d8460c5f189bd4021377af5 100644 --- a/ets2panda/ir/expression.h +++ b/ets2panda/ir/expression.h @@ -146,14 +146,9 @@ public: return optional_; } - void SetOptionalType(checker::Type *optionalType) + void ClearOptional() noexcept { - optionalType_ = optionalType; - } - - [[nodiscard]] const checker::Type *OptionalType() const noexcept - { - return optionalType_ != nullptr ? optionalType_ : TsType(); + optional_ = false; } protected: @@ -165,12 +160,10 @@ protected: MaybeOptionalExpression(MaybeOptionalExpression const &other) : Expression(static_cast(other)) { - optionalType_ = other.optionalType_; optional_ = other.optional_; } private: - checker::Type *optionalType_ {}; bool optional_; }; diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index 294f8f23ae7d769442d8c22f8aee5a36b4f8f615..653b922f980f3791b8163ece2f192c0e5caed914 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -53,7 +53,6 @@ ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression } } -// NOLINTNEXTLINE(google-default-arguments) ArrayExpression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index 34e834a7765ecab2b31dc9122a7088c3c31175fd..90dfd3e7aa86f1f043c075a51b04a5e7b8df96e0 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -119,8 +119,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] bool ConvertibleToArrayPattern(); [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 3e4f53a46ed8095ae3767a5f02a07fc3ba4cf673..63676ae3870886639563672e09568213469f246b 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -26,7 +26,6 @@ #include "ir/ets/etsTypeReference.h" #include "ir/ets/etsTypeReferencePart.h" #include "ir/expressions/identifier.h" -#include "ir/expressions/thisExpression.h" #include "ir/statements/variableDeclarator.h" namespace panda::es2panda::ir { @@ -86,7 +85,6 @@ ArrowFunctionExpression::ArrowFunctionExpression(ArrowFunctionExpression const & } } -// NOLINTNEXTLINE(google-default-arguments) ArrowFunctionExpression *ArrowFunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { @@ -105,11 +103,9 @@ ir::TypeNode *ArrowFunctionExpression::CreateReturnNodeFromType(checker::ETSChec Construct a synthetic Node with the correct ts_type_. */ ASSERT(returnType != nullptr); - ir::TypeNode *returnNode = nullptr; - auto *ident = checker->Allocator()->New(util::StringView(""), checker->Allocator()); - ir::ETSTypeReferencePart *part = checker->Allocator()->New(ident); - returnNode = checker->Allocator()->New(part); - part->SetParent(returnNode); + auto *ident = checker->AllocNode(util::StringView(""), checker->Allocator()); + auto *const part = checker->AllocNode(ident); + auto *returnNode = checker->AllocNode(part); returnNode->SetTsType(returnType); return returnNode; } @@ -135,14 +131,15 @@ ir::TypeNode *ArrowFunctionExpression::CreateTypeAnnotation(checker::ETSChecker */ returnNode = CreateReturnNodeFromType(checker, Function()->Signature()->ReturnType()); } else { - returnNode = Function()->ReturnTypeAnnotation(); + returnNode = Function()->ReturnTypeAnnotation()->Clone(checker->Allocator(), nullptr); + returnNode->SetTsType(Function()->ReturnTypeAnnotation()->TsType()); } - auto origParams = Function()->Params(); - auto signature = ir::FunctionSignature(nullptr, std::move(origParams), returnNode); - auto *funcType = - checker->Allocator()->New(std::move(signature), ir::ScriptFunctionFlags::NONE); - returnNode->SetParent(funcType); + ArenaVector params {checker->Allocator()->Adapter()}; + checker->CopyParams(Function()->Params(), params); + + auto signature = ir::FunctionSignature(nullptr, std::move(params), returnNode); + auto *funcType = checker->AllocNode(std::move(signature), ir::ScriptFunctionFlags::NONE); return funcType; } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index c1358a17226898a2ebb656b6b9d5b97251dc6fd5..79bc5b379f7f3fd5a3944986f3120bec6fb17408 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -83,8 +83,7 @@ public: propagateThis_ = true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index b4a288a8231c59ed255f5dee3f7c99dddd932a17..bebb7e2b2e3d161c9748e4e67da4da1fea8d2798 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -174,16 +174,17 @@ AssignmentExpression::AssignmentExpression([[maybe_unused]] Tag const tag, Assig } } -// NOLINTNEXTLINE(google-default-arguments) AssignmentExpression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, left, right); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index ae8eea339769b2ea8d20abf12824dda0f4acba5f..4077716d10ce6512b5da4aeacfcdf22b7081c2b6 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -112,8 +112,7 @@ public: return target_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] bool ConvertibleToAssignmentPattern(bool mustBePattern = true); diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 5048bd86c4c62fe1875b9616575222fb9a2b907f..bd59fee26901fa9f56dd73e0bbeedb54356cd44a 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -66,18 +66,20 @@ checker::Type *AwaitExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument); clone != nullptr) { if (argument != nullptr) { argument->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/awaitExpression.h b/ets2panda/ir/expressions/awaitExpression.h index ab1160ad375e45e0d074c89472bd8a47f42346fd..5754b7b9765130257aebd09c9ccf0dcaf1fa5a90 100644 --- a/ets2panda/ir/expressions/awaitExpression.h +++ b/ets2panda/ir/expressions/awaitExpression.h @@ -41,8 +41,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 69de43333363cff079a95bbcc10db776dccb20c6..dbbfc271d005740d48664b5e88f71fbc0efe2c40 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -75,25 +75,29 @@ checker::Type *BinaryExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BinaryExpression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(left, right, operator_); clone != nullptr) { if (operationType_ != nullptr) { clone->SetOperationType(operationType_); } + if (right != nullptr) { right->SetParent(clone); } + if (left != nullptr) { left->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index c4222f4db9ade7a1937bbe987dde6559c33f6caf..031b259e926720d993f8b8ac93ccced566776c93 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -106,19 +106,22 @@ public: void SetLeft(Expression *expr) noexcept { left_ = expr; + left_->SetParent(this); SetStart(left_->Start()); } void SetRight(Expression *expr) noexcept { right_ = expr; + right_->SetParent(this); SetEnd(right_->End()); } void SetResult(Expression *expr) noexcept { - left_ = expr; - SetStart(left_->Start()); + result_ = expr; + result_->SetParent(this); + SetStart(result_->Start()); } void SetOperator(lexer::TokenType operatorType) noexcept @@ -142,8 +145,7 @@ public: return operationType_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/blockExpression.cpp b/ets2panda/ir/expressions/blockExpression.cpp index 63b795532e49e71648cbe153cfa5cd339bb9dbb7..eaf53644da99ba43f555db33ff619b3159fb3e65 100644 --- a/ets2panda/ir/expressions/blockExpression.cpp +++ b/ets2panda/ir/expressions/blockExpression.cpp @@ -40,7 +40,6 @@ BlockExpression::BlockExpression([[maybe_unused]] Tag const tag, BlockExpression } } -// NOLINTNEXTLINE(google-default-arguments) BlockExpression *BlockExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/blockExpression.h b/ets2panda/ir/expressions/blockExpression.h index 6c6329ccd290328d853051c071a39ee337e183b7..1fd672f964f40a824f7e2e00336e0b4391d47240 100644 --- a/ets2panda/ir/expressions/blockExpression.h +++ b/ets2panda/ir/expressions/blockExpression.h @@ -41,8 +41,27 @@ public: return statements_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void AddStatements(ArenaVector const &statements) + { + std::copy_if(statements.begin(), statements.end(), std::back_inserter(statements_), + [this](ir::Statement *statement) { + if (statement != nullptr) { + statement->SetParent(this); + return true; + }; + return false; + }); + } + + void AddStatement(ir::Statement *statement) + { + if (statement != nullptr) { + statement->SetParent(this); + statements_.emplace_back(statement); + } + } + + [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index 577a4393b39525a3c6d9355de9ac034bf7bcfa73..f8645aae00f7dec463a2410f03c3b408ec38a806 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -65,6 +65,9 @@ void CallExpression::Dump(ir::SrcDumper *dumper) const { ASSERT(callee_); callee_->Dump(dumper); + if (IsOptional()) { + dumper->Add("?."); + } dumper->Add("("); for (auto arg : arguments_) { arg->Dump(dumper); @@ -108,27 +111,43 @@ CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *cons isTrailingBlockInNewLine_(other.isTrailingBlockInNewLine_) { callee_ = other.callee_->Clone(allocator, this)->AsExpression(); - typeParams_ = other.typeParams_->Clone(allocator, this); + typeParams_ = other.typeParams_ != nullptr ? other.typeParams_->Clone(allocator, this) : nullptr; for (auto *const argument : other.arguments_) { arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } - if (other.trailingBlock_ != nullptr) { - trailingBlock_ = other.trailingBlock_->Clone(allocator, this)->AsBlockStatement(); - } + trailingBlock_ = + other.trailingBlock_ != nullptr ? other.trailingBlock_->Clone(allocator, this)->AsBlockStatement() : nullptr; } -// NOLINTNEXTLINE(google-default-arguments) CallExpression *CallExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } + +void CallExpression::SetTypeParams(TSTypeParameterInstantiation *const typeParams) noexcept +{ + typeParams_ = typeParams; + if (typeParams_ != nullptr) { + typeParams_->SetParent(this); + } +} + +void CallExpression::SetTrailingBlock(ir::BlockStatement *const block) noexcept +{ + trailingBlock_ = block; + if (trailingBlock_ != nullptr) { + trailingBlock_->SetParent(this); + } +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index cd2e29cb97e968884b92241c1539e0b85ea7ca58..39b59c1ffe829de3f7844510b164d3a8da80d8a9 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -74,6 +74,7 @@ public: void SetCallee(Expression *callee) noexcept { callee_ = callee; + callee_->SetParent(this); } [[nodiscard]] const TSTypeParameterInstantiation *TypeParams() const noexcept @@ -116,10 +117,7 @@ public: signature_ = signature; } - void SetTypeParams(TSTypeParameterInstantiation *const typeParams) noexcept - { - typeParams_ = typeParams; - } + void SetTypeParams(TSTypeParameterInstantiation *typeParams) noexcept; [[nodiscard]] checker::Type *UncheckedType() const noexcept { @@ -131,10 +129,7 @@ public: uncheckedType_ = type; } - void SetTrailingBlock(ir::BlockStatement *const block) noexcept - { - trailingBlock_ = block; - } + void SetTrailingBlock(ir::BlockStatement *const block) noexcept; [[nodiscard]] ir::BlockStatement *TrailingBlock() const noexcept { @@ -151,8 +146,7 @@ public: return isTrailingBlockInNewLine_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index 7513d034fe0a30e3114d33369b798cd9caa48ef4..6959122c5a10bae644805b13f464cf16f857cbc6 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -40,7 +40,9 @@ void ChainExpression::Dump(ir::AstDumper *dumper) const void ChainExpression::Dump(ir::SrcDumper *dumper) const { - dumper->Add("ChainExpression"); + dumper->Add("("); // affects precedence + expression_->Dump(dumper); + dumper->Add(")"); } void ChainExpression::Compile(compiler::PandaGen *pg) const @@ -76,10 +78,9 @@ checker::Type *ChainExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ChainExpression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expression = expression_ != nullptr ? expression_->Clone(allocator)->AsExpression() : nullptr; + auto *const expression = expression_ != nullptr ? expression_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expression); clone != nullptr) { if (expression != nullptr) { diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 9c124c9c91ce4a2a818f8823c74efb209a624c42..2d83a525f7f489dc02af82f4866937b5c4cf3383 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -45,8 +45,12 @@ public: return expression_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + Expression *GetExpression() noexcept + { + return expression_; + } + + [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index 6caf00999f2954395085a8dabebfe401ab4859b4..7d8e14ddff37d0e6acd3ea057ba32aea108a1330 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -62,10 +62,9 @@ checker::Type *ClassExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const def = def_ != nullptr ? def_->Clone(allocator)->AsClassDefinition() : nullptr; + auto *const def = def_ != nullptr ? def_->Clone(allocator, nullptr)->AsClassDefinition() : nullptr; if (auto *const clone = allocator->New(def); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/classExpression.h b/ets2panda/ir/expressions/classExpression.h index 3277ec23ae89f68e4ca2ee43640cc600fc100ab3..2073d0690d5b9dc859f2c69d0b958c4423b58c70 100644 --- a/ets2panda/ir/expressions/classExpression.h +++ b/ets2panda/ir/expressions/classExpression.h @@ -36,8 +36,7 @@ public: return def_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index c75255d97188df4c7fbe4530b8f751ac084ef92d..839f243ca187870718d816cc0345840383943955 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -82,26 +82,30 @@ checker::Type *ConditionalExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ConditionalExpression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const test = test_ != nullptr ? test_->Clone(allocator)->AsExpression() : nullptr; - auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator)->AsExpression() : nullptr; - auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator)->AsExpression() : nullptr; + auto *const test = test_ != nullptr ? test_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(test, consequent, alternate); clone != nullptr) { if (test != nullptr) { test->SetParent(clone); } + if (consequent != nullptr) { consequent->SetParent(clone); } + if (alternate != nullptr) { alternate->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/conditionalExpression.h b/ets2panda/ir/expressions/conditionalExpression.h index f7e3bb822a3bf31d1ef8985ee8921e0fe79b148c..362715574dfd0d997d58d1596bc6b75b6b9fd07f 100644 --- a/ets2panda/ir/expressions/conditionalExpression.h +++ b/ets2panda/ir/expressions/conditionalExpression.h @@ -51,23 +51,35 @@ public: return test_; } + void SetTest(Expression *expr) noexcept + { + test_ = expr; + test_->SetParent(this); + } + [[nodiscard]] const Expression *Consequent() const noexcept { return consequent_; } + void SetConsequent(Expression *expr) noexcept + { + consequent_ = expr; + consequent_->SetParent(this); + } + [[nodiscard]] const Expression *Alternate() const noexcept { return alternate_; } - void SetTest(Expression *const test) noexcept + void SetAlternate(Expression *expr) noexcept { - test_ = test; + alternate_ = expr; + alternate_->SetParent(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 243a94df429a4bdb343ce2627d78015975ed0efc..d677d21281122a8ebc34a58fd498a274065065d0 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -62,10 +62,9 @@ checker::Type *FunctionExpression::Check([[maybe_unused]] checker::ETSChecker *c return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) FunctionExpression *FunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const func = func_->Clone(allocator)->AsScriptFunction(); + auto *const func = func_->Clone(allocator, nullptr)->AsScriptFunction(); if (auto *const clone = allocator->New(func); clone != nullptr) { func->SetParent(clone); diff --git a/ets2panda/ir/expressions/functionExpression.h b/ets2panda/ir/expressions/functionExpression.h index ae284499ced5dd641e6d70974b0d5e6f3d6b2e09..ce81316c51dfbc190eaecc9ec860bef8fe2ab8a7 100644 --- a/ets2panda/ir/expressions/functionExpression.h +++ b/ets2panda/ir/expressions/functionExpression.h @@ -58,8 +58,7 @@ public: return exprName_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index 03d77fb78166ad73d985284bf04b022e10861904..7376be7a24970e69acaf4d9c1a0ead4c3e2c754d 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -15,7 +15,6 @@ #include "identifier.h" -#include "varbinder/scope.h" #include "checker/ETSchecker.h" #include "checker/TSchecker.h" #include "compiler/core/pandagen.h" @@ -36,13 +35,14 @@ Identifier::Identifier([[maybe_unused]] Tag const tag, Identifier const &other, } } -// NOLINTNEXTLINE(google-default-arguments) Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index b91b01311f60a87343d224ad40c97d0e67ae2560..48196b964b056cc3da37e992cd51cfcc14a9c40c 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -190,8 +190,7 @@ public: decorators_ = std::move(decorators); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent) override; bool CanHaveDecorator([[maybe_unused]] bool inTs) const override { diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index 21a048c903dcaf08dab58a2b38a3546ee291101f..37a2df2530b2bb7a183045341cb46a8ca2530738 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -61,10 +61,9 @@ checker::Type *ImportExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ImportExpression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const source = source_ != nullptr ? source_->Clone(allocator)->AsExpression() : nullptr; + auto *const source = source_ != nullptr ? source_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(source); clone != nullptr) { if (source != nullptr) { diff --git a/ets2panda/ir/expressions/importExpression.h b/ets2panda/ir/expressions/importExpression.h index 4ac17ab18829b21685e1b5da20902fe239257cde..bb3a5fab15804ab1701224e7ec8e1851345483e5 100644 --- a/ets2panda/ir/expressions/importExpression.h +++ b/ets2panda/ir/expressions/importExpression.h @@ -34,8 +34,7 @@ public: return source_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index 9b72a6a358ad482b3a68aafd4fc71e28f4862a51..2dd72386fb3890041901a4c4d24ddd5cd5360dbc 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -56,13 +56,14 @@ checker::Type *BigIntLiteral::Check([[maybe_unused]] checker::ETSChecker *checke return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BigIntLiteral *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(src_); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index 6ac3d773856d79e9b3c2506673822667a22206ef..217e99057d3d88ff02f0cd45548ad19fe3645289 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -35,8 +35,7 @@ public: return src_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index 40bfa7bc655ee69bfa3c3dfc49ae8096f6ca392d..d6c73467be6377dd445bf9288ecf6296891d95a9 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -56,13 +56,13 @@ checker::Type *BooleanLiteral::Check([[maybe_unused]] checker::ETSChecker *check return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) BooleanLiteral *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(boolean_); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.h b/ets2panda/ir/expressions/literals/booleanLiteral.h index 88f62c6bf7280a0a8810fb478c66b0eaf201f8c5..f3ede215ba13fda9f54b48bf3ab4c0fa6e15b6ec 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.h +++ b/ets2panda/ir/expressions/literals/booleanLiteral.h @@ -34,8 +34,7 @@ public: return boolean_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index ce4be05ffc2477b40d3f8b1285826beb78cb5d3c..6ae2efc53f575c00ae98bd1c470a64f4386820fc 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -59,13 +59,14 @@ checker::Type *CharLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) CharLiteral *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(char_); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index 629e1a0d036151a3cbda6cc6a2bb4a19a3733274..003e922b4a9baf73c6b17cb59f788063c57f0d16 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -40,8 +40,7 @@ public: return char_ == other.char_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index 74c0e578162e27db70a51af734be3e39f602404a..6c45263aba6f17e08e4e3c66675ef4be53fadb15 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -55,13 +55,13 @@ checker::Type *NullLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) NullLiteral *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/nullLiteral.h b/ets2panda/ir/expressions/literals/nullLiteral.h index 4fb46bb414389a8f35e34285f693b6f90e81dd47..40a5f7b299ff8f582af5cf1221c89ef0aa04fdac 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.h +++ b/ets2panda/ir/expressions/literals/nullLiteral.h @@ -28,8 +28,7 @@ public: explicit NullLiteral() : Literal(AstNodeType::NULL_LITERAL) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index dc7e40501b5050e86919f7ca6ca722669a150878..3a832b8da05f2fff804af58e58c6d89b113001dd 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -74,13 +74,13 @@ checker::Type *NumberLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) NumberLiteral *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(number_); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/numberLiteral.h b/ets2panda/ir/expressions/literals/numberLiteral.h index 0abcbbce6ddbe60216a9803378b4413654f47078..7a4412d2f39fa6844770ff8e2785f87cbe80a1e1 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.h +++ b/ets2panda/ir/expressions/literals/numberLiteral.h @@ -49,8 +49,7 @@ public: [[nodiscard]] bool HasFloatingPoint() const; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index e14f0fad2da61127d333ca7580bc1f299dae8bc2..c05a8ede16ab4120d9d44f93fb657bc4012fe19e 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -57,13 +57,13 @@ checker::Type *RegExpLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) RegExpLiteral *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(pattern_, flags_, flagsStr_); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.h b/ets2panda/ir/expressions/literals/regExpLiteral.h index 9666670fe75038b2d2f231e7ba3add4555716a7f..9e21afa71f3448a5347108e721de953b45f344d8 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.h +++ b/ets2panda/ir/expressions/literals/regExpLiteral.h @@ -44,8 +44,7 @@ public: return flags_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index 11bc091825b5792eea11813beff594fc8b514802..8fb5ab112eabebf7186126b0db9ed64905153f76 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -87,13 +87,13 @@ checker::Type *StringLiteral::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) StringLiteral *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(str_); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index 081eed374fde1f4fce86bef53f75795b3a9095b7..3183fd6cd3d76fed67ff93a7dc9a7570f9f8b0d1 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -41,8 +41,7 @@ public: return str_ == other.str_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/undefinedLiteral.cpp b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp index 5ba4fd860aa2e4a92cb9ba2447fd0993fdb0181f..3195df4ce886fe8e93cd4a6098ec2ca0c384915f 100644 --- a/ets2panda/ir/expressions/literals/undefinedLiteral.cpp +++ b/ets2panda/ir/expressions/literals/undefinedLiteral.cpp @@ -63,6 +63,7 @@ UndefinedLiteral *UndefinedLiteral::Clone(ArenaAllocator *allocator, AstNode *pa if (parent != nullptr) { clone->SetParent(parent); } + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/literals/undefinedLiteral.h b/ets2panda/ir/expressions/literals/undefinedLiteral.h index 9c714c32923db984b15b16d00ad2fc6283455db8..991749c7f905afe4d5eaf6660f487d8338dfe98b 100644 --- a/ets2panda/ir/expressions/literals/undefinedLiteral.h +++ b/ets2panda/ir/expressions/literals/undefinedLiteral.h @@ -21,6 +21,11 @@ namespace panda::es2panda::ir { class UndefinedLiteral : public Literal { public: + ~UndefinedLiteral() override = default; + + NO_COPY_SEMANTIC(UndefinedLiteral); + NO_MOVE_SEMANTIC(UndefinedLiteral); + explicit UndefinedLiteral() : Literal(AstNodeType::UNDEFINED_LITERAL) {} [[nodiscard]] UndefinedLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index ae0ec9e0bf9cc132690194d38d98aaae415f7454..d58394461d5f8cd7618106803a915f84892dbf71 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -24,18 +24,11 @@ namespace panda::es2panda::ir { MemberExpression::MemberExpression([[maybe_unused]] Tag const tag, MemberExpression const &other, - Expression *const object, Expression *const property) + ArenaAllocator *allocator) : MemberExpression(other) { - object_ = object; - if (object_ != nullptr) { - object_->SetParent(this); - } - - property_ = property; - if (property_ != nullptr) { - property_->SetParent(this); - } + object_ = other.object_ != nullptr ? other.object_->Clone(allocator, this)->AsExpression() : nullptr; + property_ = other.property_ != nullptr ? other.property_->Clone(allocator, this)->AsExpression() : nullptr; } bool MemberExpression::IsPrivateReference() const noexcept @@ -190,10 +183,10 @@ std::pair MemberExpression::Resolve } } -checker::Type *MemberExpression::CheckUnionMember(checker::ETSChecker *checker, checker::Type *baseType) +checker::Type *MemberExpression::TraverseUnionMember(checker::ETSChecker *checker, checker::ETSUnionType *unionType, + checker::Type *commonPropType) + { - auto *const unionType = baseType->AsETSUnionType(); - checker::Type *commonPropType = nullptr; auto const addPropType = [this, checker, &commonPropType](checker::Type *memberType) { if (commonPropType != nullptr && commonPropType != memberType) { checker->ThrowTypeError("Member type must be the same for all union objects.", Start()); @@ -205,26 +198,30 @@ checker::Type *MemberExpression::CheckUnionMember(checker::ETSChecker *checker, if (apparent->IsETSObjectType()) { SetObjectType(apparent->AsETSObjectType()); addPropType(ResolveObjectMember(checker).first); - } else if (apparent->IsETSEnumType() || baseType->IsETSStringEnumType()) { + } else if (apparent->IsETSEnumType() || apparent->IsETSStringEnumType()) { addPropType(ResolveEnumMember(checker, apparent).first); } else { - UNREACHABLE(); + checker->ThrowTypeError({"Type ", unionType, " is illegal in union member expression."}, Start()); } } - SetObjectType(unionType->GetLeastUpperBoundType()->AsETSObjectType()); + return commonPropType; +} + +checker::Type *MemberExpression::CheckUnionMember(checker::ETSChecker *checker, checker::Type *baseType) +{ + auto *const unionType = baseType->AsETSUnionType(); + auto *const commonPropType = TraverseUnionMember(checker, unionType, nullptr); + SetObjectType(checker->GlobalETSObjectType()); return commonPropType; } checker::Type *MemberExpression::AdjustType(checker::ETSChecker *checker, checker::Type *type) { - SetOptionalType(type); - if (PropVar() != nullptr) { + auto *const objType = checker->GetApparentType(Object()->TsType()); + if (PropVar() != nullptr) { // access erased property type uncheckedType_ = checker->GuaranteedTypeForUncheckedPropertyAccess(PropVar()); - } - if (IsOptional() && checker->MayHaveNulllikeValue(Object()->TsType())) { - checker->Relation()->SetNode(this); - type = checker->CreateOptionalResultType(type); - checker->Relation()->SetNode(nullptr); + } else if (IsComputed() && objType->IsETSArrayType()) { // access erased array or tuple type + uncheckedType_ = checker->GuaranteedTypeForUncheckedCast(objType->AsETSArrayType()->ElementType(), type); } SetTsType(type); return TsType(); @@ -337,15 +334,6 @@ checker::Type *MemberExpression::CheckTupleAccessMethod(checker::ETSChecker *che // LUB was calculated by casting const checker::CastingContext cast(checker->Relation(), this, baseType->AsETSArrayType()->ElementType(), tupleTypeAtIdx, Start(), {"Tuple type couldn't be converted "}); - - // NOTE(mmartin): this can be replaced with the general type mapper, once implemented - if ((GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U) { - SetTupleConvertedType(checker->PrimitiveTypeAsETSBuiltinType(tupleTypeAtIdx)); - } - - if (tupleTypeAtIdx->IsETSObjectType() && baseType->AsETSArrayType()->ElementType()->IsETSObjectType()) { - SetTupleConvertedType(tupleTypeAtIdx); - } } return tupleTypeAtIdx; @@ -394,24 +382,14 @@ checker::Type *MemberExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) MemberExpression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const object = object_ != nullptr ? object_->Clone(allocator)->AsExpression() : nullptr; - auto *const property = property_ != nullptr ? property_->Clone(allocator)->AsExpression() : nullptr; - - if (auto *const clone = - allocator->New(object, property, kind_, computed_, MaybeOptionalExpression::IsOptional()); - clone != nullptr) { - if (object != nullptr) { - object->SetParent(clone); - } - if (property != nullptr) { - property->SetParent(clone); - } + if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index b59a73b4097f5ae6b818081e7af80ca1c5098045..6b37fbdfed735c69eb46cf0c0e2d8c5f6babc9e2 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -69,7 +69,7 @@ public: { } - explicit MemberExpression(Tag tag, MemberExpression const &other, Expression *object, Expression *property); + explicit MemberExpression(Tag tag, MemberExpression const &other, ArenaAllocator *allocator); // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields friend class compiler::JSCompiler; @@ -85,6 +85,12 @@ public: return object_; } + void SetObject(Expression *object) noexcept + { + object_ = object; + object_->SetParent(this); + } + [[nodiscard]] Expression *Property() noexcept { return property_; @@ -160,20 +166,9 @@ public: return uncheckedType_; } - checker::Type *GetTupleConvertedType() const noexcept - { - return tupleConvertedType_; - } - - void SetTupleConvertedType(checker::Type *convType) noexcept - { - tupleConvertedType_ = convType; - } - [[nodiscard]] bool IsPrivateReference() const noexcept; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -200,6 +195,7 @@ protected: ignoreBox_ = other.ignoreBox_; propVar_ = other.propVar_; // Note! Probably, we need to do 'Instantiate(...)' but we haven't access to 'Relation()' here... + uncheckedType_ = other.uncheckedType_; objType_ = other.objType_; } @@ -211,6 +207,8 @@ private: checker::Type *AdjustType(checker::ETSChecker *checker, checker::Type *type); checker::Type *CheckComputed(checker::ETSChecker *checker, checker::Type *baseType); checker::Type *CheckUnionMember(checker::ETSChecker *checker, checker::Type *baseType); + checker::Type *TraverseUnionMember(checker::ETSChecker *checker, checker::ETSUnionType *unionType, + checker::Type *commonPropType); void CheckArrayIndexValue(checker::ETSChecker *checker) const; checker::Type *CheckIndexAccessMethod(checker::ETSChecker *checker); @@ -226,7 +224,6 @@ private: checker::Type *uncheckedType_ {}; varbinder::LocalVariable *propVar_ {}; checker::ETSObjectType *objType_ {}; - checker::Type *tupleConvertedType_ {}; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index f56cdeb805147dc9c04dea64b87a01bb9811a501..8fb67ccc9fb8b484177c50868f8f12657e4aaa67 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -36,7 +36,6 @@ NewExpression::NewExpression([[maybe_unused]] Tag const tag, NewExpression const } } -// NOLINTNEXTLINE(google-default-arguments) NewExpression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/newExpression.h b/ets2panda/ir/expressions/newExpression.h index a1d974cd3fee0d1a0cf847f28f432304e68b5677..883e310a292a25c1e01439089b852581484b2520 100644 --- a/ets2panda/ir/expressions/newExpression.h +++ b/ets2panda/ir/expressions/newExpression.h @@ -53,8 +53,7 @@ public: return arguments_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index 6ebf574910a112e74a06bc44f39cc501ccf5d8c0..4ba78c48b3c5ea0b3f2afae22badf44943d95371 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -65,7 +65,6 @@ ObjectExpression::ObjectExpression([[maybe_unused]] Tag const tag, ObjectExpress } } -// NOLINTNEXTLINE(google-default-arguments) ObjectExpression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index 0beef0b780c051665b6f3c5622a7d42f1207772e..758a46c1613b7c809d39ac83798dad6f0a3efd00 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -96,8 +96,7 @@ public: return true; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; [[nodiscard]] ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToObjectPattern(); diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index 0ab3d1f33203eefd29e3f44e8ed5442c0d3860c3..abbfdd6774d751c50053adf9386671e3a7c31a7b 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -55,7 +55,6 @@ checker::Type *OmittedExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) OmittedExpression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/omittedExpression.h b/ets2panda/ir/expressions/omittedExpression.h index 4f1f340b78dfb90e6b0069d7a7b7ece85daf6c68..b29553d7c48099536533db51ccf9aa58696f7414 100644 --- a/ets2panda/ir/expressions/omittedExpression.h +++ b/ets2panda/ir/expressions/omittedExpression.h @@ -30,8 +30,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index 3830204255e2be254704e1b1fe96b17c82716c14..d4f37ffaef3de9a5bd586c75dcfea6d72c8be935 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -32,7 +32,6 @@ SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceE } } -// NOLINTNEXTLINE(google-default-arguments) SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/sequenceExpression.h b/ets2panda/ir/expressions/sequenceExpression.h index 98c53be093291a81d397b3d45e3b209a0c983248..4c46022aad2d2a65e6ebf0d5da972434c1c1e54e 100644 --- a/ets2panda/ir/expressions/sequenceExpression.h +++ b/ets2panda/ir/expressions/sequenceExpression.h @@ -47,8 +47,7 @@ public: return sequence_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 02e8244316ccb7c986413dbf8c83ae0aaa67a39e..8707b2b35ef2d32a2f3fc1a2ddaa2edc2cefdf83 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -57,7 +57,6 @@ checker::Type *SuperExpression::Check([[maybe_unused]] checker::ETSChecker *chec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) SuperExpression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/superExpression.h b/ets2panda/ir/expressions/superExpression.h index 29d12a994de0bed32b421f17ac355291e97b3b7e..a3d33a1f187cec7bf7fafa05845850390c612b94 100644 --- a/ets2panda/ir/expressions/superExpression.h +++ b/ets2panda/ir/expressions/superExpression.h @@ -28,8 +28,7 @@ public: explicit SuperExpression() : Expression(AstNodeType::SUPER_EXPRESSION) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 238deecd3736e289f7ab88d65ef9623d3d23ec5c..bd0bce7063074c909906e8c496b07c7733fc3b3b 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -81,12 +81,11 @@ checker::Type *TaggedTemplateExpression::Check([[maybe_unused]] checker::ETSChec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) TaggedTemplateExpression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const tag = tag_ != nullptr ? tag_->Clone(allocator)->AsExpression() : nullptr; - auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator) : nullptr; - auto *const typeParams = typeParams_ != nullptr ? typeParams_->Clone(allocator) : nullptr; + auto *const tag = tag_ != nullptr ? tag_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator, nullptr) : nullptr; + auto *const typeParams = typeParams_ != nullptr ? typeParams_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(tag, quasi, typeParams); clone != nullptr) { if (tag != nullptr) { diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.h b/ets2panda/ir/expressions/taggedTemplateExpression.h index d8853db8a91e549b4363ff92411fef3cb8398b36..2f70a9451a0a351e1916012e1f636f10c792d9ef 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.h +++ b/ets2panda/ir/expressions/taggedTemplateExpression.h @@ -50,8 +50,7 @@ public: return typeParams_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 732c96706b0a4377f457ba7407123afc62fb755e..30e37189f82c37e0b08ff1c5cd815d7133d81483 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -39,7 +39,6 @@ TemplateLiteral::TemplateLiteral([[maybe_unused]] Tag const tag, TemplateLiteral } } -// NOLINTNEXTLINE(google-default-arguments) TemplateLiteral *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { diff --git a/ets2panda/ir/expressions/templateLiteral.h b/ets2panda/ir/expressions/templateLiteral.h index 046ea69c4f13e5e228751330bf8f09d6872b2433..0b7b58711633734476225f6c6c16da164469c7af 100644 --- a/ets2panda/ir/expressions/templateLiteral.h +++ b/ets2panda/ir/expressions/templateLiteral.h @@ -48,8 +48,7 @@ public: return expressions_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 9598cea01a9637091955cd6b91a2cb479a84da51..7ab66d905ce236004c1411cd436afb457bd92365 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -63,7 +63,6 @@ checker::Type *ThisExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) ThisExpression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { diff --git a/ets2panda/ir/expressions/thisExpression.h b/ets2panda/ir/expressions/thisExpression.h index 51ab0411293e170091a9ea594be62454044870ef..c1db0af614090524188647b8708224117ca62e87 100644 --- a/ets2panda/ir/expressions/thisExpression.h +++ b/ets2panda/ir/expressions/thisExpression.h @@ -28,8 +28,7 @@ public: explicit ThisExpression() : Expression(AstNodeType::THIS_EXPRESSION) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 835456d9c4d10eba065554631f9af6119032b3a4..575990650740d907331df70ce4f9bb11883dc1f2 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -15,19 +15,12 @@ #include "unaryExpression.h" -#include "varbinder/variable.h" -#include "checker/types/typeFlag.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" #include "checker/ETSchecker.h" #include "ir/astDump.h" #include "ir/srcDump.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/bigIntLiteral.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/memberExpression.h" namespace panda::es2panda::ir { void UnaryExpression::TransformChildren(const NodeTransformer &cb) @@ -71,18 +64,20 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) UnaryExpression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_); clone != nullptr) { if (argument != nullptr) { argument->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index bbb261d3a0582bdadd7493c5b0a8c0191c970893..af060bca824a5f0fe3443e10eeb8e9212d99f39a 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -58,8 +58,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index 5453e7543cf9303ea6550a828cedc953f6978fcd..3e498d2bff7e18fef98be4cb21a1afb447287e22 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -78,18 +78,20 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) UpdateExpression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_, prefix_); clone != nullptr) { if (argument != nullptr) { argument->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRange(Range()); return clone; } diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 312a73df3306da2da2f1e1a7ae21f1c753dac93c..51539cccf5f8fbb3df53464a7c5e4695c5cafaa0 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -62,8 +62,7 @@ public: return prefix_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 36ce163da7007580178c8b8e8f8caf8c804930a2..3c8400649d31a0dc6430f52ed4f900d150330cee 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -67,10 +67,9 @@ checker::Type *YieldExpression::Check([[maybe_unused]] checker::ETSChecker *chec return checker->GetAnalyzer()->Check(this); } -// NOLINTNEXTLINE(google-default-arguments) YieldExpression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator, nullptr)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, delegate_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/yieldExpression.h b/ets2panda/ir/expressions/yieldExpression.h index 793843063c900c0ac63c43014cbbd40c37258dbd..c7e2f278f9e50fb0ef497f633b164edb2451a8b8 100644 --- a/ets2panda/ir/expressions/yieldExpression.h +++ b/ets2panda/ir/expressions/yieldExpression.h @@ -46,8 +46,7 @@ public: return argument_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/statements/expressionStatement.cpp b/ets2panda/ir/statements/expressionStatement.cpp index 2f10412f4e791993388e7703adf14503b654567a..53f51f3b468025ed5cab1a8320e8821f9c104280 100644 --- a/ets2panda/ir/statements/expressionStatement.cpp +++ b/ets2panda/ir/statements/expressionStatement.cpp @@ -49,6 +49,20 @@ void ExpressionStatement::Dump(ir::SrcDumper *dumper) const } } +ExpressionStatement *ExpressionStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const expression = expression_->Clone(allocator, nullptr)->AsExpression(); + + if (auto *const clone = allocator->New(expression); clone != nullptr) { + expression->SetParent(clone); + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} + void ExpressionStatement::Compile(compiler::PandaGen *pg) const { pg->GetAstCompiler()->Compile(this); diff --git a/ets2panda/ir/statements/expressionStatement.h b/ets2panda/ir/statements/expressionStatement.h index 85da0d28775b77c80cac931f8b3121c439433a57..b8c7cde5d8bd36e1c4d2d6b1bf35330066d314e8 100644 --- a/ets2panda/ir/statements/expressionStatement.h +++ b/ets2panda/ir/statements/expressionStatement.h @@ -49,6 +49,8 @@ public: v->Accept(this); } + [[nodiscard]] ExpressionStatement *Clone(ArenaAllocator *allocator, AstNode *parent) override; + private: Expression *expression_; }; diff --git a/ets2panda/ir/statements/returnStatement.cpp b/ets2panda/ir/statements/returnStatement.cpp index e6973d5d36bf6576b3a0b35348203d1e52a4b7a8..59a5277dddbbf3a11f13f0a985508691c4859f4a 100644 --- a/ets2panda/ir/statements/returnStatement.cpp +++ b/ets2panda/ir/statements/returnStatement.cpp @@ -96,6 +96,8 @@ void ReturnStatement::SetReturnType(checker::ETSChecker *checker, checker::Type void ReturnStatement::SetArgument(Expression *arg) { argument_ = arg; - arg->SetParent(this); + if (argument_ != nullptr) { + argument_->SetParent(this); + } } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/variableDeclaration.cpp b/ets2panda/ir/statements/variableDeclaration.cpp index 91c56499328bdf31abef0edae504a6bfdf5876c2..54ca6eac3d7118e6bee912b5c028870b0e192be8 100644 --- a/ets2panda/ir/statements/variableDeclaration.cpp +++ b/ets2panda/ir/statements/variableDeclaration.cpp @@ -110,6 +110,36 @@ void VariableDeclaration::Dump(ir::SrcDumper *dumper) const } } +VariableDeclaration::VariableDeclaration([[maybe_unused]] Tag const tag, VariableDeclaration const &other, + ArenaAllocator *const allocator) + : Statement(static_cast(other)), + kind_(other.kind_), + decorators_(allocator->Adapter()), + declarators_(allocator->Adapter()), + declare_(other.declare_) +{ + for (auto const &d : other.decorators_) { + decorators_.emplace_back(d->Clone(allocator, nullptr)); + decorators_.back()->SetParent(this); + } + + for (auto const &d : other.declarators_) { + declarators_.emplace_back(d->Clone(allocator, nullptr)->AsVariableDeclarator()); + declarators_.back()->SetParent(this); + } +} + +VariableDeclaration *VariableDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} + void VariableDeclaration::Compile(compiler::PandaGen *pg) const { pg->GetAstCompiler()->Compile(this); diff --git a/ets2panda/ir/statements/variableDeclaration.h b/ets2panda/ir/statements/variableDeclaration.h index e4fa1b7a5581cc1ea0cb7ec45becdd12333476c7..314e928b011ac62a600e2c0c9c8c979cdf79bcee 100644 --- a/ets2panda/ir/statements/variableDeclaration.h +++ b/ets2panda/ir/statements/variableDeclaration.h @@ -22,6 +22,9 @@ namespace panda::es2panda::ir { class VariableDeclarator; class VariableDeclaration : public Statement { +private: + struct Tag {}; + public: enum class VariableDeclarationKind { CONST, LET, VAR }; @@ -35,6 +38,8 @@ public: { } + explicit VariableDeclaration(Tag tag, VariableDeclaration const &other, ArenaAllocator *allocator); + const ArenaVector &Declarators() const { return declarators_; @@ -84,6 +89,8 @@ public: v->Accept(this); } + [[nodiscard]] VariableDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent) override; + private: VariableDeclarationKind kind_; ArenaVector decorators_; diff --git a/ets2panda/ir/statements/variableDeclarator.cpp b/ets2panda/ir/statements/variableDeclarator.cpp index 7dc9140ded2c51bf09f95a80da56fe31dc90af3b..d53ac7ef4a8a1fa17723620804418fd4a622f7b6 100644 --- a/ets2panda/ir/statements/variableDeclarator.cpp +++ b/ets2panda/ir/statements/variableDeclarator.cpp @@ -75,6 +75,26 @@ void VariableDeclarator::Dump(ir::SrcDumper *dumper) const } } +VariableDeclarator *VariableDeclarator::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const id = id_ != nullptr ? id_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *const init = init_ != nullptr ? init_->Clone(allocator, nullptr)->AsExpression() : nullptr; + + if (auto *const clone = allocator->New(flag_, id, init); clone != nullptr) { + if (id != nullptr) { + id->SetParent(clone); + } + if (init != nullptr) { + init->SetParent(clone); + } + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} + void VariableDeclarator::Compile([[maybe_unused]] compiler::PandaGen *pg) const { pg->GetAstCompiler()->Compile(this); diff --git a/ets2panda/ir/statements/variableDeclarator.h b/ets2panda/ir/statements/variableDeclarator.h index aad932d74b896a8180d7983414636e2ca10a43ca..8e4d1da872d11dbfa052e451478aae18506631c9 100644 --- a/ets2panda/ir/statements/variableDeclarator.h +++ b/ets2panda/ir/statements/variableDeclarator.h @@ -56,6 +56,12 @@ public: return init_; } + void SetInit(Expression *init) + { + init_ = init; + init_->SetParent(this); + } + Expression *Id() { return id_; @@ -85,6 +91,8 @@ public: v->Accept(this); } + [[nodiscard]] VariableDeclarator *Clone(ArenaAllocator *allocator, AstNode *parent) override; + private: Expression *id_; Expression *init_ {}; diff --git a/ets2panda/ir/ts/tsArrayType.cpp b/ets2panda/ir/ts/tsArrayType.cpp index b4c9d27caea08b929459d42482688d807dcc4c90..5a09b0a130e54380c6cf15e6c2ad9f0812821bcd 100644 --- a/ets2panda/ir/ts/tsArrayType.cpp +++ b/ets2panda/ir/ts/tsArrayType.cpp @@ -73,15 +73,12 @@ checker::Type *TSArrayType::Check(checker::ETSChecker *checker) checker::Type *TSArrayType::GetType(checker::ETSChecker *checker) { - auto *const elementType = checker->GetTypeFromTypeAnnotation(elementType_); - - return checker->CreateETSArrayType(elementType); + return checker->CreateETSArrayType(elementType_->GetType(checker)); } -// NOLINTNEXTLINE(google-default-arguments) TSArrayType *TSArrayType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const elementTypeClone = elementType_ != nullptr ? elementType_->Clone(allocator) : nullptr; + auto *const elementTypeClone = elementType_ != nullptr ? elementType_->Clone(allocator, nullptr) : nullptr; if (auto *const clone = allocator->New(elementTypeClone); clone != nullptr) { if (elementTypeClone != nullptr) { diff --git a/ets2panda/ir/ts/tsArrayType.h b/ets2panda/ir/ts/tsArrayType.h index 12752a30046a61ffc28895d56c02ab5bcfa5b9db..131d10a5d0339925179a21bbef0eb1eb68462377 100644 --- a/ets2panda/ir/ts/tsArrayType.h +++ b/ets2panda/ir/ts/tsArrayType.h @@ -53,8 +53,7 @@ public: v->Accept(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSArrayType *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSArrayType *Clone(ArenaAllocator *allocator, AstNode *parent) override; private: TypeNode *elementType_; diff --git a/ets2panda/ir/ts/tsAsExpression.cpp b/ets2panda/ir/ts/tsAsExpression.cpp index 051d18b7a501ad7c7ffb506028571cc785f713ef..c28ff0e5cc35808f2ced439a3efbf539dd9e5058 100644 --- a/ets2panda/ir/ts/tsAsExpression.cpp +++ b/ets2panda/ir/ts/tsAsExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -15,30 +15,24 @@ #include "tsAsExpression.h" -#include "varbinder/scope.h" #include "checker/TSchecker.h" -#include "checker/ets/castingContext.h" -#include "checker/types/ets/etsUnionType.h" +#include "checker/ETSchecker.h" #include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literal.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/unaryExpression.h" -#include "ir/typeNode.h" -#include "ir/ets/etsFunctionType.h" namespace panda::es2panda::ir { -Expression *TSAsExpression::Expr() +Expression *TSAsExpression::Expr() noexcept { return expression_; } -void TSAsExpression::SetExpr(Expression *expr) +void TSAsExpression::SetExpr(Expression *expr) noexcept { expression_ = expr; - SetStart(expression_->Start()); + if (expression_ != nullptr) { + SetStart(expression_->Start()); + expression_->SetParent(this); + } } void TSAsExpression::TransformChildren(const NodeTransformer &cb) @@ -82,4 +76,33 @@ checker::Type *TSAsExpression::Check(checker::ETSChecker *const checker) { return checker->GetAnalyzer()->Check(this); } + +TSAsExpression *TSAsExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const expression = expression_ != nullptr ? expression_->Clone(allocator, nullptr)->AsExpression() : nullptr; + auto *typeAnnotation = TypeAnnotation(); + if (typeAnnotation != nullptr) { + typeAnnotation = typeAnnotation->Clone(allocator, nullptr); + } + + if (auto *const clone = allocator->New(expression, typeAnnotation, isConst_); clone != nullptr) { + if (expression != nullptr) { + expression->SetParent(clone); + } + + if (typeAnnotation != nullptr) { + typeAnnotation->SetParent(clone); + } + + clone->SetTsType(TsType()); + if (parent != nullptr) { + clone->SetParent(parent); + } + + clone->SetRange(Range()); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsAsExpression.h b/ets2panda/ir/ts/tsAsExpression.h index ba4903adaba877e18f6e07985238cfdfcfec036e..7639332ad451d8d9d173f54fccfe46a660c67c2e 100644 --- a/ets2panda/ir/ts/tsAsExpression.h +++ b/ets2panda/ir/ts/tsAsExpression.h @@ -29,6 +29,12 @@ class ETSCompiler; namespace panda::es2panda::ir { class TSAsExpression : public AnnotatedExpression { public: + TSAsExpression() = delete; + ~TSAsExpression() override = default; + + NO_COPY_SEMANTIC(TSAsExpression); + NO_MOVE_SEMANTIC(TSAsExpression); + explicit TSAsExpression(Expression *expression, TypeNode *typeAnnotation, bool isConst) : AnnotatedExpression(AstNodeType::TS_AS_EXPRESSION, typeAnnotation), expression_(expression), isConst_(isConst) { @@ -36,19 +42,27 @@ public: // NOTE (vivienvoros): these friend relationships can be removed once there are getters for private fields friend class checker::ETSAnalyzer; friend class compiler::ETSCompiler; - const Expression *Expr() const + + [[nodiscard]] const Expression *Expr() const noexcept { return expression_; } - Expression *Expr(); - void SetExpr(Expression *expr); + [[nodiscard]] Expression *Expr() noexcept; + void SetExpr(Expression *expr) noexcept; - bool IsConst() const + [[nodiscard]] bool IsConst() const noexcept { return isConst_; } + [[nodiscard]] TSAsExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; + + void SetUncheckedCast(bool isUncheckedCast) noexcept + { + isUncheckedCast_ = isUncheckedCast; + } + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsInterfaceBody.cpp b/ets2panda/ir/ts/tsInterfaceBody.cpp index ecdb20767258843ee742c126607d2a0c44bd21a3..34392b288281970da3a67f6fb16b19bb0cd3d05a 100644 --- a/ets2panda/ir/ts/tsInterfaceBody.cpp +++ b/ets2panda/ir/ts/tsInterfaceBody.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/ets2panda/ir/ts/tsNonNullExpression.cpp b/ets2panda/ir/ts/tsNonNullExpression.cpp index 7dc7a91a68a3472af3a4ab5f79f0c6944082ff46..f3b9483f1138593bc3554fef13ce59e1d00425e5 100644 --- a/ets2panda/ir/ts/tsNonNullExpression.cpp +++ b/ets2panda/ir/ts/tsNonNullExpression.cpp @@ -64,4 +64,19 @@ checker::Type *TSNonNullExpression::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +TSNonNullExpression *TSNonNullExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const expr = expr_->Clone(allocator, nullptr)->AsExpression(); + + if (auto *const clone = allocator->New(expr); clone != nullptr) { + expr->SetParent(clone); + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} + } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsNonNullExpression.h b/ets2panda/ir/ts/tsNonNullExpression.h index 1453a835d4e7527d5f9ef30361e144a5750aeba6..dfa339cb625ffab0bb80c3599a1b26b72998e933 100644 --- a/ets2panda/ir/ts/tsNonNullExpression.h +++ b/ets2panda/ir/ts/tsNonNullExpression.h @@ -29,11 +29,21 @@ public: // NOTE (vivienvoros): these friend relationships can be removed once there are getters for private fields friend class checker::ETSAnalyzer; - const Expression *Expr() const + const Expression *Expr() const noexcept { return expr_; } + Expression *Expr() noexcept + { + return expr_; + } + + void SetExpr(Expression *expr) noexcept + { + expr_ = expr; + } + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; @@ -48,6 +58,8 @@ public: v->Accept(this); } + [[nodiscard]] TSNonNullExpression *Clone(ArenaAllocator *allocator, AstNode *parent) override; + private: Expression *expr_; }; diff --git a/ets2panda/ir/ts/tsQualifiedName.cpp b/ets2panda/ir/ts/tsQualifiedName.cpp index d3c4751114aecc79edb26fa7ece0fa23cf5d1dbd..65fe1b15bb654daecdfb2e23028e19f3f0d3b2b5 100644 --- a/ets2panda/ir/ts/tsQualifiedName.cpp +++ b/ets2panda/ir/ts/tsQualifiedName.cpp @@ -24,6 +24,14 @@ #include "ir/expressions/identifier.h" namespace panda::es2panda::ir { +TSQualifiedName::TSQualifiedName([[maybe_unused]] Tag const tag, TSQualifiedName const &other, + ArenaAllocator *allocator) + : Expression(static_cast(other)) +{ + left_ = other.left_ != nullptr ? other.left_->Clone(allocator, this)->AsExpression() : nullptr; + right_ = other.right_ != nullptr ? other.right_->Clone(allocator, this)->AsIdentifier() : nullptr; +} + void TSQualifiedName::Iterate(const NodeTraverser &cb) const { cb(left_); @@ -132,4 +140,18 @@ const ir::TSQualifiedName *TSQualifiedName::ResolveLeftMostQualifiedName() const { return ResolveLeftMostQualifiedNameImpl(this); } + +TSQualifiedName *TSQualifiedName::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + + clone->SetRange(Range()); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsQualifiedName.h b/ets2panda/ir/ts/tsQualifiedName.h index a59bf6aa3a2fd7988ad27fd2e8de52b53817ea14..ff2e145f8f224f4ca97f5382a3a7f94add1433c4 100644 --- a/ets2panda/ir/ts/tsQualifiedName.h +++ b/ets2panda/ir/ts/tsQualifiedName.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 2024 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 @@ -20,28 +20,38 @@ namespace panda::es2panda::ir { class TSQualifiedName : public Expression { + struct Tag {}; + public: + TSQualifiedName() = delete; + ~TSQualifiedName() override = default; + + NO_COPY_SEMANTIC(TSQualifiedName); + NO_MOVE_SEMANTIC(TSQualifiedName); + explicit TSQualifiedName(Expression *left, Identifier *right) : Expression(AstNodeType::TS_QUALIFIED_NAME), left_(left), right_(right) { } - const Expression *Left() const + explicit TSQualifiedName(Tag tag, TSQualifiedName const &other, ArenaAllocator *allocator); + + [[nodiscard]] const Expression *Left() const noexcept { return left_; } - Expression *Left() + [[nodiscard]] Expression *Left() noexcept { return left_; } - const Identifier *Right() const + [[nodiscard]] const Identifier *Right() const noexcept { return right_; } - Identifier *Right() + [[nodiscard]] Identifier *Right() noexcept { return right_; } @@ -51,6 +61,8 @@ public: ir::TSQualifiedName *ResolveLeftMostQualifiedName(); const ir::TSQualifiedName *ResolveLeftMostQualifiedName() const; + [[nodiscard]] TSQualifiedName *Clone(ArenaAllocator *allocator, AstNode *parent) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index ef538c9bcf72eee3a1a702979bec167a0f0163f1..84496dcd92e2889b2426dc65cc4fa70d628bc348 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -35,7 +35,6 @@ TSTypeParameterInstantiation::TSTypeParameterInstantiation([[maybe_unused]] Tag } } -// NOLINTNEXTLINE(google-default-arguments) TSTypeParameterInstantiation *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, AstNode *const parent) { diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.h b/ets2panda/ir/ts/tsTypeParameterInstantiation.h index be57a1c502e38aa4e83c37d498263212135bfbe5..e6c02c9e585dee7d228d5f808e6f26bb259d807d 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.h @@ -42,8 +42,7 @@ public: return params_; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/typeNode.cpp b/ets2panda/ir/typeNode.cpp index be22e10ee704a4131e7b904c37bcbe46245b34a3..c90e0234ae5e3f4a3bc3403da01b03c431176bc4 100644 --- a/ets2panda/ir/typeNode.cpp +++ b/ets2panda/ir/typeNode.cpp @@ -20,7 +20,6 @@ namespace panda::es2panda::ir { -// NOLINTNEXTLINE(google-default-arguments) TypeNode *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const type = TsType(); type != nullptr) { diff --git a/ets2panda/ir/typeNode.h b/ets2panda/ir/typeNode.h index 7933f9b5e407daaa0898bc2b39b20c5107b542c4..72f4ceb54011618bdab613b38036c72fe9749a47 100644 --- a/ets2panda/ir/typeNode.h +++ b/ets2panda/ir/typeNode.h @@ -47,8 +47,7 @@ public: return nullptr; } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent) override; protected: explicit TypeNode(AstNodeType const type) : Expression(type) {} diff --git a/ets2panda/ir/visitor/IterateAstVisitor.h b/ets2panda/ir/visitor/IterateAstVisitor.h index a6aad93b01a49df8f1f40d9abbb933baff38ca36..e990651198c9a86c38a6b79e34492e80b2ed6161 100644 --- a/ets2panda/ir/visitor/IterateAstVisitor.h +++ b/ets2panda/ir/visitor/IterateAstVisitor.h @@ -21,6 +21,7 @@ #include "ir/expressions/blockExpression.h" #include "ir/ets/etsUnionType.h" #include "ir/ets/etsTuple.h" +#include "ir/ets/etsNullishTypes.h" namespace panda::es2panda::ir::visitor { diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index b91b25f8162a6920f18bda39f0b4fbc7946231e4..c684179239ea1a40fc99f94cbdf63bfa0b210334 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -94,6 +94,7 @@ #include "ir/ets/etsScript.h" #include "ir/ets/etsTypeReference.h" #include "ir/ets/etsTypeReferencePart.h" +#include "ir/ets/etsNullishTypes.h" #include "ir/ets/etsUnionType.h" #include "ir/ets/etsImportSource.h" #include "ir/ets/etsImportDeclaration.h" @@ -648,7 +649,7 @@ ir::ScriptFunction *ETSParser::AddInitMethod(ArenaVector &globalP auto *initBody = AllocNode(Allocator(), std::move(statements)); initFunc = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), - initBody, functionFlags, false, GetContext().GetLanguge()); + initBody, functionFlags, false, GetContext().GetLanguage()); } initFunc->SetIdent(initIdent); @@ -656,8 +657,9 @@ ir::ScriptFunction *ETSParser::AddInitMethod(ArenaVector &globalP auto *funcExpr = AllocNode(initFunc); - auto *initMethod = AllocNode(ir::MethodDefinitionKind::METHOD, initIdent, funcExpr, - functionModifiers, Allocator(), false); + auto *initMethod = AllocNode(ir::MethodDefinitionKind::METHOD, + initIdent->Clone(Allocator(), nullptr)->AsExpression(), + funcExpr, functionModifiers, Allocator(), false); return std::make_pair(initFunc, initMethod); }; @@ -1017,9 +1019,6 @@ void ETSParser::CreateCCtor(ArenaVector &properties, const lexer: } ArenaVector params(Allocator()->Adapter()); - - auto *id = AllocNode(compiler::Signatures::CCTOR, Allocator()); - ArenaVector statements(Allocator()->Adapter()); // Add the call to special '_$init$_' method containing all the top-level variable initializations (as assignments) @@ -1044,10 +1043,12 @@ void ETSParser::CreateCCtor(ArenaVector &properties, const lexer: } } + auto *id = AllocNode(compiler::Signatures::CCTOR, Allocator()); auto *body = AllocNode(Allocator(), std::move(statements)); - auto *func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, - ir::ModifierFlags::STATIC, false, GetContext().GetLanguge()); + auto *func = AllocNode( + ir::FunctionSignature(nullptr, std::move(params), nullptr), body, + ir::ScriptFunction::ScriptFunctionData {ir::ScriptFunctionFlags::STATIC_BLOCK | ir::ScriptFunctionFlags::HIDDEN, + ir::ModifierFlags::STATIC, false, GetContext().GetLanguage()}); func->SetIdent(id); auto *funcExpr = AllocNode(func); @@ -1387,18 +1388,19 @@ lexer::SourcePosition ETSParser::InitializeGlobalVariable(ir::Identifier *fieldN ident->SetReference(); ident->SetRange(fieldName->Range()); - auto *assignmentExpression = - AllocNode(ident, initializer, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *assignmentExpression = AllocNode( + ident, initializer->Clone(Allocator(), nullptr)->AsExpression(), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); endLoc = initializer->End(); assignmentExpression->SetRange({fieldName->Start(), endLoc}); - assignmentExpression->SetParent(funcBody); auto expressionStatement = AllocNode(assignmentExpression); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { endLoc = Lexer()->GetToken().End(); } + expressionStatement->SetParent(funcBody); expressionStatement->SetRange({startLoc, endLoc}); funcBody->AsBlockStatement()->Statements().emplace_back(expressionStatement); + expressionStatement->SetParent(funcBody); if (typeAnnotation != nullptr && !typeAnnotation->IsETSFunctionType()) { initializer = nullptr; @@ -1440,7 +1442,8 @@ ir::MethodDefinition *ETSParser::ParseClassMethodDefinition(ir::Identifier *meth if (className != nullptr) { func->AddFlag(ir::ScriptFunctionFlags::INSTANCE_EXTENSION_METHOD); } - auto *method = AllocNode(methodKind, methodName, funcExpr, modifiers, Allocator(), false); + auto *method = AllocNode(methodKind, methodName->Clone(Allocator(), nullptr)->AsExpression(), + funcExpr, modifiers, Allocator(), false); method->SetRange(funcExpr->Range()); fieldMap_.insert({methodName->Name(), method}); @@ -1489,7 +1492,7 @@ ir::ScriptFunction *ETSParser::ParseFunction(ParserStatus newStatus, ir::Identif functionContext.AddFlag(throwMarker); auto *funcNode = AllocNode(std::move(signature), body, functionContext.Flags(), false, - GetContext().GetLanguge()); + GetContext().GetLanguage()); funcNode->SetRange({startLoc, endLoc}); return funcNode; @@ -1505,6 +1508,9 @@ ir::MethodDefinition *ETSParser::ParseClassMethod(ClassElementDescriptor *desc, } ir::ScriptFunction *func = ParseFunction(desc->newStatus); + if (propName->IsIdentifier()) { + func->SetIdent(propName->AsIdentifier()->Clone(Allocator(), nullptr)); + } auto *funcExpr = AllocNode(func); funcExpr->SetRange(func->Range()); @@ -1517,8 +1523,9 @@ ir::MethodDefinition *ETSParser::ParseClassMethod(ClassElementDescriptor *desc, *propEnd = func->End(); func->AddFlag(ir::ScriptFunctionFlags::METHOD); - auto *method = AllocNode(desc->methodKind, propName, funcExpr, desc->modifiers, Allocator(), - desc->isComputed); + auto *method = + AllocNode(desc->methodKind, propName->Clone(Allocator(), nullptr)->AsExpression(), + funcExpr, desc->modifiers, Allocator(), desc->isComputed); method->SetRange(funcExpr->Range()); return method; @@ -1745,7 +1752,6 @@ ir::MethodDefinition *ETSParser::ParseClassGetterSetterMethod(const ArenaVector< lexer::SourcePosition propEnd = methodName->End(); ir::MethodDefinition *method = ParseClassMethod(&desc, properties, methodName, &propEnd); - method->Function()->SetIdent(methodName); method->Function()->AddModifier(desc.modifiers); method->SetRange({desc.propStart, propEnd}); if (desc.methodKind == ir::MethodDefinitionKind::GET) { @@ -1772,7 +1778,7 @@ ir::MethodDefinition *ETSParser::ParseInterfaceGetterSetterMethod(const ir::Modi method->Function()->AddFlag(ir::ScriptFunctionFlags::SETTER); } - method->Function()->SetIdent(method->Id()); + method->Function()->SetIdent(method->Id()->Clone(Allocator(), nullptr)); method->Function()->AddModifier(method->Modifiers()); return method; @@ -1964,7 +1970,7 @@ ir::TSInterfaceDeclaration *ETSParser::ParseInterfaceBody(ir::Identifier *name, const auto isExternal = (GetContext().Status() & ParserStatus::IN_EXTERNAL); auto *interfaceDecl = AllocNode( - Allocator(), name, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguge()); + Allocator(), name, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguage()); Lexer()->NextToken(); GetContext().Status() &= ~ParserStatus::ALLOW_THIS_TYPE; @@ -2065,7 +2071,7 @@ ir::ClassDefinition *ETSParser::ParseClassDefinition(ir::ClassDefinitionModifier auto *classDefinition = AllocNode( util::StringView(), identNode, typeParamDecl, superTypeParams, std::move(implements), ctor, superClass, - std::move(properties), modifiers, flags, GetContext().GetLanguge()); + std::move(properties), modifiers, flags, GetContext().GetLanguage()); classDefinition->SetRange(bodyRange); @@ -2133,6 +2139,7 @@ ir::ClassProperty *ETSParser::ParseInterfaceField() typeAnnotation = ParseTypeAnnotation(&options); name->SetTsTypeAnnotation(typeAnnotation); + typeAnnotation->SetParent(name); if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_EQUAL) { ThrowSyntaxError("Initializers are not allowed on interface propertys."); @@ -2144,7 +2151,8 @@ ir::ClassProperty *ETSParser::ParseInterfaceField() fieldModifiers |= ir::ModifierFlags::DECLARE; } - auto *field = AllocNode(name, nullptr, typeAnnotation, fieldModifiers, Allocator(), false); + auto *field = AllocNode(name, nullptr, typeAnnotation->Clone(Allocator(), nullptr), + fieldModifiers, Allocator(), false); field->SetEnd(Lexer()->GetToken().End()); return field; @@ -2181,8 +2189,9 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags, i functionContext.AddFlag(throwMarker); - auto *func = AllocNode(std::move(signature), body, functionContext.Flags(), flags, true, - GetContext().GetLanguge()); + auto *func = AllocNode( + std::move(signature), body, + ir::ScriptFunction::ScriptFunctionData {functionContext.Flags(), flags, true, GetContext().GetLanguage()}); if ((flags & ir::ModifierFlags::STATIC) == 0 && body == nullptr) { func->AddModifier(ir::ModifierFlags::ABSTRACT); @@ -2196,8 +2205,9 @@ ir::MethodDefinition *ETSParser::ParseInterfaceMethod(ir::ModifierFlags flags, i func->AddFlag(ir::ScriptFunctionFlags::METHOD); func->SetIdent(name); - auto *method = - AllocNode(ir::MethodDefinitionKind::METHOD, name, funcExpr, flags, Allocator(), false); + auto *method = AllocNode(ir::MethodDefinitionKind::METHOD, + name->Clone(Allocator(), nullptr)->AsExpression(), funcExpr, flags, + Allocator(), false); method->SetRange(funcExpr->Range()); ConsumeSemicolon(method); @@ -2387,43 +2397,22 @@ std::string ETSParser::GetNameForETSUnionType(const ir::TypeNode *typeAnnotation std::string newstr; for (size_t i = 0; i < typeAnnotation->AsETSUnionType()->Types().size(); i++) { auto type = typeAnnotation->AsETSUnionType()->Types()[i]; - if (type->IsNullAssignable() || type->IsUndefinedAssignable()) { - continue; - } - std::string str = GetNameForTypeNode(type, false); + std::string str = GetNameForTypeNode(type); newstr += str; if (i != typeAnnotation->AsETSUnionType()->Types().size() - 1) { newstr += "|"; } } - if (typeAnnotation->IsNullAssignable()) { - newstr += "|null"; - } - if (typeAnnotation->IsUndefinedAssignable()) { - newstr += "|undefined"; - } return newstr; } -std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *typeAnnotation, bool adjust) const +std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *typeAnnotation) const { if (typeAnnotation->IsETSUnionType()) { return GetNameForETSUnionType(typeAnnotation); } - - const auto adjustNullish = [typeAnnotation, adjust](std::string const &s) { - std::string newstr = s; - if (typeAnnotation->IsNullAssignable() && adjust) { - newstr += "|null"; - } - if (typeAnnotation->IsUndefinedAssignable() && adjust) { - newstr += "|undefined"; - } - return newstr; - }; - if (typeAnnotation->IsETSPrimitiveType()) { - return adjustNullish(PrimitiveTypeToName(typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType())); + return PrimitiveTypeToName(typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType()); } if (typeAnnotation->IsETSTypeReference()) { @@ -2439,8 +2428,7 @@ std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *typeAnnotation, bo typeParamNames.pop_back(); typeParamNames += ">"; } - return adjustNullish(typeAnnotation->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name().Mutf8() + - typeParamNames); + return typeAnnotation->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name().Mutf8() + typeParamNames; } if (typeAnnotation->IsETSFunctionType()) { @@ -2456,7 +2444,7 @@ std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *typeAnnotation, bo lambdaParams.pop_back(); const std::string returnTypeName = GetNameForTypeNode(typeAnnotation->AsETSFunctionType()->ReturnType()); - return adjustNullish("((" + lambdaParams + ") => " + returnTypeName + ")"); + return "((" + lambdaParams + ") => " + returnTypeName + ")"; } if (typeAnnotation->IsTSArrayType()) { @@ -2464,6 +2452,14 @@ std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *typeAnnotation, bo return GetNameForTypeNode(typeAnnotation->AsTSArrayType()->ElementType()) + "[]"; } + if (typeAnnotation->IsETSNullType()) { + return "null"; + } + + if (typeAnnotation->IsETSUndefinedType()) { + return "undefined"; + } + UNREACHABLE(); } @@ -2654,33 +2650,15 @@ ir::TypeNode *ETSParser::ParseUnionType(ir::TypeNode *const firstType) ArenaVector types(Allocator()->Adapter()); types.push_back(firstType->AsTypeNode()); - ir::ModifierFlags nullishModifiers {}; - while (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_OR) { Lexer()->NextToken(); // eat '|' - if (Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_NULL) { - nullishModifiers |= ir::ModifierFlags::NULL_ASSIGNABLE; - Lexer()->NextToken(); - } else if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_UNDEFINED) { - nullishModifiers |= ir::ModifierFlags::UNDEFINED_ASSIGNABLE; - Lexer()->NextToken(); - } else { - auto options = TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::DISALLOW_UNION; - types.push_back(ParseTypeAnnotation(&options)); - } - } - - lexer::SourcePosition const endLoc = types.back()->End(); - - if (types.size() == 1) { // Workaround until nullability is a typeflag - firstType->AddModifier(nullishModifiers); - firstType->SetRange({firstType->Start(), endLoc}); - return firstType; + auto options = TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::DISALLOW_UNION; + types.push_back(ParseTypeAnnotation(&options)); } + auto const endLoc = types.back()->End(); auto *const unionType = AllocNode(std::move(types)); - unionType->AddModifier(nullishModifiers); unionType->SetRange({firstType->Start(), endLoc}); return unionType; } @@ -2903,6 +2881,18 @@ std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnota typeAnnotation = ParsePrimitiveType(options, ir::PrimitiveType::SHORT); break; } + case lexer::TokenType::LITERAL_NULL: { + typeAnnotation = AllocNode(); + typeAnnotation->SetRange(Lexer()->GetToken().Loc()); + Lexer()->NextToken(); + break; + } + case lexer::TokenType::KEYW_UNDEFINED: { + typeAnnotation = AllocNode(); + typeAnnotation->SetRange(Lexer()->GetToken().Loc()); + Lexer()->NextToken(); + break; + } case lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS: { auto startLoc = Lexer()->GetToken().Start(); lexer::LexerPosition savedPos = Lexer()->Save(); @@ -3427,40 +3417,28 @@ static constexpr char const ONLY_ARRAY_FOR_REST[] = "Rest parameter should be of static constexpr char const EXPLICIT_PARAM_TYPE[] = "Parameter declaration should have an explicit type annotation."; // NOLINTEND(modernize-avoid-c-arrays) -ir::Expression *ETSParser::ParseFunctionParameter() +ir::ETSUnionType *ETSParser::CreateOptionalParameterTypeNode(ir::TypeNode *typeAnnotation, + ir::ETSUndefinedType *defaultUndef) { - ir::ETSParameterExpression *paramExpression; - auto *const paramIdent = GetAnnotatedExpressionFromParam(); - - bool defaultUndefined = false; - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { - if (paramIdent->IsRestElement()) { - ThrowSyntaxError(NO_DEFAULT_FOR_REST); + ArenaVector types(Allocator()->Adapter()); + if (typeAnnotation->IsETSUnionType()) { + for (auto const &type : typeAnnotation->AsETSUnionType()->Types()) { + types.push_back(type); } - defaultUndefined = true; - Lexer()->NextToken(); // eat '?' + } else { + types.push_back(typeAnnotation); } + types.push_back(defaultUndef); - const bool isArrow = (GetContext().Status() & ParserStatus::ARROW_FUNCTION) != 0; - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { - Lexer()->NextToken(); // eat ':' - - TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; - ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); - - if (paramIdent->IsRestElement() && !typeAnnotation->IsTSArrayType()) { - ThrowSyntaxError(ONLY_ARRAY_FOR_REST); - } - - typeAnnotation->SetParent(paramIdent); - paramIdent->SetTsTypeAnnotation(typeAnnotation); - paramIdent->SetEnd(typeAnnotation->End()); - - } else if (!isArrow && !defaultUndefined) { - ThrowSyntaxError(EXPLICIT_PARAM_TYPE); - } + auto *const unionType = AllocNode(std::move(types)); + unionType->SetRange({typeAnnotation->Start(), typeAnnotation->End()}); + return unionType; +} +ir::Expression *ETSParser::ParseFunctionParameterExpression(ir::AnnotatedExpression *const paramIdent, + ir::ETSUndefinedType *defaultUndef) +{ + ir::ETSParameterExpression *paramExpression; if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { if (paramIdent->IsRestElement()) { ThrowSyntaxError(NO_DEFAULT_FOR_REST); @@ -3469,10 +3447,9 @@ ir::Expression *ETSParser::ParseFunctionParameter() auto const lexerPos = Lexer()->Save().Iterator(); Lexer()->NextToken(); // eat '=' - if (defaultUndefined) { + if (defaultUndef != nullptr) { ThrowSyntaxError("Not enable default value with default undefined"); } - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS || Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { ThrowSyntaxError("You didn't set the value."); @@ -3491,54 +3468,70 @@ ir::Expression *ETSParser::ParseFunctionParameter() paramExpression->SetRange({paramIdent->Start(), paramExpression->Initializer()->End()}); } else if (paramIdent->IsIdentifier()) { - auto *const typeAnnotation = paramIdent->AsIdentifier()->TypeAnnotation(); + auto *typeAnnotation = paramIdent->AsIdentifier()->TypeAnnotation(); - const auto typeAnnotationValue = [this, typeAnnotation]() -> std::pair { + const auto typeAnnotationValue = [this, typeAnnotation, + defaultUndef]() -> std::pair { if (typeAnnotation == nullptr) { return std::make_pair(nullptr, ""); } - if (!typeAnnotation->IsETSPrimitiveType()) { - return std::make_pair(AllocNode(), "undefined"); - } - // NOTE(ttamas) : after nullable fix, fix this scope - switch (typeAnnotation->AsETSPrimitiveType()->GetPrimitiveType()) { - case ir::PrimitiveType::BYTE: - case ir::PrimitiveType::INT: - case ir::PrimitiveType::LONG: - case ir::PrimitiveType::SHORT: - case ir::PrimitiveType::FLOAT: - case ir::PrimitiveType::DOUBLE: - return std::make_pair(AllocNode(lexer::Number(0)), "0"); - case ir::PrimitiveType::BOOLEAN: - return std::make_pair(AllocNode(false), "false"); - case ir::PrimitiveType::CHAR: - return std::make_pair(AllocNode(), "c'\\u0000'"); - default: { - UNREACHABLE(); - } - } + return std::make_pair(defaultUndef != nullptr ? AllocNode() : nullptr, "undefined"); }(); - if (defaultUndefined && !typeAnnotation->IsETSPrimitiveType()) { - typeAnnotation->AddModifier(ir::ModifierFlags::UNDEFINED_ASSIGNABLE); - } - - paramExpression = AllocNode( - paramIdent->AsIdentifier(), defaultUndefined ? std::get<0>(typeAnnotationValue) : nullptr); - - if (defaultUndefined) { + paramExpression = + AllocNode(paramIdent->AsIdentifier(), std::get<0>(typeAnnotationValue)); + if (defaultUndef != nullptr) { paramExpression->SetLexerSaved(util::UString(std::get<1>(typeAnnotationValue), Allocator()).View()); } - paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); } else { paramExpression = AllocNode(paramIdent->AsRestElement(), nullptr); paramExpression->SetRange({paramIdent->Start(), paramIdent->End()}); } - return paramExpression; } +ir::Expression *ETSParser::ParseFunctionParameter() +{ + auto *const paramIdent = GetAnnotatedExpressionFromParam(); + + ir::ETSUndefinedType *defaultUndef = nullptr; + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_QUESTION_MARK) { + if (paramIdent->IsRestElement()) { + ThrowSyntaxError(NO_DEFAULT_FOR_REST); + } + defaultUndef = AllocNode(); + defaultUndef->SetRange({Lexer()->GetToken().Start(), Lexer()->GetToken().End()}); + Lexer()->NextToken(); // eat '?' + } + + const bool isArrow = (GetContext().Status() & ParserStatus::ARROW_FUNCTION) != 0; + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COLON) { + Lexer()->NextToken(); // eat ':' + + TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; + ir::TypeNode *typeAnnotation = ParseTypeAnnotation(&options); + + if (defaultUndef != nullptr) { + typeAnnotation = CreateOptionalParameterTypeNode(typeAnnotation, defaultUndef); + } + + if (paramIdent->IsRestElement() && !typeAnnotation->IsTSArrayType()) { + ThrowSyntaxError(ONLY_ARRAY_FOR_REST); + } + + typeAnnotation->SetParent(paramIdent); + paramIdent->SetTsTypeAnnotation(typeAnnotation); + paramIdent->SetEnd(typeAnnotation->End()); + } else if (!isArrow && defaultUndef == nullptr) { + ThrowSyntaxError(EXPLICIT_PARAM_TYPE); + } + + return ParseFunctionParameterExpression(paramIdent, defaultUndef); +} + ir::Expression *ETSParser::CreateParameterThis(const util::StringView className) { auto *paramIdent = AllocNode(varbinder::TypedBinder::MANDATORY_PARAM_THIS, Allocator()); @@ -3718,7 +3711,10 @@ void ETSParser::ParseCatchParamTypeAnnotation([[maybe_unused]] ir::AnnotatedExpr Lexer()->NextToken(); // eat ':' TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; - param->SetTsTypeAnnotation(ParseTypeAnnotation(&options)); + if (auto *typeAnnotation = ParseTypeAnnotation(&options); typeAnnotation != nullptr) { + typeAnnotation->SetParent(param); + param->SetTsTypeAnnotation(typeAnnotation); + } } if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { @@ -4117,6 +4113,10 @@ ir::Expression *ETSParser::ParsePostPrimaryExpression(ir::Expression *primaryExp while (true) { switch (Lexer()->GetToken().Type()) { case lexer::TokenType::PUNCTUATOR_QUESTION_DOT: { + if (*isChainExpression) { + break; // terminate current chain + } + *isChainExpression = true; Lexer()->NextToken(); // eat ?. if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET) { @@ -4155,7 +4155,6 @@ ir::Expression *ETSParser::ParsePostPrimaryExpression(ir::Expression *primaryExp if (ignoreCallExpression) { break; } - returnExpression = ParseCallExpression(returnExpression, false, false); continue; } @@ -4196,6 +4195,53 @@ ir::Expression *ETSParser::ParsePotentialAsExpression(ir::Expression *primaryExp return asExpression; } +// Extracted from 'ParseNewExpression()' to reduce function's size +ir::ClassDefinition *ETSParser::CreateClassDefinitionForNewExpression(ArenaVector &arguments, + ir::TypeNode *typeReference, + ir::TypeNode *baseTypeReference) +{ + lexer::SourcePosition endLoc = typeReference->End(); + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { + if (baseTypeReference != nullptr) { + ThrowSyntaxError("Can not use 'new' on primitive types.", baseTypeReference->Start()); + } + + Lexer()->NextToken(); + + while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { + ir::Expression *argument = ParseExpression(); + arguments.push_back(argument); + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { + Lexer()->NextToken(); + continue; + } + } + + endLoc = Lexer()->GetToken().End(); + Lexer()->NextToken(); + } + + ir::ClassDefinition *classDefinition {}; + + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { + ArenaVector implements(Allocator()->Adapter()); + auto modifiers = ir::ClassDefinitionModifiers::ANONYMOUS | ir::ClassDefinitionModifiers::HAS_SUPER; + auto [ctor, properties, bodyRange] = ParseClassBody(modifiers); + + auto newIdent = AllocNode("#0", Allocator()); + classDefinition = AllocNode( + "#0", newIdent, nullptr, nullptr, std::move(implements), ctor, // remove name + typeReference->Clone(Allocator(), nullptr), std::move(properties), modifiers, ir::ModifierFlags::NONE, + Language(Language::Id::ETS)); + + classDefinition->SetRange(bodyRange); + } + + return classDefinition; +} + ir::Expression *ETSParser::ParseNewExpression() { lexer::SourcePosition start = Lexer()->GetToken().Start(); @@ -4220,7 +4266,7 @@ ir::Expression *ETSParser::ParseNewExpression() ExpectToken(lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET); if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET) { - auto *arrInstance = AllocNode(Allocator(), typeReference, dimension); + auto *arrInstance = AllocNode(typeReference, dimension); arrInstance->SetRange({start, endLoc}); return arrInstance; } @@ -4242,43 +4288,8 @@ ir::Expression *ETSParser::ParseNewExpression() } ArenaVector arguments(Allocator()->Adapter()); - lexer::SourcePosition endLoc = typeReference->End(); - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_PARENTHESIS) { - if (baseTypeReference != nullptr) { - ThrowSyntaxError("Can not use 'new' on primitive types.", baseTypeReference->Start()); - } - - Lexer()->NextToken(); - - while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { - ir::Expression *argument = ParseExpression(); - arguments.push_back(argument); - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_COMMA) { - Lexer()->NextToken(); - continue; - } - } - - endLoc = Lexer()->GetToken().End(); - Lexer()->NextToken(); - } - - ir::ClassDefinition *classDefinition {}; - - if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { - ArenaVector implements(Allocator()->Adapter()); - auto modifiers = ir::ClassDefinitionModifiers::ANONYMOUS | ir::ClassDefinitionModifiers::HAS_SUPER; - auto [ctor, properties, bodyRange] = ParseClassBody(modifiers); - - auto newIdent = AllocNode("#0", Allocator()); - classDefinition = AllocNode( - "#0", newIdent, nullptr, nullptr, std::move(implements), ctor, // remove name - typeReference, std::move(properties), modifiers, ir::ModifierFlags::NONE, Language(Language::Id::ETS)); - - classDefinition->SetRange(bodyRange); - } + ir::ClassDefinition *classDefinition = + CreateClassDefinitionForNewExpression(arguments, typeReference, baseTypeReference); auto *newExprNode = AllocNode(typeReference, std::move(arguments), classDefinition); diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index 4b4afef511257ad239e6150fd9db23e9cc66d76e..1560bfbd4f7ff2f967740eed28fd4ebc3d2c6d58 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -71,9 +71,7 @@ public: ir::Expression *CreateFormattedExpression(std::string_view const sourceCode, std::string_view const fileName, Args &&...args) { - std::vector insertingNodes {}; - insertingNodes.reserve(sizeof...(Args)); - (insertingNodes.emplace_back(std::forward(args)), ...); + std::vector insertingNodes {args...}; return CreateFormattedExpression(sourceCode, insertingNodes, fileName); } @@ -88,8 +86,7 @@ public: ArenaVector CreateFormattedStatements(std::string_view const sourceCode, std::string_view const fileName, Args &&...args) { - std::vector insertingNodes {}; - (insertingNodes.emplace(std::forward(args)), ...); + std::vector insertingNodes {args...}; return CreateFormattedStatements(sourceCode, insertingNodes, fileName); } @@ -199,7 +196,7 @@ private: ir::MethodDefinition *CreateProxyConstructorDefinition(ir::MethodDefinition const *const method); void AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *identNode = nullptr); static std::string PrimitiveTypeToName(ir::PrimitiveType type); - std::string GetNameForTypeNode(const ir::TypeNode *typeAnnotation, bool adjust = true) const; + std::string GetNameForTypeNode(const ir::TypeNode *typeAnnotation) const; std::string GetNameForETSUnionType(const ir::TypeNode *typeAnnotation) const; ir::TSInterfaceDeclaration *ParseInterfaceBody(ir::Identifier *name, bool isStatic); bool IsArrowFunctionExpressionStart(); @@ -231,8 +228,11 @@ private: ir::AstNode *ParseTypeLiteralOrInterfaceMember() override; void ParseNameSpaceSpecifier(ArenaVector *specifiers, bool isReExport = false); bool CheckModuleAsModifier(); + ir::Expression *ParseFunctionParameterExpression(ir::AnnotatedExpression *paramIdent, + ir::ETSUndefinedType *defaultUndef); ir::Expression *ParseFunctionParameter() override; ir::AnnotatedExpression *GetAnnotatedExpressionFromParam(); + ir::ETSUnionType *CreateOptionalParameterTypeNode(ir::TypeNode *typeAnnotation, ir::ETSUndefinedType *defaultUndef); // NOLINTNEXTLINE(google-default-arguments) ir::Expression *ParseUnaryOrPrefixUpdateExpression( ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS) override; @@ -266,6 +266,10 @@ private: ir::AstNode *ParseInnerRest(const ArenaVector &properties, ir::ClassDefinitionModifiers modifiers, ir::ModifierFlags memberModifiers, ir::Identifier *identNode, const lexer::SourcePosition &startLoc); + + ir::ClassDefinition *CreateClassDefinitionForNewExpression(ArenaVector &arguments, + ir::TypeNode *typeReference, + ir::TypeNode *baseTypeReference); ir::Expression *ParseNewExpression() override; ir::Expression *ParseAsyncExpression(); ir::Expression *ParseAwaitExpression(); diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index a3018356f2b0dc8c995306197b600d68d79f8d2f..9851f05a727fe667ccf38ed487b31a68d0b1eb78 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -462,7 +462,7 @@ ir::Statement *TypedParser::ParseInterfaceDeclaration(bool isStatic) const auto isExternal = (GetContext().Status() & ParserStatus::IN_EXTERNAL); auto *interfaceDecl = AllocNode( - Allocator(), id, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguge()); + Allocator(), id, typeParamDecl, body, std::move(extends), isStatic, isExternal, GetContext().GetLanguage()); interfaceDecl->SetRange({interfaceStart, Lexer()->GetToken().End()}); Lexer()->NextToken(); @@ -880,7 +880,7 @@ ir::ClassDefinition *TypedParser::ParseClassDefinition(ir::ClassDefinitionModifi auto *classDefinition = AllocNode( privateBinding.View(), identNode, typeParamDecl, superTypeParams, std::move(implements), ctor, superClass, - std::move(properties), modifiers, flags, GetContext().GetLanguge()); + std::move(properties), modifiers, flags, GetContext().GetLanguage()); classDefinition->SetRange(bodyRange); diff --git a/ets2panda/parser/context/parserContext.h b/ets2panda/parser/context/parserContext.h index 926fc510f0f3a3a425aa047e84bd55866d54c64e..5a3c4ce5118a483d24d84b9d7cf5e2bd299b51f5 100644 --- a/ets2panda/parser/context/parserContext.h +++ b/ets2panda/parser/context/parserContext.h @@ -98,7 +98,7 @@ public: program_ = program; } - Language GetLanguge() const + Language GetLanguage() const { return lang_; } diff --git a/ets2panda/parser/expressionParser.cpp b/ets2panda/parser/expressionParser.cpp index 5eaa24e774c206db6312bfb73a1e4122b46ab6c1..947edf5a77432b564a54170d7755f55d9711d2e5 100644 --- a/ets2panda/parser/expressionParser.cpp +++ b/ets2panda/parser/expressionParser.cpp @@ -62,6 +62,7 @@ #include "ir/statements/blockStatement.h" #include "ir/statements/classDeclaration.h" #include "ir/ts/tsAsExpression.h" +#include "ir/ts/tsNonNullExpression.h" #include "ir/validationInfo.h" #include "lexer/lexer.h" #include "lexer/regexp/regexp.h" @@ -325,7 +326,7 @@ ir::ArrowFunctionExpression *ParserImpl::ParseArrowFunctionExpressionBody(ArrowF funcNode = AllocNode( ir::FunctionSignature(typeParamDecl, std::move(desc->params), returnTypeAnnotation), body, - arrowFunctionContext->Flags(), false, context_.GetLanguge()); + arrowFunctionContext->Flags(), false, context_.GetLanguage()); funcNode->SetRange({desc->startLoc, endLoc}); auto *arrowFuncNode = AllocNode(Allocator(), funcNode); @@ -1587,6 +1588,26 @@ void ParserImpl::ValidateUpdateExpression(ir::Expression *returnExpression, bool } } +ir::Expression *ParserImpl::SetupChainExpr(ir::Expression *const top, lexer::SourcePosition startLoc) +{ + auto expr = top; + while (expr->IsTSNonNullExpression()) { + expr = expr->AsTSNonNullExpression()->Expr(); + } + auto chainParent = expr->Parent(); + + lexer::SourcePosition endLoc = expr->End(); + auto chain = AllocNode(expr); + chain->SetRange({startLoc, endLoc}); + + if (expr == top) { + return chain; + } + chainParent->AsTSNonNullExpression()->SetExpr(chain); + chain->SetParent(chainParent); + return top; +} + ir::Expression *ParserImpl::ParseMemberExpression(bool ignoreCallExpression, ExpressionParseFlags flags) { bool isAsync = lexer_->GetToken().IsAsyncModifier(); @@ -1606,8 +1627,17 @@ ir::Expression *ParserImpl::ParseMemberExpression(bool ignoreCallExpression, Exp } } - bool isChainExpression = false; - returnExpression = ParsePostPrimaryExpression(returnExpression, startLoc, ignoreCallExpression, &isChainExpression); + bool isChainExpression; + ir::Expression *prevExpression; + do { + isChainExpression = false; + prevExpression = returnExpression; + returnExpression = + ParsePostPrimaryExpression(returnExpression, startLoc, ignoreCallExpression, &isChainExpression); + if (isChainExpression) { + returnExpression = SetupChainExpr(returnExpression, startLoc); + } + } while (prevExpression != returnExpression); if (!lexer_->GetToken().NewLine() && lexer::Token::IsUpdateToken(lexer_->GetToken().Type())) { lexer::SourcePosition start = returnExpression->Start(); @@ -1620,12 +1650,6 @@ ir::Expression *ParserImpl::ParseMemberExpression(bool ignoreCallExpression, Exp lexer_->NextToken(); } - if (isChainExpression) { - lexer::SourcePosition endLoc = returnExpression->End(); - returnExpression = AllocNode(returnExpression); - returnExpression->SetRange({startLoc, endLoc}); - } - return returnExpression; } diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 5f4d6b623c1ca9ad05b63236f238f0573b00a73c..675bdf760b447c0d967cfb515457efb033dafe69 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -466,7 +466,11 @@ ir::MethodDefinition *ParserImpl::ParseClassMethod(ClassElementDescriptor *desc, *propEnd = func->End(); func->AddFlag(ir::ScriptFunctionFlags::METHOD); - auto *method = AllocNode(desc->methodKind, propName, funcExpr, desc->modifiers, Allocator(), + + auto *ident = !propName->IsArrowFunctionExpression() && !propName->IsFunctionExpression() + ? propName->Clone(Allocator(), nullptr)->AsExpression() + : propName; + auto *method = AllocNode(desc->methodKind, ident, funcExpr, desc->modifiers, Allocator(), desc->isComputed); method->SetRange(funcExpr->Range()); @@ -569,8 +573,9 @@ ir::ClassElement *ParserImpl::ParseClassStaticBlock() auto *body = AllocNode(Allocator(), std::move(statements)); auto *func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, - ir::ScriptFunctionFlags::EXPRESSION | ir::ScriptFunctionFlags::STATIC_BLOCK, - ir::ModifierFlags::STATIC, false, context_.GetLanguge()); + ir::ScriptFunction::ScriptFunctionData { + ir::ScriptFunctionFlags::EXPRESSION | ir::ScriptFunctionFlags::STATIC_BLOCK, + ir::ModifierFlags::STATIC, false, context_.GetLanguage()}); auto *funcExpr = AllocNode(func); auto *staticBlock = AllocNode(funcExpr, Allocator()); @@ -656,7 +661,7 @@ ir::MethodDefinition *ParserImpl::BuildImplicitConstructor(ir::ClassDefinitionMo auto *func = AllocNode(ir::FunctionSignature(nullptr, std::move(params), nullptr), body, ir::ScriptFunctionFlags::CONSTRUCTOR | ir::ScriptFunctionFlags::IMPLICIT_SUPER_CALL_NEEDED, - false, context_.GetLanguge()); + false, context_.GetLanguage()); auto *funcExpr = AllocNode(func); auto *key = AllocNode("constructor", Allocator()); @@ -665,7 +670,8 @@ ir::MethodDefinition *ParserImpl::BuildImplicitConstructor(ir::ClassDefinitionMo func->SetIdent(key); } - auto *ctor = AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, key, funcExpr, + auto *ctor = AllocNode(ir::MethodDefinitionKind::CONSTRUCTOR, + key->Clone(Allocator(), nullptr)->AsExpression(), funcExpr, ir::ModifierFlags::NONE, Allocator(), false); ctor->SetRange({startLoc, lexer_->GetToken().End()}); @@ -763,7 +769,7 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(ir::ClassDefinitionModifie ArenaVector implements(Allocator()->Adapter()); auto *classDefinition = AllocNode( privateBinding.View(), identNode, nullptr, superTypeParams, std::move(implements), ctor, superClass, - std::move(properties), modifiers, flags, GetContext().GetLanguge()); + std::move(properties), modifiers, flags, GetContext().GetLanguage()); classDefinition->SetRange(bodyRange); @@ -912,7 +918,7 @@ ir::ScriptFunction *ParserImpl::ParseFunction(ParserStatus newStatus) functionContext.AddFlag(throw_marker); auto *funcNode = AllocNode(std::move(signature), body, functionContext.Flags(), - isDeclare && letDeclare, context_.GetLanguge()); + isDeclare && letDeclare, context_.GetLanguage()); funcNode->SetRange({startLoc, endLoc}); return funcNode; diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 7939cd0fcf620e89a85d817ce0037f15cc1137c2..392a01c61d7b1d6f2b465003e85f7f1a9ce85d9e 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -232,6 +232,7 @@ protected: void ValidateUpdateExpression(ir::Expression *returnExpression, bool isChainExpression); ir::Expression *ParseMemberExpression(bool ignoreCallExpression = false, ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS); + ir::Expression *SetupChainExpr(ir::Expression *const top, lexer::SourcePosition startLoc); ir::MetaProperty *ParsePotentialNewTarget(); void CheckInvalidDestructuring(const ir::AstNode *object) const; void ValidateParenthesizedExpression(ir::Expression *lhsExpression); diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 4386ff754fa662041883a3db460aa90a65220c0f..7caf884e8fed4c13255a428fa775bbae6f8e4161 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -170,10 +170,6 @@ static ir::ModifierFlags E2pToIrModifierFlags(es2panda_ModifierFlags e2pFlags) irFlags |= (e2pFlags & ES2PANDA_MODIFIER_FUNCTIONAL) != 0 ? ir::ModifierFlags::FUNCTIONAL : ir::ModifierFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_MODIFIER_IN) != 0 ? ir::ModifierFlags::IN : ir::ModifierFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_MODIFIER_OUT) != 0 ? ir::ModifierFlags::OUT : ir::ModifierFlags::NONE; - irFlags |= (e2pFlags & ES2PANDA_MODIFIER_NULL_ASSIGNABLE) != 0 ? ir::ModifierFlags::NULL_ASSIGNABLE - : ir::ModifierFlags::NONE; - irFlags |= (e2pFlags & ES2PANDA_MODIFIER_UNDEFINED_ASSIGNABLE) != 0 ? ir::ModifierFlags::UNDEFINED_ASSIGNABLE - : ir::ModifierFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_MODIFIER_EXPORT) != 0 ? ir::ModifierFlags::EXPORT : ir::ModifierFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_MODIFIER_SETTER) != 0 ? ir::ModifierFlags::SETTER : ir::ModifierFlags::NONE; irFlags |= (e2pFlags & ES2PANDA_MODIFIER_DEFAULT_EXPORT) != 0 ? ir::ModifierFlags::DEFAULT_EXPORT @@ -239,11 +235,6 @@ static es2panda_ModifierFlags IrToE2pModifierFlags(ir::ModifierFlags irFlags) (irFlags & ir::ModifierFlags::IN) != 0 ? e2pFlags | ES2PANDA_MODIFIER_IN : e2pFlags); e2pFlags = static_cast( (irFlags & ir::ModifierFlags::OUT) != 0 ? e2pFlags | ES2PANDA_MODIFIER_OUT : e2pFlags); - e2pFlags = static_cast( - (irFlags & ir::ModifierFlags::NULL_ASSIGNABLE) != 0 ? e2pFlags | ES2PANDA_MODIFIER_NULL_ASSIGNABLE : e2pFlags); - e2pFlags = static_cast((irFlags & ir::ModifierFlags::UNDEFINED_ASSIGNABLE) != 0 - ? e2pFlags | ES2PANDA_MODIFIER_UNDEFINED_ASSIGNABLE - : e2pFlags); e2pFlags = static_cast( (irFlags & ir::ModifierFlags::EXPORT) != 0 ? e2pFlags | ES2PANDA_MODIFIER_EXPORT : e2pFlags); e2pFlags = static_cast( @@ -1091,6 +1082,7 @@ extern "C" void BlockStatementAddStatement(es2panda_AstNode *ast, es2panda_AstNo auto *node = reinterpret_cast(ast)->AsBlockStatement(); auto *stmt = reinterpret_cast(statement)->AsBlockStatement(); node->Statements().push_back(stmt); + stmt->SetParent(node); } extern "C" es2panda_AstNode *CreateCallExpression(es2panda_Context *context, es2panda_AstNode *callee, @@ -1833,8 +1825,7 @@ extern "C" es2panda_AstNode *CreateNewArrayInstanceExpression(es2panda_Context * auto *irTyperef = reinterpret_cast(typeReference)->AsExpression()->AsTypeNode(); auto *irDim = reinterpret_cast(dimension)->AsExpression(); - return reinterpret_cast( - allocator->New(allocator, irTyperef, irDim)); + return reinterpret_cast(allocator->New(irTyperef, irDim)); } extern "C" es2panda_AstNode *NewArrayInstanceExpressionTypeReference(es2panda_AstNode *ast) @@ -2023,8 +2014,8 @@ extern "C" es2panda_AstNode *CreateScriptFunction(es2panda_Context *context, es2 auto irModifierFlags = E2pToIrModifierFlags(modifierFlags); ir::FunctionSignature sig(irTypeParams, std::move(irParams), irReturnTypeAnnotation); - auto func = allocator->New(std::move(sig), nullptr, irFunctionFlags, irModifierFlags, isDeclare, - Language::FromString("ets").value()); + auto func = allocator->New( + std::move(sig), nullptr, ir::ScriptFunction::ScriptFunctionData {irFunctionFlags, irModifierFlags, isDeclare}); return reinterpret_cast(func); } diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index c28f1e708bb70b292dd0eea0e7751f6a3b7150be..b8bf2793ca5db767f7d3c53413e2dda73f3ff34c 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -74,8 +74,6 @@ enum es2panda_ModifierFlags { ES2PANDA_MODIFIER_IN = 1U << 17U, ES2PANDA_MODIFIER_OUT = 1U << 18U, ES2PANDA_MODIFIER_INTERNAL = 1U << 19U, - ES2PANDA_MODIFIER_NULL_ASSIGNABLE = 1U << 20U, - ES2PANDA_MODIFIER_UNDEFINED_ASSIGNABLE = 1U << 21U, ES2PANDA_MODIFIER_EXPORT = 1U << 22U, ES2PANDA_MODIFIER_SETTER = 1U << 23U, ES2PANDA_MODIFIER_DEFAULT_EXPORT = 1U << 24U, diff --git a/ets2panda/test/compiler/ets/FunctionType1-expected.txt b/ets2panda/test/compiler/ets/FunctionType1-expected.txt index eb64020f40e49445ed82f79f28fa02782d538428..a62c8dd85d60ae17e7e06f6baa860ffc9336f53d 100644 --- a/ets2panda/test/compiler/ets/FunctionType1-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType1-expected.txt @@ -1001,4 +1001,4 @@ } } } -TypeError: Type '(a: int, b: int) => int' cannot be assigned to type '(a: int, b: int) => void' [FunctionType1.ets:24:12] +TypeError: Type '(a: int, b: int) => int' cannot be assigned to type '(p1: Int, p2: Int) => void' [FunctionType1.ets:24:12] diff --git a/ets2panda/test/compiler/ets/FunctionType3-expected.txt b/ets2panda/test/compiler/ets/FunctionType3-expected.txt index bbb4c6e27b15eea2054e80a1da9798db1abe9305..0d0d88e229b078e339a18c8a16becd16b3ed2448 100644 --- a/ets2panda/test/compiler/ets/FunctionType3-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType3-expected.txt @@ -809,4 +809,4 @@ } } } -TypeError: Type 'string' is not compatible with type 'int' at index 2 [FunctionType3.ets:23:16] +TypeError: Type 'string' is not compatible with type 'Int' at index 2 [FunctionType3.ets:23:16] diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt index f0c0cc7404ab428b7655774467d15325faa452dd..ad85786f3fd4f9f22ba79c54c104b6e74c9ddc33 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_non_nullish-expected.txt @@ -395,42 +395,212 @@ } }, "right": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "arr", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 33 - }, - "end": { - "line": 19, - "column": 36 + "type": "BlockExpression", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "init": { + "type": "Identifier", + "name": "arr", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 41 + } } - } - }, - "property": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 19, - "column": 39 + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "ConditionalExpression", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NullLiteral", + "value": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": { + "type": "MemberExpression", + "object": { + "type": "TSNonNullExpression", + "expression": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 39 + }, + "end": { + "line": 19, + "column": 40 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } }, - "end": { - "line": 19, - "column": 40 + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, - "computed": true, - "optional": true, + ], "loc": { "start": { "line": 19, - "column": 33 + "column": 5 }, "end": { "line": 19, @@ -621,13 +791,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 19, @@ -635,21 +830,24 @@ }, "end": { "line": 19, - "column": 18 + "column": 20 } } }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 20 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 30 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -657,7 +855,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 30 } } }, @@ -670,7 +868,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 30 } } } @@ -709,4 +907,4 @@ } } } -TypeError: The type of the object reference must be a nullish array or Record type [array_indexing_with_chaining_non_nullish.ets:19:33] +TypeError: Bad operand type, the operand of the non-nullish expression must be a nullish type [array_indexing_with_chaining_non_nullish.ets:19:33] diff --git a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt index d57bb4ddb5328082d29cbb6e3810a73d733160ec..8c0f16fc9294c096c39997a44a5fc46e1fde85bb 100644 --- a/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_with_chaining_nullish-expected.txt @@ -395,42 +395,212 @@ } }, "right": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "arr", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 33 - }, - "end": { - "line": 19, - "column": 36 + "type": "BlockExpression", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "init": { + "type": "Identifier", + "name": "arr", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 41 + } } - } - }, - "property": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 19, - "column": 39 + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "ConditionalExpression", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NullLiteral", + "value": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": { + "type": "MemberExpression", + "object": { + "type": "TSNonNullExpression", + "expression": { + "type": "Identifier", + "name": "gensym$_2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "property": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 19, + "column": 39 + }, + "end": { + "line": 19, + "column": 40 + } + } + }, + "computed": true, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 33 + }, + "end": { + "line": 19, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } }, - "end": { - "line": 19, - "column": 40 + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, - "computed": true, - "optional": true, + ], "loc": { "start": { "line": 19, - "column": 33 + "column": 5 }, "end": { "line": 19, @@ -531,15 +701,40 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, "loc": { "start": { "line": 18, @@ -547,32 +742,35 @@ }, "end": { "line": 18, - "column": 17 + "column": 18 } } }, "loc": { "start": { "line": 18, - "column": 11 + "column": 20 }, "end": { "line": 18, - "column": 18 + "column": 21 } } }, - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 18 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 26 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -580,7 +778,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 26 } } }, @@ -593,7 +791,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 26 } } }, @@ -621,13 +819,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 19, @@ -635,21 +858,24 @@ }, "end": { "line": 19, - "column": 18 + "column": 20 } } }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 20 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 30 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -657,7 +883,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 30 } } }, @@ -670,7 +896,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 30 } } } diff --git a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt index 771737bbd842586c93500fb0d517c443542c50f9..411717b9276b312ae7199b629d59468f0e135cee 100644 --- a/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt +++ b/ets2panda/test/compiler/ets/array_indexing_without_chaining_nullish-expected.txt @@ -531,15 +531,40 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, "loc": { "start": { "line": 18, @@ -547,32 +572,35 @@ }, "end": { "line": 18, - "column": 17 + "column": 18 } } }, "loc": { "start": { "line": 18, - "column": 11 + "column": 20 }, "end": { "line": 18, - "column": 18 + "column": 21 } } }, - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 18 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 26 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -580,7 +608,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 26 } } }, @@ -593,7 +621,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 26 } } }, @@ -621,13 +649,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 19, @@ -635,21 +688,24 @@ }, "end": { "line": 19, - "column": 18 + "column": 20 } } }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 20 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 30 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -657,7 +713,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 30 } } }, @@ -670,7 +726,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 30 } } } @@ -709,4 +765,4 @@ } } } -TypeError: The type of the object reference must be a non-nullish array or Record type [array_indexing_without_chaining_nullish.ets:19:33] +TypeError: Value is possibly nullish. [array_indexing_without_chaining_nullish.ets:19:33] diff --git a/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt index 0f8108b11a032fbee82ee649c1665fbd4958aaf8..c7850cf501a93b66180fc312dff5d78b97d77bb4 100644 --- a/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt +++ b/ets2panda/test/compiler/ets/etsObjectToString0-expected.txt @@ -366,63 +366,91 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 12 + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } }, - "end": { - "line": 19, - "column": 13 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSPrimitiveType", + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], "loc": { "start": { "line": 19, - "column": 14 + "column": 13 }, "end": { "line": 19, - "column": 17 + "column": 18 } } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 19, - "column": 13 + "column": 12 }, "end": { "line": 19, - "column": 18 + "column": 19 } } }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 19 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -430,7 +458,7 @@ }, "end": { "line": 19, - "column": 19 + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt index da2b83b6cf7eb52623f4da056a18bca863a8dc47..0507ee41669805fd3167cd6861246b8e1c681a08 100644 --- a/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt +++ b/ets2panda/test/compiler/ets/etsObjectToString1-expected.txt @@ -422,63 +422,91 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 12 + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } }, - "end": { - "line": 19, - "column": 13 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSPrimitiveType", + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], "loc": { "start": { "line": 19, - "column": 14 + "column": 13 }, "end": { "line": 19, - "column": 17 + "column": 18 } } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 19, - "column": 13 + "column": 12 }, "end": { "line": 19, - "column": 18 + "column": 19 } } }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 19 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -486,7 +514,7 @@ }, "end": { "line": 19, - "column": 19 + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt index 34fb46d94ac0fcd7e70f712fd1c35b922f77306e..9ea9341127a6044fc986360650cf3377adb41fe4 100644 --- a/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt +++ b/ets2panda/test/compiler/ets/etsObjectToString2-expected.txt @@ -342,35 +342,60 @@ "expression": false, "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 19 + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 20 + } + } }, - "end": { - "line": 18, - "column": 20 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, "loc": { "start": { "line": 18, @@ -378,55 +403,58 @@ }, "end": { "line": 18, - "column": 27 + "column": 28 } } - }, - "loc": { - "start": { - "line": 18, - "column": 21 - }, - "end": { - "line": 18, - "column": 28 - } } - }, + ], "loc": { "start": { "line": 18, - "column": 21 + "column": 20 }, "end": { "line": 18, "column": 28 } } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 29 + } } - ], + }, "loc": { "start": { "line": 18, - "column": 20 + "column": 19 }, "end": { "line": 18, - "column": 28 + "column": 29 } } }, - "loc": { - "start": { - "line": 18, - "column": 19 - }, - "end": { - "line": 18, - "column": 29 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 33 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -434,7 +462,7 @@ }, "end": { "line": 18, - "column": 29 + "column": 33 } } }, @@ -450,63 +478,91 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 12 + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 13 + } + } }, - "end": { - "line": 19, - "column": 13 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSPrimitiveType", + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], "loc": { "start": { "line": 19, - "column": 14 + "column": 13 }, "end": { "line": 19, - "column": 17 + "column": 18 } } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 19 + } } - ], + }, "loc": { "start": { "line": 19, - "column": 13 + "column": 12 }, "end": { "line": 19, - "column": 18 + "column": 19 } } }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 19 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -514,7 +570,7 @@ }, "end": { "line": 19, - "column": 19 + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt index a92c60328361986dbfda8e79c83c01c8505f41a3..88b19e630767b6639fd7c0229703a624d34ffdfd 100644 --- a/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt +++ b/ets2panda/test/compiler/ets/etsObjectToString4-expected.txt @@ -370,20 +370,6 @@ } } }, - "value": { - "type": "NumberLiteral", - "value": 5, - "loc": { - "start": { - "line": 18, - "column": 29 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, "accessibility": "public", "static": true, "readonly": false, @@ -391,21 +377,49 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSFunctionType", - "params": [], - "returnType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 18, - "column": 15 + "type": "ETSUnionType", + "types": [ + { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 18 + } + } }, - "end": { - "line": 18, - "column": 18 + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 18 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 26 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -413,7 +427,7 @@ }, "end": { "line": 18, - "column": 18 + "column": 26 } } }, @@ -426,7 +440,7 @@ }, "end": { "line": 18, - "column": 30 + "column": 26 } } } @@ -465,4 +479,4 @@ } } } -TypeError: Type 'int' cannot be assigned to type '() => int' [etsObjectToString4.ets:18:29] +TypeError: Type 'int' cannot be assigned to type '() => Int|null' [etsObjectToString4.ets:18:29] diff --git a/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt index c96da27d618f81a70d048be77af960f521cdfca5..5cb850892e0b5ccaf27d662f4dac66c9a6bfc114 100644 --- a/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt +++ b/ets2panda/test/compiler/ets/etsObjectToString5-expected.txt @@ -449,35 +449,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 57 + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 58 + } + } }, - "end": { - "line": 18, - "column": 58 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 59 + }, + "end": { + "line": 18, + "column": 66 + } + } + }, "loc": { "start": { "line": 18, @@ -485,55 +510,58 @@ }, "end": { "line": 18, - "column": 65 + "column": 66 } } - }, - "loc": { - "start": { - "line": 18, - "column": 59 - }, - "end": { - "line": 18, - "column": 66 - } } - }, + ], "loc": { "start": { "line": 18, - "column": 59 + "column": 58 }, "end": { "line": 18, "column": 66 } } + }, + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 67 + } } - ], + }, "loc": { "start": { "line": 18, - "column": 58 + "column": 57 }, "end": { "line": 18, - "column": 66 + "column": 67 } } }, - "loc": { - "start": { - "line": 18, - "column": 57 - }, - "end": { - "line": 18, - "column": 67 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 67 + }, + "end": { + "line": 18, + "column": 71 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -541,7 +569,7 @@ }, "end": { "line": 18, - "column": 67 + "column": 71 } } }, @@ -617,64 +645,90 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSFunctionType", - "params": [ + "type": "ETSUnionType", + "types": [ { - "type": "ETSParameterExpression", - "name": { - "type": "Identifier", - "name": "y", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 11 + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } }, - "end": { - "line": 18, - "column": 12 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSPrimitiveType", + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 16 + } + } + } + ], "loc": { "start": { "line": 18, - "column": 13 + "column": 12 }, "end": { "line": 18, - "column": 16 + "column": 17 } } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 18, - "column": 12 + "column": 11 }, "end": { "line": 18, - "column": 17 + "column": 18 } } }, + "decorators": [], "loc": { "start": { "line": 18, - "column": 11 + "column": 9 }, "end": { "line": 18, @@ -685,70 +739,97 @@ "loc": { "start": { "line": 18, - "column": 11 + "column": 9 }, "end": { "line": 18, "column": 18 } } - }, - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 9 - }, - "end": { - "line": 18, - "column": 18 - } } - }, - "loc": { - "start": { - "line": 18, - "column": 9 - }, - "end": { - "line": 18, - "column": 18 - } - } - } - ], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 22 + ], + "returnType": { + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 29 + } + } }, - "end": { - "line": 18, - "column": 23 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ { - "type": "ETSPrimitiveType", + "type": "ETSNullType", "loc": { "start": { "line": 18, - "column": 24 + "column": 29 }, "end": { "line": 18, - "column": 27 + "column": 33 } } } @@ -756,36 +837,39 @@ "loc": { "start": { "line": 18, - "column": 23 + "column": 22 }, "end": { "line": 18, - "column": 28 + "column": 33 } } }, "loc": { "start": { "line": 18, - "column": 22 + "column": 7 }, "end": { "line": 18, - "column": 29 + "column": 33 } } }, - "loc": { - "start": { - "line": 18, - "column": 22 - }, - "end": { - "line": 18, - "column": 29 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 39 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -793,7 +877,7 @@ }, "end": { "line": 18, - "column": 29 + "column": 39 } } }, @@ -845,4 +929,4 @@ } } } -TypeError: Type '(y: A) => A|null' cannot be assigned to type '(y: A) => A|null' [etsObjectToString5.ets:18:42] +TypeError: Type '(y: A) => A|null' cannot be assigned to type '(p1: A) => A|null|null' [etsObjectToString5.ets:18:42] diff --git a/ets2panda/test/compiler/ets/function_subtyping_1-expected.txt b/ets2panda/test/compiler/ets/function_subtyping_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca68775f5e7c4bc5c7f56237ce0df6d0a6b5102e --- /dev/null +++ b/ets2panda/test/compiler/ets/function_subtyping_1-expected.txt @@ -0,0 +1,997 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 18 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 54 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 48 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 41 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 39 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } +} diff --git a/ets2panda/test/parser/ets/cast_expressions6.ets b/ets2panda/test/compiler/ets/function_subtyping_1.ets similarity index 87% rename from ets2panda/test/parser/ets/cast_expressions6.ets rename to ets2panda/test/compiler/ets/function_subtyping_1.ets index 8338c1150552c014ae35a6b95e936f0b7e402ba0..0b2ffc867e56034fb79f90e76dc9f53a784492f0 100644 --- a/ets2panda/test/parser/ets/cast_expressions6.ets +++ b/ets2panda/test/compiler/ets/function_subtyping_1.ets @@ -13,7 +13,9 @@ * limitations under the License. */ +class A {} +class B extends A {} + function main(): void { - let Object_: Object = null as Object; - let Int_ = Object_ as Int; -} + let x: (p: B) => A = (p: A): B => { return new B() } +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/function_subtyping_2-expected.txt b/ets2panda/test/compiler/ets/function_subtyping_2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..b49902e0360b9b56bf1c02ddee4587169b8038a5 --- /dev/null +++ b/ets2panda/test/compiler/ets/function_subtyping_2-expected.txt @@ -0,0 +1,998 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 18 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 54 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 48 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 41 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 39 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } +} +TypeError: Type '(p: A) => A' cannot be assigned to type '(p1: B) => B' [function_subtyping_2.ets:20:26] diff --git a/ets2panda/test/compiler/ets/function_subtyping_2.ets b/ets2panda/test/compiler/ets/function_subtyping_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..64860a92b84090397682ef3b294ceaf8f3238e5e --- /dev/null +++ b/ets2panda/test/compiler/ets/function_subtyping_2.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +class B extends A {} + +function main(): void { + let x: (p: B) => B = (p: A): A => { return new B() } +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/function_subtyping_3-expected.txt b/ets2panda/test/compiler/ets/function_subtyping_3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..55e50a03bc5ecb3b7575a869ff4157abd02441b0 --- /dev/null +++ b/ets2panda/test/compiler/ets/function_subtyping_3-expected.txt @@ -0,0 +1,998 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 13 + }, + "end": { + "line": 20, + "column": 18 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 22 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 25 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 10 + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "p", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 34 + }, + "end": { + "line": 20, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 52 + }, + "end": { + "line": 20, + "column": 54 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 48 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 41 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 39 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 26 + }, + "end": { + "line": 20, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 57 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } +} +TypeError: Type '(p: B) => B' cannot be assigned to type '(p1: A) => A' [function_subtyping_3.ets:20:26] diff --git a/ets2panda/test/compiler/ets/function_subtyping_3.ets b/ets2panda/test/compiler/ets/function_subtyping_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e57a855ae937b56c005189c6c52c898c43b5c5b --- /dev/null +++ b/ets2panda/test/compiler/ets/function_subtyping_3.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +class B extends A {} + +function main(): void { + let x: (p: A) => A = (p: B): B => { return new B() } +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt index 426576fd85849a298c4f58b43c1357fa07867b15..296c4beeb9dace3f6bb746d00d21f96ba51fbf1a 100644 --- a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt +++ b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt @@ -1256,35 +1256,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 31 + "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 + } + } }, - "end": { - "line": 29, - "column": 36 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 29, @@ -1292,55 +1317,58 @@ }, "end": { "line": 29, - "column": 38 + "column": 39 } } - }, - "loc": { - "start": { - "line": 29, - "column": 37 - }, - "end": { - "line": 29, - "column": 39 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 37 + "column": 36 }, "end": { "line": 29, "column": 39 } } + }, + "loc": { + "start": { + "line": 29, + "column": 31 + }, + "end": { + "line": 29, + "column": 41 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 36 + "column": 31 }, "end": { "line": 29, - "column": 39 + "column": 41 } } }, - "loc": { - "start": { - "line": 29, - "column": 31 - }, - "end": { - "line": 29, - "column": 41 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 29, + "column": 42 + }, + "end": { + "line": 29, + "column": 46 + } } } - }, + ], "loc": { "start": { "line": 29, @@ -1348,7 +1376,7 @@ }, "end": { "line": 29, - "column": 41 + "column": 46 } } }, @@ -1360,7 +1388,7 @@ }, "end": { "line": 29, - "column": 41 + "column": 46 } } }, @@ -1371,7 +1399,7 @@ }, "end": { "line": 29, - "column": 41 + "column": 46 } } }, @@ -2032,13 +2060,38 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 31, @@ -2046,21 +2099,24 @@ }, "end": { "line": 31, - "column": 44 + "column": 46 } } }, - "loc": { - "start": { - "line": 31, - "column": 43 - }, - "end": { - "line": 31, - "column": 46 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 31, + "column": 47 + }, + "end": { + "line": 31, + "column": 51 + } } } - }, + ], "loc": { "start": { "line": 31, @@ -2068,7 +2124,7 @@ }, "end": { "line": 31, - "column": 46 + "column": 51 } } }, @@ -2080,7 +2136,7 @@ }, "end": { "line": 31, - "column": 46 + "column": 51 } } }, @@ -2091,7 +2147,7 @@ }, "end": { "line": 31, - "column": 46 + "column": 51 } } }, @@ -2737,35 +2793,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 33, - "column": 45 + "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 + } + } }, - "end": { - "line": 33, - "column": 50 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 33, @@ -2773,55 +2854,58 @@ }, "end": { "line": 33, - "column": 52 + "column": 53 } } - }, - "loc": { - "start": { - "line": 33, - "column": 51 - }, - "end": { - "line": 33, - "column": 53 - } } - }, + ], "loc": { "start": { "line": 33, - "column": 51 + "column": 50 }, "end": { "line": 33, "column": 53 } } + }, + "loc": { + "start": { + "line": 33, + "column": 45 + }, + "end": { + "line": 33, + "column": 55 + } } - ], + }, "loc": { "start": { "line": 33, - "column": 50 + "column": 45 }, "end": { "line": 33, - "column": 53 + "column": 55 } } }, - "loc": { - "start": { - "line": 33, - "column": 45 - }, - "end": { - "line": 33, - "column": 55 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 33, + "column": 56 + }, + "end": { + "line": 33, + "column": 60 + } } } - }, + ], "loc": { "start": { "line": 33, @@ -2829,7 +2913,7 @@ }, "end": { "line": 33, - "column": 55 + "column": 60 } } }, @@ -2841,7 +2925,7 @@ }, "end": { "line": 33, - "column": 55 + "column": 60 } } }, @@ -2852,7 +2936,7 @@ }, "end": { "line": 33, - "column": 55 + "column": 60 } } }, @@ -3110,35 +3194,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 53 + "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 + } + } }, - "end": { - "line": 34, - "column": 58 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 34, @@ -3146,55 +3255,58 @@ }, "end": { "line": 34, - "column": 60 + "column": 61 } } - }, - "loc": { - "start": { - "line": 34, - "column": 59 - }, - "end": { - "line": 34, - "column": 61 - } } - }, + ], "loc": { "start": { "line": 34, - "column": 59 + "column": 58 }, "end": { "line": 34, "column": 61 } } + }, + "loc": { + "start": { + "line": 34, + "column": 53 + }, + "end": { + "line": 34, + "column": 63 + } } - ], + }, "loc": { "start": { "line": 34, - "column": 58 + "column": 53 }, "end": { "line": 34, - "column": 61 + "column": 63 } } }, - "loc": { - "start": { - "line": 34, - "column": 53 - }, - "end": { - "line": 34, - "column": 63 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 34, + "column": 64 + }, + "end": { + "line": 34, + "column": 68 + } } } - }, + ], "loc": { "start": { "line": 34, @@ -3202,7 +3314,7 @@ }, "end": { "line": 34, - "column": 63 + "column": 68 } } }, @@ -3214,7 +3326,7 @@ }, "end": { "line": 34, - "column": 63 + "column": 68 } } }, @@ -3225,7 +3337,7 @@ }, "end": { "line": 34, - "column": 63 + "column": 68 } } }, @@ -3591,13 +3703,38 @@ "type": "Identifier", "name": "val", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 39, @@ -3605,21 +3742,24 @@ }, "end": { "line": 39, - "column": 39 + "column": 41 } } }, - "loc": { - "start": { - "line": 39, - "column": 38 - }, - "end": { - "line": 39, - "column": 41 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 39, + "column": 42 + }, + "end": { + "line": 39, + "column": 46 + } } } - }, + ], "loc": { "start": { "line": 39, @@ -3627,7 +3767,7 @@ }, "end": { "line": 39, - "column": 41 + "column": 46 } } }, @@ -3639,7 +3779,7 @@ }, "end": { "line": 39, - "column": 41 + "column": 46 } } }, @@ -3650,7 +3790,7 @@ }, "end": { "line": 39, - "column": 41 + "column": 46 } } } @@ -11488,35 +11628,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Listt", - "decorators": [], - "loc": { - "start": { - "line": 141, - "column": 47 + "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 + } + } }, - "end": { - "line": 141, - "column": 52 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 141, @@ -11524,55 +11689,58 @@ }, "end": { "line": 141, - "column": 54 + "column": 55 } } - }, - "loc": { - "start": { - "line": 141, - "column": 53 - }, - "end": { - "line": 141, - "column": 55 - } } - }, + ], "loc": { "start": { "line": 141, - "column": 53 + "column": 52 }, "end": { "line": 141, "column": 55 } } + }, + "loc": { + "start": { + "line": 141, + "column": 47 + }, + "end": { + "line": 141, + "column": 57 + } } - ], + }, "loc": { "start": { "line": 141, - "column": 52 + "column": 47 }, "end": { "line": 141, - "column": 55 + "column": 57 } } }, - "loc": { - "start": { - "line": 141, - "column": 47 - }, - "end": { - "line": 141, - "column": 57 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 141, + "column": 58 + }, + "end": { + "line": 141, + "column": 62 + } } } - }, + ], "loc": { "start": { "line": 141, @@ -11580,7 +11748,7 @@ }, "end": { "line": 141, - "column": 57 + "column": 62 } } }, @@ -13260,13 +13428,38 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 156, @@ -13274,21 +13467,24 @@ }, "end": { "line": 156, - "column": 60 + "column": 62 } } }, - "loc": { - "start": { - "line": 156, - "column": 59 - }, - "end": { - "line": 156, - "column": 62 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 156, + "column": 63 + }, + "end": { + "line": 156, + "column": 67 + } } } - }, + ], "loc": { "start": { "line": 156, @@ -13296,7 +13492,7 @@ }, "end": { "line": 156, - "column": 62 + "column": 67 } } }, @@ -15190,35 +15386,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "ArrayAsListt", - "decorators": [], - "loc": { - "start": { - "line": 178, - "column": 60 + "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 + } + } }, - "end": { - "line": 178, - "column": 72 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 178, @@ -15226,55 +15447,58 @@ }, "end": { "line": 178, - "column": 74 + "column": 75 } } - }, - "loc": { - "start": { - "line": 178, - "column": 73 - }, - "end": { - "line": 178, - "column": 75 - } } - }, + ], "loc": { "start": { "line": 178, - "column": 73 + "column": 72 }, "end": { "line": 178, "column": 75 } } + }, + "loc": { + "start": { + "line": 178, + "column": 60 + }, + "end": { + "line": 178, + "column": 77 + } } - ], + }, "loc": { "start": { "line": 178, - "column": 72 + "column": 60 }, "end": { "line": 178, - "column": 75 + "column": 77 } } }, - "loc": { - "start": { - "line": 178, - "column": 60 - }, - "end": { - "line": 178, - "column": 77 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 178, + "column": 78 + }, + "end": { + "line": 178, + "column": 82 + } } } - }, + ], "loc": { "start": { "line": 178, @@ -15282,7 +15506,7 @@ }, "end": { "line": 178, - "column": 77 + "column": 82 } } }, @@ -16976,35 +17200,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "ArrayAsListt", - "decorators": [], - "loc": { - "start": { - "line": 198, - "column": 68 + "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 + } + } }, - "end": { - "line": 198, - "column": 80 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 198, @@ -17012,55 +17261,58 @@ }, "end": { "line": 198, - "column": 82 + "column": 83 } } - }, - "loc": { - "start": { - "line": 198, - "column": 81 - }, - "end": { - "line": 198, - "column": 83 - } } - }, + ], "loc": { "start": { "line": 198, - "column": 81 + "column": 80 }, "end": { "line": 198, "column": 83 } } + }, + "loc": { + "start": { + "line": 198, + "column": 68 + }, + "end": { + "line": 198, + "column": 85 + } } - ], + }, "loc": { "start": { "line": 198, - "column": 80 + "column": 68 }, "end": { "line": 198, - "column": 83 + "column": 85 } } }, - "loc": { - "start": { - "line": 198, - "column": 68 - }, - "end": { - "line": 198, - "column": 85 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 198, + "column": 86 + }, + "end": { + "line": 198, + "column": 90 + } } } - }, + ], "loc": { "start": { "line": 198, @@ -17068,7 +17320,7 @@ }, "end": { "line": 198, - "column": 85 + "column": 90 } } }, diff --git a/ets2panda/test/compiler/ets/generic_variance_1-expected.txt b/ets2panda/test/compiler/ets/generic_variance_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..abef87ab4c4cf75d73e08363d4d783627af2c92e --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_1-expected.txt @@ -0,0 +1,1973 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "in": true, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "out": true, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x1", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 24, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 24, + "column": 8 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 8 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x2", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 16 + }, + "end": { + "line": 24, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 16 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 16 + }, + "end": { + "line": 24, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 15 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 25 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 27 + }, + "end": { + "line": 24, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 25 + }, + "end": { + "line": 24, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 25 + }, + "end": { + "line": 24, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 26, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 26, + "column": 8 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 26, + "column": 8 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x3", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 16 + }, + "end": { + "line": 26, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 15 + }, + "end": { + "line": 26, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 26, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 26, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 26, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 27 + }, + "end": { + "line": 26, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 25 + }, + "end": { + "line": 26, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 27, + "column": 8 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 9 + }, + "end": { + "line": 27, + "column": 8 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 26, + "column": 5 + }, + "end": { + "line": 27, + "column": 8 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x4", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 27, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 16 + }, + "end": { + "line": 27, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 16 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 16 + }, + "end": { + "line": 27, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 15 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 27, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 27, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 25 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 28 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 28 + }, + "end": { + "line": 27, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 28 + }, + "end": { + "line": 27, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 27 + }, + "end": { + "line": 27, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 25 + }, + "end": { + "line": 27, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 25 + }, + "end": { + "line": 27, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 28, + "column": 2 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 28, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 28, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 28, + "column": 2 + } + } +} diff --git a/ets2panda/test/compiler/ets/generic_variance_1.ets b/ets2panda/test/compiler/ets/generic_variance_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..dee382251f27b4b4bf54bd1301d60bd5101e1333 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_1.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +class B extends A {} + +class A1 {} +class A2 {} + +function main(): void { + let x1: A1 = new A1() + let x2: A1 = new A1() + + let x3: A2 = new A2() + let x4: A2 = new A2() +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generic_variance_2-expected.txt b/ets2panda/test/compiler/ets/generic_variance_2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..227f565f389428b1045e0e534beb36cd377f33cd --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_2-expected.txt @@ -0,0 +1,1218 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "in": true, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "out": true, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x1", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } +} +TypeError: Type 'A1' cannot be assigned to type 'A1' [generic_variance_2.ets:23:21] diff --git a/ets2panda/test/compiler/ets/generic_variance_2.ets b/ets2panda/test/compiler/ets/generic_variance_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..a3bc04b21106d940201239715b1df566b8c54390 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_2.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +class B extends A {} + +class A1 {} +class A2 {} + +function main(): void { + let x1: A1 = new A1() +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generic_variance_3-expected.txt b/ets2panda/test/compiler/ets/generic_variance_3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3bb1aa6f553a968fa3737fc7131a53455a5471f3 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_3-expected.txt @@ -0,0 +1,1218 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "in": true, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "out": true, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x1", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } +} +TypeError: Type 'A2' cannot be assigned to type 'A2' [generic_variance_3.ets:23:21] diff --git a/ets2panda/test/compiler/ets/generic_variance_3.ets b/ets2panda/test/compiler/ets/generic_variance_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b61cf93020ab46e12e7ff3529e19a89aeced8a0 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_3.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +class B extends A {} + +class A1 {} +class A2 {} + +function main(): void { + let x1: A2 = new A2() +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generic_variance_4-expected.txt b/ets2panda/test/compiler/ets/generic_variance_4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..a3be0edfd53c7b33af22adc6758d875021534c77 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_4-expected.txt @@ -0,0 +1,1178 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "in": true, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "out": true, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x2", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } +} +TypeError: Type 'A1' cannot be assigned to type 'A1' [generic_variance_4.ets:23:21] diff --git a/ets2panda/test/compiler/ets/generic_variance_4.ets b/ets2panda/test/compiler/ets/generic_variance_4.ets new file mode 100644 index 0000000000000000000000000000000000000000..bc985183024577a560e50aa367a96c900c579be2 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_4.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +class B {} + +class A1 {} +class A2 {} + +function main(): void { + let x2: A1 = new A1() +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generic_variance_5-expected.txt b/ets2panda/test/compiler/ets/generic_variance_5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..07709a6558f4d84f09ff4d90575315dab782d991 --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_5-expected.txt @@ -0,0 +1,1178 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "in": true, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 9 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "out": true, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 19 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "x4", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 15 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 16 + }, + "end": { + "line": 23, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 23, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 27 + }, + "end": { + "line": 23, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 25 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 23 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } +} +TypeError: Type 'A2' cannot be assigned to type 'A2' [generic_variance_5.ets:23:21] diff --git a/ets2panda/test/compiler/ets/generic_variance_5.ets b/ets2panda/test/compiler/ets/generic_variance_5.ets new file mode 100644 index 0000000000000000000000000000000000000000..9e351ad8f9ad8cd90c7a8bb0514f9d2122b4917c --- /dev/null +++ b/ets2panda/test/compiler/ets/generic_variance_5.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A {} +class B {} + +class A1 {} +class A2 {} + +function main(): void { + let x4: A2 = new A2() +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt index 2e60845699d3825ea362f56d7c1df654d0fdef7b..de5ede9edc96d36831b4b88597ca445956c961f5 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt @@ -111,35 +111,60 @@ "expression": false, "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 16 + "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 + } + } }, - "end": { - "line": 17, - "column": 19 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "U", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 17, @@ -147,55 +172,58 @@ }, "end": { "line": 17, - "column": 21 + "column": 22 } } - }, - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 22 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 20 + "column": 19 }, "end": { "line": 17, "column": 22 } } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 19 + "column": 16 }, "end": { "line": 17, - "column": 22 + "column": 24 } } }, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 24 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 29 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -203,7 +231,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 29 } } }, @@ -630,35 +658,60 @@ "expression": false, "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], - "loc": { - "start": { - "line": 25, - "column": 12 + "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 + } + } }, - "end": { - "line": 25, - "column": 13 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 25, @@ -666,55 +719,58 @@ }, "end": { "line": 25, - "column": 15 + "column": 16 } } - }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 16 - } } - }, + ], "loc": { "start": { "line": 25, - "column": 14 + "column": 13 }, "end": { "line": 25, "column": 16 } } + }, + "loc": { + "start": { + "line": 25, + "column": 12 + }, + "end": { + "line": 25, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 25, - "column": 13 + "column": 12 }, "end": { "line": 25, - "column": 16 + "column": 18 } } }, - "loc": { - "start": { - "line": 25, - "column": 12 - }, - "end": { - "line": 25, - "column": 18 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 25, + "column": 19 + }, + "end": { + "line": 25, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 25, @@ -722,7 +778,7 @@ }, "end": { "line": 25, - "column": 18 + "column": 23 } } }, @@ -849,35 +905,60 @@ "expression": false, "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 12 + "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 + } + } }, - "end": { - "line": 29, - "column": 15 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 29, @@ -885,55 +966,58 @@ }, "end": { "line": 29, - "column": 17 + "column": 18 } } - }, - "loc": { - "start": { - "line": 29, - "column": 16 - }, - "end": { - "line": 29, - "column": 18 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 16 + "column": 15 }, "end": { "line": 29, "column": 18 } } + }, + "loc": { + "start": { + "line": 29, + "column": 12 + }, + "end": { + "line": 29, + "column": 20 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 15 + "column": 12 }, "end": { "line": 29, - "column": 18 + "column": 20 } } }, - "loc": { - "start": { - "line": 29, - "column": 12 - }, - "end": { - "line": 29, - "column": 20 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 29, + "column": 21 + }, + "end": { + "line": 29, + "column": 25 + } } } - }, + ], "loc": { "start": { "line": 29, @@ -941,7 +1025,7 @@ }, "end": { "line": 29, - "column": 20 + "column": 25 } } }, @@ -1477,35 +1561,60 @@ "type": "Identifier", "name": "p1", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Foo", - "decorators": [], - "loc": { - "start": { - "line": 35, - "column": 13 + "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 + } + } }, - "end": { - "line": 35, - "column": 16 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 35, @@ -1513,55 +1622,58 @@ }, "end": { "line": 35, - "column": 23 + "column": 24 } } - }, - "loc": { - "start": { - "line": 35, - "column": 17 - }, - "end": { - "line": 35, - "column": 24 - } } - }, + ], "loc": { "start": { "line": 35, - "column": 17 + "column": 16 }, "end": { "line": 35, "column": 24 } } + }, + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 26 + } } - ], + }, "loc": { "start": { "line": 35, - "column": 16 + "column": 13 }, "end": { "line": 35, - "column": 24 + "column": 26 } } }, - "loc": { - "start": { - "line": 35, - "column": 13 - }, - "end": { - "line": 35, - "column": 26 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 35, + "column": 27 + }, + "end": { + "line": 35, + "column": 31 + } } } - }, + ], "loc": { "start": { "line": 35, @@ -1569,7 +1681,7 @@ }, "end": { "line": 35, - "column": 26 + "column": 31 } } }, @@ -2226,46 +2338,91 @@ "callee": { "type": "MemberExpression", "object": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "p2", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 10 + "type": "TSNonNullExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "TSNonNullExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p2", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 12 + } + } }, - "end": { - "line": 37, - "column": 12 + "property": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 18 + } } - } - }, - "property": { - "type": "Identifier", - "name": "value", - "decorators": [], + }, + "property": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 19 + }, + "end": { + "line": 37, + "column": 22 + } + } + }, + "computed": false, + "optional": false, "loc": { "start": { "line": 37, - "column": 13 + "column": 10 }, "end": { "line": 37, - "column": 18 + "column": 22 } } }, - "computed": false, + "arguments": [], "optional": false, "loc": { "start": { @@ -2274,27 +2431,10 @@ }, "end": { "line": 37, - "column": 18 - } - } - }, - "property": { - "type": "Identifier", - "name": "bar", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 19 - }, - "end": { - "line": 37, - "column": 22 + "column": 24 } } }, - "computed": false, - "optional": false, "loc": { "start": { "line": 37, @@ -2302,11 +2442,26 @@ }, "end": { "line": 37, - "column": 22 + "column": 25 + } + } + }, + "property": { + "type": "Identifier", + "name": "baz", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 29 } } }, - "arguments": [], + "computed": false, "optional": false, "loc": { "start": { @@ -2315,26 +2470,11 @@ }, "end": { "line": 37, - "column": 24 - } - } - }, - "property": { - "type": "Identifier", - "name": "baz", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 25 - }, - "end": { - "line": 37, - "column": 28 + "column": 29 } } }, - "computed": false, + "arguments": [], "optional": false, "loc": { "start": { @@ -2343,12 +2483,10 @@ }, "end": { "line": 37, - "column": 28 + "column": 31 } } }, - "arguments": [], - "optional": false, "loc": { "start": { "line": 37, @@ -2356,7 +2494,7 @@ }, "end": { "line": 37, - "column": 30 + "column": 32 } } }, @@ -2367,11 +2505,11 @@ "loc": { "start": { "line": 37, - "column": 31 + "column": 33 }, "end": { "line": 37, - "column": 35 + "column": 37 } } }, @@ -2384,7 +2522,7 @@ }, "end": { "line": 37, - "column": 35 + "column": 37 } } }, @@ -2404,33 +2542,33 @@ "loc": { "start": { "line": 37, - "column": 36 + "column": 38 }, "end": { "line": 37, - "column": 42 + "column": 44 } } }, "loc": { "start": { "line": 37, - "column": 36 + "column": 38 }, "end": { "line": 37, - "column": 43 + "column": 45 } } }, "loc": { "start": { "line": 37, - "column": 36 + "column": 38 }, "end": { "line": 37, - "column": 43 + "column": 45 } } } @@ -2438,11 +2576,11 @@ "loc": { "start": { "line": 37, - "column": 35 + "column": 37 }, "end": { "line": 37, - "column": 43 + "column": 45 } } }, @@ -2453,7 +2591,7 @@ }, "end": { "line": 37, - "column": 45 + "column": 47 } } }, @@ -2464,7 +2602,7 @@ }, "end": { "line": 37, - "column": 45 + "column": 47 } } }, @@ -2475,7 +2613,7 @@ }, "end": { "line": 37, - "column": 46 + "column": 48 } } } diff --git a/ets2panda/test/compiler/ets/generics_instantiation_2.ets b/ets2panda/test/compiler/ets/generics_instantiation_2.ets index 057e2ee92c8bc17aa29919a7278d7ad2570a38d1..ba89e953183905b267c3bab600c33b8e60991b73 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_2.ets +++ b/ets2panda/test/compiler/ets/generics_instantiation_2.ets @@ -34,5 +34,5 @@ class A { function bar(p: Foo): void { let p1: Foo | null = p.then(); let p2: Foo>> = new Foo>>(); - p1 = p2.value.bar().baz().then(); + p1 = p2.value.bar()!.baz()!.then(); } diff --git a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt index 58ac0be4cfac4fecd88f525982db39725aebebcf..adac48e1f28ccc2445b6bac986a23423739a7204 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt @@ -1199,35 +1199,60 @@ "expression": false, "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 31, - "column": 12 + "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 + } + } }, - "end": { - "line": 31, - "column": 13 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 31, @@ -1235,55 +1260,58 @@ }, "end": { "line": 31, - "column": 15 + "column": 16 } } - }, - "loc": { - "start": { - "line": 31, - "column": 14 - }, - "end": { - "line": 31, - "column": 16 - } } - }, + ], "loc": { "start": { "line": 31, - "column": 14 + "column": 13 }, "end": { "line": 31, "column": 16 } } + }, + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 18 + } } - ], + }, "loc": { "start": { "line": 31, - "column": 13 + "column": 12 }, "end": { "line": 31, - "column": 16 + "column": 18 } } }, - "loc": { - "start": { - "line": 31, - "column": 12 - }, - "end": { - "line": 31, - "column": 18 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 31, + "column": 19 + }, + "end": { + "line": 31, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 31, @@ -1291,7 +1319,7 @@ }, "end": { "line": 31, - "column": 18 + "column": 23 } } }, @@ -1668,35 +1696,60 @@ } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 37, - "column": 21 + "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 + } + } }, - "end": { - "line": 37, - "column": 22 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "U", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 37, @@ -1704,55 +1757,58 @@ }, "end": { "line": 37, - "column": 24 + "column": 25 } } - }, - "loc": { - "start": { - "line": 37, - "column": 23 - }, - "end": { - "line": 37, - "column": 25 - } } - }, + ], "loc": { "start": { "line": 37, - "column": 23 + "column": 22 }, "end": { "line": 37, "column": 25 } } + }, + "loc": { + "start": { + "line": 37, + "column": 21 + }, + "end": { + "line": 37, + "column": 27 + } } - ], + }, "loc": { "start": { "line": 37, - "column": 22 + "column": 21 }, "end": { "line": 37, - "column": 25 + "column": 27 } } }, - "loc": { - "start": { - "line": 37, - "column": 21 - }, - "end": { - "line": 37, - "column": 27 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 37, + "column": 28 + }, + "end": { + "line": 37, + "column": 32 + } } } - }, + ], "loc": { "start": { "line": 37, @@ -1760,7 +1816,7 @@ }, "end": { "line": 37, - "column": 27 + "column": 32 } } }, @@ -2757,35 +2813,60 @@ "type": "Identifier", "name": "p1", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 48, - "column": 13 + "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 + } + } }, - "end": { - "line": 48, - "column": 14 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 48, @@ -2793,55 +2874,58 @@ }, "end": { "line": 48, - "column": 21 + "column": 22 } } - }, - "loc": { - "start": { - "line": 48, - "column": 15 - }, - "end": { - "line": 48, - "column": 22 - } } - }, + ], "loc": { "start": { "line": 48, - "column": 15 + "column": 14 }, "end": { "line": 48, "column": 22 } } + }, + "loc": { + "start": { + "line": 48, + "column": 13 + }, + "end": { + "line": 48, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 48, - "column": 14 + "column": 13 }, "end": { "line": 48, - "column": 22 + "column": 24 } } }, - "loc": { - "start": { - "line": 48, - "column": 13 - }, - "end": { - "line": 48, - "column": 24 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 48, + "column": 25 + }, + "end": { + "line": 48, + "column": 29 + } } } - }, + ], "loc": { "start": { "line": 48, @@ -2849,7 +2933,7 @@ }, "end": { "line": 48, - "column": 24 + "column": 29 } } }, @@ -3776,19 +3860,49 @@ "callee": { "type": "MemberExpression", "object": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { + "type": "TSNonNullExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "CallExpression", + "callee": { "type": "MemberExpression", "object": { - "type": "Identifier", - "name": "p2", - "decorators": [], + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p2", + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 10 + }, + "end": { + "line": 51, + "column": 12 + } + } + }, + "property": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 13 + }, + "end": { + "line": 51, + "column": 18 + } + } + }, + "computed": false, + "optional": false, "loc": { "start": { "line": 51, @@ -3796,22 +3910,22 @@ }, "end": { "line": 51, - "column": 12 + "column": 18 } } }, "property": { "type": "Identifier", - "name": "value", + "name": "bar", "decorators": [], "loc": { "start": { "line": 51, - "column": 13 + "column": 19 }, "end": { "line": 51, - "column": 18 + "column": 22 } } }, @@ -3822,28 +3936,13 @@ "line": 51, "column": 10 }, - "end": { - "line": 51, - "column": 18 - } - } - }, - "property": { - "type": "Identifier", - "name": "bar", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 19 - }, "end": { "line": 51, "column": 22 } } }, - "computed": false, + "arguments": [], "optional": false, "loc": { "start": { @@ -3852,39 +3951,39 @@ }, "end": { "line": 51, - "column": 22 + "column": 24 + } + } + }, + "property": { + "type": "Identifier", + "name": "baz", + "decorators": [], + "loc": { + "start": { + "line": 51, + "column": 25 + }, + "end": { + "line": 51, + "column": 28 } } }, - "arguments": [], + "computed": false, "optional": false, "loc": { "start": { "line": 51, "column": 10 }, - "end": { - "line": 51, - "column": 24 - } - } - }, - "property": { - "type": "Identifier", - "name": "baz", - "decorators": [], - "loc": { - "start": { - "line": 51, - "column": 25 - }, "end": { "line": 51, "column": 28 } } }, - "computed": false, + "arguments": [], "optional": false, "loc": { "start": { @@ -3893,12 +3992,10 @@ }, "end": { "line": 51, - "column": 28 + "column": 30 } } }, - "arguments": [], - "optional": false, "loc": { "start": { "line": 51, @@ -3906,7 +4003,7 @@ }, "end": { "line": 51, - "column": 30 + "column": 31 } } }, @@ -3917,11 +4014,11 @@ "loc": { "start": { "line": 51, - "column": 31 + "column": 32 }, "end": { "line": 51, - "column": 35 + "column": 36 } } }, @@ -3934,7 +4031,7 @@ }, "end": { "line": 51, - "column": 35 + "column": 36 } } }, @@ -3952,33 +4049,33 @@ "loc": { "start": { "line": 51, - "column": 48 + "column": 49 }, "end": { "line": 51, - "column": 54 + "column": 55 } } }, "loc": { "start": { "line": 51, - "column": 48 + "column": 49 }, "end": { "line": 51, - "column": 55 + "column": 56 } } }, "loc": { "start": { "line": 51, - "column": 48 + "column": 49 }, "end": { "line": 51, - "column": 55 + "column": 56 } } }, @@ -3986,11 +4083,11 @@ "loc": { "start": { "line": 51, - "column": 44 + "column": 45 }, "end": { "line": 51, - "column": 57 + "column": 58 } } } @@ -4010,33 +4107,33 @@ "loc": { "start": { "line": 51, - "column": 36 + "column": 37 }, "end": { "line": 51, - "column": 42 + "column": 43 } } }, "loc": { "start": { "line": 51, - "column": 36 + "column": 37 }, "end": { "line": 51, - "column": 43 + "column": 44 } } }, "loc": { "start": { "line": 51, - "column": 36 + "column": 37 }, "end": { "line": 51, - "column": 43 + "column": 44 } } } @@ -4044,11 +4141,11 @@ "loc": { "start": { "line": 51, - "column": 35 + "column": 36 }, "end": { "line": 51, - "column": 43 + "column": 44 } } }, @@ -4059,7 +4156,7 @@ }, "end": { "line": 51, - "column": 57 + "column": 58 } } }, @@ -4070,7 +4167,7 @@ }, "end": { "line": 51, - "column": 57 + "column": 58 } } }, @@ -4081,7 +4178,7 @@ }, "end": { "line": 51, - "column": 58 + "column": 59 } } }, @@ -4110,19 +4207,49 @@ "callee": { "type": "MemberExpression", "object": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { - "type": "CallExpression", - "callee": { - "type": "MemberExpression", - "object": { + "type": "TSNonNullExpression", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "CallExpression", + "callee": { "type": "MemberExpression", "object": { - "type": "Identifier", - "name": "p2", - "decorators": [], + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p2", + "decorators": [], + "loc": { + "start": { + "line": 52, + "column": 10 + }, + "end": { + "line": 52, + "column": 12 + } + } + }, + "property": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 52, + "column": 13 + }, + "end": { + "line": 52, + "column": 18 + } + } + }, + "computed": false, + "optional": false, "loc": { "start": { "line": 52, @@ -4130,22 +4257,22 @@ }, "end": { "line": 52, - "column": 12 + "column": 18 } } }, "property": { "type": "Identifier", - "name": "value", + "name": "bar", "decorators": [], "loc": { "start": { "line": 52, - "column": 13 + "column": 19 }, "end": { "line": 52, - "column": 18 + "column": 22 } } }, @@ -4156,28 +4283,13 @@ "line": 52, "column": 10 }, - "end": { - "line": 52, - "column": 18 - } - } - }, - "property": { - "type": "Identifier", - "name": "bar", - "decorators": [], - "loc": { - "start": { - "line": 52, - "column": 19 - }, "end": { "line": 52, "column": 22 } } }, - "computed": false, + "arguments": [], "optional": false, "loc": { "start": { @@ -4186,39 +4298,39 @@ }, "end": { "line": 52, - "column": 22 + "column": 24 + } + } + }, + "property": { + "type": "Identifier", + "name": "baz", + "decorators": [], + "loc": { + "start": { + "line": 52, + "column": 25 + }, + "end": { + "line": 52, + "column": 28 } } }, - "arguments": [], + "computed": false, "optional": false, "loc": { "start": { "line": 52, "column": 10 }, - "end": { - "line": 52, - "column": 24 - } - } - }, - "property": { - "type": "Identifier", - "name": "baz", - "decorators": [], - "loc": { - "start": { - "line": 52, - "column": 25 - }, "end": { "line": 52, "column": 28 } } }, - "computed": false, + "arguments": [], "optional": false, "loc": { "start": { @@ -4227,12 +4339,10 @@ }, "end": { "line": 52, - "column": 28 + "column": 30 } } }, - "arguments": [], - "optional": false, "loc": { "start": { "line": 52, @@ -4240,7 +4350,7 @@ }, "end": { "line": 52, - "column": 30 + "column": 31 } } }, @@ -4251,11 +4361,11 @@ "loc": { "start": { "line": 52, - "column": 31 + "column": 32 }, "end": { "line": 52, - "column": 35 + "column": 36 } } }, @@ -4268,7 +4378,7 @@ }, "end": { "line": 52, - "column": 35 + "column": 36 } } }, @@ -4286,33 +4396,33 @@ "loc": { "start": { "line": 52, - "column": 48 + "column": 49 }, "end": { "line": 52, - "column": 54 + "column": 55 } } }, "loc": { "start": { "line": 52, - "column": 48 + "column": 49 }, "end": { "line": 52, - "column": 55 + "column": 56 } } }, "loc": { "start": { "line": 52, - "column": 48 + "column": 49 }, "end": { "line": 52, - "column": 55 + "column": 56 } } }, @@ -4320,11 +4430,11 @@ "loc": { "start": { "line": 52, - "column": 44 + "column": 45 }, "end": { "line": 52, - "column": 57 + "column": 58 } } } @@ -4344,33 +4454,33 @@ "loc": { "start": { "line": 52, - "column": 36 + "column": 37 }, "end": { "line": 52, - "column": 42 + "column": 43 } } }, "loc": { "start": { "line": 52, - "column": 36 + "column": 37 }, "end": { "line": 52, - "column": 43 + "column": 44 } } }, "loc": { "start": { "line": 52, - "column": 36 + "column": 37 }, "end": { "line": 52, - "column": 43 + "column": 44 } } } @@ -4378,11 +4488,11 @@ "loc": { "start": { "line": 52, - "column": 35 + "column": 36 }, "end": { "line": 52, - "column": 43 + "column": 44 } } }, @@ -4393,7 +4503,7 @@ }, "end": { "line": 52, - "column": 57 + "column": 58 } } }, @@ -4404,7 +4514,7 @@ }, "end": { "line": 52, - "column": 57 + "column": 58 } } }, @@ -4415,7 +4525,7 @@ }, "end": { "line": 52, - "column": 58 + "column": 59 } } }, @@ -4428,35 +4538,60 @@ "type": "Identifier", "name": "p3", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], - "loc": { - "start": { - "line": 54, - "column": 13 + "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 + } + } }, - "end": { - "line": 54, - "column": 14 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 54, @@ -4464,55 +4599,58 @@ }, "end": { "line": 54, - "column": 21 + "column": 22 } } - }, - "loc": { - "start": { - "line": 54, - "column": 15 - }, - "end": { - "line": 54, - "column": 22 - } } - }, + ], "loc": { "start": { "line": 54, - "column": 15 + "column": 14 }, "end": { "line": 54, "column": 22 } } + }, + "loc": { + "start": { + "line": 54, + "column": 13 + }, + "end": { + "line": 54, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 54, - "column": 14 + "column": 13 }, "end": { "line": 54, - "column": 22 + "column": 24 } } }, - "loc": { - "start": { - "line": 54, - "column": 13 - }, - "end": { - "line": 54, - "column": 24 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 54, + "column": 25 + }, + "end": { + "line": 54, + "column": 29 + } } } - }, + ], "loc": { "start": { "line": 54, @@ -4520,7 +4658,7 @@ }, "end": { "line": 54, - "column": 24 + "column": 29 } } }, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_4.ets b/ets2panda/test/compiler/ets/generics_instantiation_4.ets index fd4163839b72e518614fc87f1963c7eede579c5a..a26f452d3fae5deb5c372275e119e4d090c44d14 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_4.ets +++ b/ets2panda/test/compiler/ets/generics_instantiation_4.ets @@ -48,8 +48,8 @@ function bar(p: C): void { let p1: C | null = p.then(new Object()); let p2: C>> = new C>>(); p1 = p2.then(new Object()); - p1 = p2.value.bar().baz().then(new Object()); - p1 = p2.value.bar().baz().then(new Object()); + p1 = p2.value.bar().baz()!.then(new Object()); + p1 = p2.value.bar().baz()!.then(new Object()); let p3: C | null = p.then(new Double()); let p4: C>> = new C>>(); diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index c0fb2875eaa35752d68d03bccc91b4ba8fc0d2a9..100cdc5d9da37ed85518a0c2b428f0fb57b24619 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -398,4 +398,4 @@ } } } -TypeError: Type '(v: double, u: double) => double' cannot be assigned to type '(a: int, b: int) => void' [identifierReference2.ets:16:34] +TypeError: Type '(v: double, u: double) => double' cannot be assigned to type '(p1: Int, p2: Int) => void' [identifierReference2.ets:16:34] diff --git a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt index a17df28bb337b0d74b04879a1bb4e4a8890a0fd9..d7fafa4654f0fea7e5ee572646ba22800f3d2d44 100644 --- a/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaExpressionWithoutBlockStatementDifferentType-expected.txt @@ -515,4 +515,4 @@ } } } -TypeError: Type '() => String' cannot be assigned to type '() => int' [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] +TypeError: Type '() => String' cannot be assigned to type '() => Int' [lambdaExpressionWithoutBlockStatementDifferentType.ets:17:28] diff --git a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt index 22b2a3c2f299f5bea005e116a3f713eede8dbe30..1e358988d23eb51fd4051bddf93911fcf3861fb8 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction3-expected.txt @@ -642,4 +642,4 @@ } } } -TypeError: Type '(b: int) => void' cannot be assigned to type '(b: String) => void' [lambdaFunction3.ets:18:39] +TypeError: Type '(b: int) => void' cannot be assigned to type '(p1: String) => void' [lambdaFunction3.ets:18:39] diff --git a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt index 5737ced2b4eaa0c3cb5614fd7a5e7a02b82a8e43..b82ab2b93218d0c24802219361d0308fec15622e 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt @@ -1705,4 +1705,4 @@ } } } -TypeError: Type 'string' is not compatible with type 'int' at index 2 [lambdaFunction5.ets:35:17] +TypeError: Type 'string' is not compatible with type 'Int' at index 2 [lambdaFunction5.ets:35:17] diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt index 545b1715cf2905525d1f37c516f466f808038e42..21e87c7c1a01ed9ce6bec01f0688ec0e8f443579 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening-expected.txt @@ -289,7 +289,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "B", + "name": "A", "decorators": [], "loc": { "start": { @@ -354,9 +354,49 @@ { "type": "ReturnStatement", "argument": { - "type": "Identifier", - "name": "a", - "decorators": [], + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 41 + }, + "end": { + "line": 22, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 41 + }, + "end": { + "line": 22, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 41 + }, + "end": { + "line": 22, + "column": 44 + } + } + }, + "arguments": [], "loc": { "start": { "line": 22, @@ -364,7 +404,7 @@ }, "end": { "line": 22, - "column": 38 + "column": 44 } } }, @@ -375,7 +415,7 @@ }, "end": { "line": 22, - "column": 38 + "column": 44 } } } @@ -387,7 +427,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 44 } } }, @@ -398,7 +438,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 44 } } }, @@ -409,7 +449,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 44 } } }, @@ -432,33 +472,33 @@ "loc": { "start": { "line": 22, - "column": 48 + "column": 53 }, "end": { "line": 22, - "column": 49 + "column": 54 } } }, "loc": { "start": { "line": 22, - "column": 48 + "column": 53 }, "end": { "line": 22, - "column": 50 + "column": 55 } } }, "loc": { "start": { "line": 22, - "column": 48 + "column": 53 }, "end": { "line": 22, - "column": 50 + "column": 55 } } }, @@ -466,22 +506,22 @@ "loc": { "start": { "line": 22, - "column": 44 + "column": 49 }, "end": { "line": 22, - "column": 50 + "column": 55 } } }, "loc": { "start": { "line": 22, - "column": 44 + "column": 49 }, "end": { "line": 22, - "column": 50 + "column": 55 } } } @@ -497,18 +537,18 @@ "loc": { "start": { "line": 22, - "column": 54 + "column": 59 }, "end": { "line": 22, - "column": 55 + "column": 60 } } }, "loc": { "start": { "line": 22, - "column": 54 + "column": 59 }, "end": { "line": 23, @@ -519,7 +559,7 @@ "loc": { "start": { "line": 22, - "column": 54 + "column": 59 }, "end": { "line": 23, @@ -530,7 +570,7 @@ "loc": { "start": { "line": 22, - "column": 43 + "column": 48 }, "end": { "line": 23, @@ -545,7 +585,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 44 } } }, @@ -556,7 +596,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 44 } } } @@ -569,7 +609,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 44 } } }, @@ -595,7 +635,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "A", + "name": "B", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets index cb90f223b65492d77d5f230dba1fa2e5a2097eaf..2d5c270007400772d8aa797f644c91391f04ca04 100644 --- a/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets +++ b/ets2panda/test/compiler/ets/lambda_infer_type/lambda_cast_infer_type_widening.ets @@ -19,7 +19,7 @@ class A { class B extends A { main () { - let a = (a : B) => { return a} as (a : A) => A - let expected : (a : A) => A = a + let a = (a : A) => { return new B } as (a : A) => A + let expected : (a : B) => A = a } } diff --git a/ets2panda/test/compiler/ets/launch_expression-expected.txt b/ets2panda/test/compiler/ets/launch_expression-expected.txt index e0578ae16196361e968129658537280fb2e39d55..8ff5489b259909294c3c9d3bad377d09f4eeb11e 100644 --- a/ets2panda/test/compiler/ets/launch_expression-expected.txt +++ b/ets2panda/test/compiler/ets/launch_expression-expected.txt @@ -19,35 +19,60 @@ } }, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 10 + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Promise", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 17 + } + } }, - "end": { - "line": 20, - "column": 17 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 22 + } + } + }, "loc": { "start": { "line": 20, @@ -55,55 +80,58 @@ }, "end": { "line": 20, - "column": 21 + "column": 22 } } - }, - "loc": { - "start": { - "line": 20, - "column": 18 - }, - "end": { - "line": 20, - "column": 22 - } } - }, + ], "loc": { "start": { "line": 20, - "column": 18 + "column": 17 }, "end": { "line": 20, "column": 22 } } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 24 + } } - ], + }, "loc": { "start": { "line": 20, - "column": 17 + "column": 10 }, "end": { "line": 20, - "column": 22 + "column": 24 } } }, - "loc": { - "start": { - "line": 20, - "column": 10 - }, - "end": { - "line": 20, - "column": 24 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 29 + } } } - }, + ], "loc": { "start": { "line": 20, @@ -111,7 +139,7 @@ }, "end": { "line": 20, - "column": 24 + "column": 29 } } }, @@ -2367,39 +2395,52 @@ "callee": { "type": "MemberExpression", "object": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "p", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 27 - }, - "end": { - "line": 38, - "column": 28 + "type": "TSNonNullExpression", + "expression": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 27 + }, + "end": { + "line": 38, + "column": 28 + } } - } - }, - "property": { - "type": "Identifier", - "name": "i", - "decorators": [], + }, + "property": { + "type": "Identifier", + "name": "i", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 29 + }, + "end": { + "line": 38, + "column": 30 + } + } + }, + "computed": true, + "optional": false, "loc": { "start": { "line": 38, - "column": 29 + "column": 27 }, "end": { "line": 38, - "column": 30 + "column": 31 } } }, - "computed": true, - "optional": false, "loc": { "start": { "line": 38, @@ -2407,7 +2448,7 @@ }, "end": { "line": 38, - "column": 31 + "column": 32 } } }, @@ -2418,11 +2459,11 @@ "loc": { "start": { "line": 38, - "column": 32 + "column": 33 }, "end": { "line": 38, - "column": 47 + "column": 48 } } }, @@ -2435,7 +2476,7 @@ }, "end": { "line": 38, - "column": 47 + "column": 48 } } }, @@ -2448,7 +2489,7 @@ }, "end": { "line": 38, - "column": 49 + "column": 50 } } }, @@ -2461,11 +2502,11 @@ "loc": { "start": { "line": 38, - "column": 52 + "column": 53 }, "end": { "line": 38, - "column": 53 + "column": 54 } } }, @@ -2476,11 +2517,11 @@ "loc": { "start": { "line": 38, - "column": 54 + "column": 55 }, "end": { "line": 38, - "column": 55 + "column": 56 } } }, @@ -2489,11 +2530,11 @@ "loc": { "start": { "line": 38, - "column": 52 + "column": 53 }, "end": { "line": 38, - "column": 56 + "column": 57 } } }, @@ -2504,7 +2545,7 @@ }, "end": { "line": 38, - "column": 56 + "column": 57 } } }, @@ -2515,7 +2556,7 @@ }, "end": { "line": 38, - "column": 56 + "column": 57 } } }, @@ -2526,7 +2567,7 @@ }, "end": { "line": 38, - "column": 56 + "column": 57 } } }, @@ -2537,7 +2578,7 @@ }, "end": { "line": 38, - "column": 57 + "column": 58 } } } diff --git a/ets2panda/test/compiler/ets/launch_expression.ets b/ets2panda/test/compiler/ets/launch_expression.ets index 362b63db1131de6c6281bfb347729ca6e7c963fe..2579ef8b01aae838ea1e0c338feec605536fac9e 100644 --- a/ets2panda/test/compiler/ets/launch_expression.ets +++ b/ets2panda/test/compiler/ets/launch_expression.ets @@ -35,7 +35,7 @@ function ufib(n: int) : Int { } let result = 0 for (let i = 0; i < count; ++i) { - result = result + p[i].awaitResolution() * a[i]; + result = result + p[i]!.awaitResolution() * a[i]; } return result; } diff --git a/ets2panda/test/compiler/ets/methodOverrideCovariantReturnType-expected.txt b/ets2panda/test/compiler/ets/methodOverrideCovariantReturnType-expected.txt index 186fa4c37141f593fb820c8dc978c6d5a0388b67..36610c08a0f6982d1fad63bdf19f31ef144a989f 100644 --- a/ets2panda/test/compiler/ets/methodOverrideCovariantReturnType-expected.txt +++ b/ets2panda/test/compiler/ets/methodOverrideCovariantReturnType-expected.txt @@ -2084,4 +2084,3 @@ } } } -TypeError: foo(a: int): C in B cannot override foo(): A in A because overriding return type is not compatible with the other return type. [methodOverrideCovariantReturnType.ets:42:8] diff --git a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt index 218cfffdcb33c7c392be1d8fa7840ee67f888e43..dec6c6ee6e4a619f295a83690ff23611aa38ceff 100644 --- a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt +++ b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable-expected.txt @@ -553,13 +553,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "B", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, "loc": { "start": { "line": 20, @@ -567,21 +592,24 @@ }, "end": { "line": 20, - "column": 16 + "column": 18 } } }, - "loc": { - "start": { - "line": 20, - "column": 15 - }, - "end": { - "line": 20, - "column": 18 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 20, @@ -589,7 +617,7 @@ }, "end": { "line": 20, - "column": 18 + "column": 23 } } } @@ -1012,4 +1040,4 @@ } } } -TypeError: Type 'A' cannot be assigned to type 'A' [n_assignGenericWithNullableTypeParamToNonNullable.ets:21:19] +TypeError: Type 'A' cannot be assigned to type 'A' [n_assignGenericWithNullableTypeParamToNonNullable.ets:20:27] diff --git a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable.ets b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable.ets index 8dab208be01f4e78883dae08af77e7f8022f906a..bbe9f2aa80e7c880b27ccd0ca7dcc9b9745f1368 100644 --- a/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable.ets +++ b/ets2panda/test/compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable.ets @@ -17,6 +17,6 @@ class A {} class B {} function main(): void { - let abn : A = new A(); // should work: non nullable B is the subtype of nullable B + let abn : A = new A(); // should not work: non nullable B is the subtype of nullable B, but T has no variance mark let ab : A = abn; // should not work: nullable B (the type of abn) is not the subtype of non nullable B } diff --git a/ets2panda/test/compiler/ets/n_ensureNotNullArgNotNullable-expected.txt b/ets2panda/test/compiler/ets/n_ensureNotNullArgNotNullable-expected.txt index 91ecb22a02e5f3202b3c163e29017ab67a581a59..7f8f049fe249900b6608bac998cc3f71b79ec2f4 100644 --- a/ets2panda/test/compiler/ets/n_ensureNotNullArgNotNullable-expected.txt +++ b/ets2panda/test/compiler/ets/n_ensureNotNullArgNotNullable-expected.txt @@ -661,4 +661,4 @@ } } } -TypeError: Bad operand type, the operand of the non-null expression must be a nullable type [n_ensureNotNullArgNotNullable.ets:19:3] +TypeError: Bad operand type, the operand of the non-nullish expression must be a nullish type [n_ensureNotNullArgNotNullable.ets:19:3] diff --git a/ets2panda/test/compiler/ets/n_ensureNotNullLocalNotNullable-expected.txt b/ets2panda/test/compiler/ets/n_ensureNotNullLocalNotNullable-expected.txt index 694d785f8faa4f56d0e13b8de7a5c12ec7fa809b..3ea5aa44645d030dba964c9ce97e3b036f5a2e60 100644 --- a/ets2panda/test/compiler/ets/n_ensureNotNullLocalNotNullable-expected.txt +++ b/ets2panda/test/compiler/ets/n_ensureNotNullLocalNotNullable-expected.txt @@ -386,4 +386,4 @@ } } } -TypeError: Bad operand type, the operand of the non-null expression must be a nullable type [n_ensureNotNullLocalNotNullable.ets:18:3] +TypeError: Bad operand type, the operand of the non-nullish expression must be a nullish type [n_ensureNotNullLocalNotNullable.ets:18:3] diff --git a/ets2panda/test/compiler/ets/n_ensureNotNullReturnNotNullable-expected.txt b/ets2panda/test/compiler/ets/n_ensureNotNullReturnNotNullable-expected.txt index 4064670059063b05ec5bbc0b25d0a0a50b6eff98..513c38713cbf5976b36875efa635547bfb189b79 100644 --- a/ets2panda/test/compiler/ets/n_ensureNotNullReturnNotNullable-expected.txt +++ b/ets2panda/test/compiler/ets/n_ensureNotNullReturnNotNullable-expected.txt @@ -547,4 +547,4 @@ } } } -TypeError: Bad operand type, the operand of the non-null expression must be a nullable type [n_ensureNotNullReturnNotNullable.ets:21:3] +TypeError: Bad operand type, the operand of the non-nullish expression must be a nullish type [n_ensureNotNullReturnNotNullable.ets:21:3] diff --git a/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt b/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt index 4a7b6839493dbc97ec772b1c516c8d5e7d83ad1a..7308dc875be6606722abb83ad343a7ff3b1c7c9e 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeInArgNotRef-expected.txt @@ -449,7 +449,35 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSPrimitiveType", + "type": "ETSUnionType", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 28 + } + } + } + ], "loc": { "start": { "line": 21, @@ -457,7 +485,7 @@ }, "end": { "line": 21, - "column": 21 + "column": 28 } } }, @@ -469,7 +497,7 @@ }, "end": { "line": 21, - "column": 21 + "column": 28 } } }, @@ -480,19 +508,44 @@ }, "end": { "line": 21, - "column": 21 + "column": 28 } } } ], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 21, @@ -500,21 +553,24 @@ }, "end": { "line": 21, - "column": 35 + "column": 37 } } }, - "loc": { - "start": { - "line": 21, - "column": 32 - }, - "end": { - "line": 21, - "column": 37 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 38 + }, + "end": { + "line": 21, + "column": 42 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -522,7 +578,7 @@ }, "end": { "line": 21, - "column": 37 + "column": 42 } } }, @@ -639,4 +695,3 @@ } } } -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 0bf5ccb540c0991b880db5fa0874e830b2c6eb63..bbdcfc18e7e525a76a1ad14b93ba9743b3ad7255 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeInReturnNotRef-expected.txt @@ -429,7 +429,35 @@ "expression": false, "params": [], "returnType": { - "type": "ETSPrimitiveType", + "type": "ETSUnionType", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 29 + } + } + } + ], "loc": { "start": { "line": 21, @@ -437,7 +465,7 @@ }, "end": { "line": 21, - "column": 22 + "column": 29 } } }, @@ -553,4 +581,3 @@ } } } -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 c7344bfab70acc69f02189e13a433c2d2018d1b7..4227351dbde0c8c9a151427cf23c0d36aae5774b 100644 --- a/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt +++ b/ets2panda/test/compiler/ets/n_nullableTypeNotRef-expected.txt @@ -214,7 +214,35 @@ "type": "Identifier", "name": "a", "typeAnnotation": { - "type": "ETSPrimitiveType", + "type": "ETSUnionType", + "types": [ + { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], "loc": { "start": { "line": 17, @@ -222,7 +250,7 @@ }, "end": { "line": 17, - "column": 14 + "column": 21 } } }, @@ -345,4 +373,3 @@ } } } -TypeError: Non reference types cannot be nullish. [n_nullableTypeNotRef.ets:17:11] diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt b/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt index f309c04503198af162a59c46ddc98158510b52aa..ec75f9dc3f0e24b608b30ee9f87876c6a49f25f5 100644 --- a/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1-expected.txt @@ -304,13 +304,38 @@ "type": "Identifier", "name": "data", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, "loc": { "start": { "line": 17, @@ -318,21 +343,24 @@ }, "end": { "line": 17, - "column": 12 + "column": 14 } } }, - "loc": { - "start": { - "line": 17, - "column": 11 - }, - "end": { - "line": 17, - "column": 14 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 24 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -340,7 +368,7 @@ }, "end": { "line": 17, - "column": 14 + "column": 24 } } }, @@ -352,7 +380,7 @@ }, "end": { "line": 17, - "column": 14 + "column": 24 } } }, @@ -363,7 +391,7 @@ }, "end": { "line": 17, - "column": 14 + "column": 24 } } }, @@ -381,13 +409,38 @@ "type": "Identifier", "name": "pointer", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "C", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, "loc": { "start": { "line": 18, @@ -395,21 +448,24 @@ }, "end": { "line": 18, - "column": 22 + "column": 24 } } }, - "loc": { - "start": { - "line": 18, - "column": 21 - }, - "end": { - "line": 18, - "column": 24 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 18, + "column": 25 + }, + "end": { + "line": 18, + "column": 34 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -417,7 +473,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 34 } } }, @@ -429,7 +485,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 34 } } }, @@ -440,7 +496,7 @@ }, "end": { "line": 18, - "column": 24 + "column": 34 } } } diff --git a/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt index ffbe88bb73ad6cc0a97b6cd8b1d7fd0cff8c602f..feb9b83c82d52d0a012d68ba79dce8cacf10cffd 100644 --- a/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt +++ b/ets2panda/test/compiler/ets/null_coalescing_generic_1_neg-expected.txt @@ -597,4 +597,4 @@ } } } -TypeError: Type 'Integral' is not compatible with the enclosing method's return type 'T' [null_coalescing_generic_1_neg.ets:18:12] +TypeError: Type 'T|Short' is not compatible with the enclosing method's return type 'T' [null_coalescing_generic_1_neg.ets:18:12] diff --git a/ets2panda/test/compiler/ets/nullableTuple-expected.txt b/ets2panda/test/compiler/ets/nullableTuple-expected.txt index 6cd2174f4a8d7e6d0de225745c01486ca618e50c..eedfa67002a7bc44c0ccfde023b841b0a2611cb8 100644 --- a/ets2panda/test/compiler/ets/nullableTuple-expected.txt +++ b/ets2panda/test/compiler/ets/nullableTuple-expected.txt @@ -145,13 +145,38 @@ } }, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TNumberStringPair", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "TNumberStringPair", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, "loc": { "start": { "line": 17, @@ -159,21 +184,24 @@ }, "end": { "line": 17, - "column": 37 + "column": 38 } } }, - "loc": { - "start": { - "line": 17, - "column": 20 - }, - "end": { - "line": 17, - "column": 38 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 17, + "column": 38 + }, + "end": { + "line": 17, + "column": 47 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -181,7 +209,7 @@ }, "end": { "line": 17, - "column": 38 + "column": 47 } } }, diff --git a/ets2panda/test/compiler/ets/overload_with_generics-expected.txt b/ets2panda/test/compiler/ets/overload_with_generics-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b5703c1493afd528dc17347c6a422110916f61e --- /dev/null +++ b/ets2panda/test/compiler/ets/overload_with_generics-expected.txt @@ -0,0 +1,1209 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 7 + }, + "end": { + "line": 16, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "arg", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 32 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 32 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 32 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 27 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 27 + }, + "end": { + "line": 17, + "column": 35 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 26 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "arg1", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 31 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "arg2", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 41 + }, + "end": { + "line": 18, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 41 + }, + "end": { + "line": 18, + "column": 50 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 52 + }, + "end": { + "line": 18, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 52 + }, + "end": { + "line": 18, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 52 + }, + "end": { + "line": 18, + "column": 58 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "A1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "A2", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 30 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 30 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 57 + }, + "end": { + "line": 18, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 59 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 59 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 2 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 10 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "lll", + "loc": { + "start": { + "line": 22, + "column": 11 + }, + "end": { + "line": 22, + "column": 16 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 7 + }, + "end": { + "line": 23, + "column": 10 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 10 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "lll", + "loc": { + "start": { + "line": 23, + "column": 11 + }, + "end": { + "line": 23, + "column": 16 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 19 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 20 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 13 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 26, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/overload_with_generics.ets b/ets2panda/test/compiler/ets/overload_with_generics.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0c007e32a8c5ff832dc535cd86bee703c13e6b3 --- /dev/null +++ b/ets2panda/test/compiler/ets/overload_with_generics.ets @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http: //www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A { + public static foo(arg: A1): void {} + public static foo(arg1: A1, arg2: A2): void {} +} + +function main(): int { + A.foo("lll") + A.foo("lll", 1) + return 0 +} diff --git a/ets2panda/test/compiler/ets/override16-expected.txt b/ets2panda/test/compiler/ets/override16-expected.txt index b1fa4f9c7e759e54e7a618c444c7222a23ae0ede..cf234349f288e38c4ac38e767197a72ad85eaf39 100644 --- a/ets2panda/test/compiler/ets/override16-expected.txt +++ b/ets2panda/test/compiler/ets/override16-expected.txt @@ -735,4 +735,4 @@ } } } -TypeError: Hiding method is not return-type-substitutable for other method. [override16.ets:23:5] +TypeError: fn(): float in B cannot override fn(): int in A because overridden method is static. [override16.ets:23:5] diff --git a/ets2panda/test/compiler/ets/parenthesizedType-expected.txt b/ets2panda/test/compiler/ets/parenthesizedType-expected.txt index 66ec32d13735169de62634804767afe41114a573..53c7ea8516014379147ec3f96dc8f6c3ecafa37a 100644 --- a/ets2panda/test/compiler/ets/parenthesizedType-expected.txt +++ b/ets2panda/test/compiler/ets/parenthesizedType-expected.txt @@ -358,13 +358,38 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 19, @@ -372,21 +397,24 @@ }, "end": { "line": 19, - "column": 18 + "column": 20 } } }, - "loc": { - "start": { - "line": 19, - "column": 12 - }, - "end": { - "line": 19, - "column": 20 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 24 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -394,7 +422,7 @@ }, "end": { "line": 19, - "column": 20 + "column": 24 } } }, diff --git a/ets2panda/test/compiler/ets/tuple_types_1-expected.txt b/ets2panda/test/compiler/ets/tuple_types_1-expected.txt index 1fa7dad85ccf7b373d40cfabfe8231e8d165d1e1..e2ca72f175d911a84eeebd03220bc04ddadd5197 100644 --- a/ets2panda/test/compiler/ets/tuple_types_1-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_1-expected.txt @@ -6580,736 +6580,6 @@ } } }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "h_var", - "typeAnnotation": { - "type": "ETSTuple", - "types": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "number", - "decorators": [], - "loc": { - "start": { - "line": 75, - "column": 17 - }, - "end": { - "line": 75, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 17 - }, - "end": { - "line": 75, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 17 - }, - "end": { - "line": 75, - "column": 24 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 75, - "column": 25 - }, - "end": { - "line": 75, - "column": 28 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 75, - "column": 30 - }, - "end": { - "line": 75, - "column": 36 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 30 - }, - "end": { - "line": 75, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 30 - }, - "end": { - "line": 75, - "column": 37 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 75, - "column": 38 - }, - "end": { - "line": 75, - "column": 45 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 75, - "column": 47 - }, - "end": { - "line": 75, - "column": 53 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 47 - }, - "end": { - "line": 75, - "column": 54 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 47 - }, - "end": { - "line": 75, - "column": 54 - } - } - } - ], - "spreadType": null, - "loc": { - "start": { - "line": 75, - "column": 16 - }, - "end": { - "line": 75, - "column": 56 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 75, - "column": 9 - }, - "end": { - "line": 75, - "column": 14 - } - } - }, - "init": { - "type": "ArrayExpression", - "elements": [ - { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 75, - "column": 58 - }, - "end": { - "line": 75, - "column": 59 - } - } - }, - { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 75, - "column": 61 - }, - "end": { - "line": 75, - "column": 62 - } - } - }, - { - "type": "StringLiteral", - "value": "asd", - "loc": { - "start": { - "line": 75, - "column": 64 - }, - "end": { - "line": 75, - "column": 69 - } - } - }, - { - "type": "BooleanLiteral", - "value": false, - "loc": { - "start": { - "line": 75, - "column": 71 - }, - "end": { - "line": 75, - "column": 76 - } - } - }, - { - "type": "ETSNewClassInstanceExpression", - "typeReference": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 75, - "column": 82 - }, - "end": { - "line": 75, - "column": 88 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 82 - }, - "end": { - "line": 75, - "column": 89 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 82 - }, - "end": { - "line": 75, - "column": 89 - } - } - }, - "arguments": [], - "loc": { - "start": { - "line": 75, - "column": 78 - }, - "end": { - "line": 75, - "column": 91 - } - } - } - ], - "loc": { - "start": { - "line": 75, - "column": 57 - }, - "end": { - "line": 75, - "column": 91 - } - } - }, - "loc": { - "start": { - "line": 75, - "column": 9 - }, - "end": { - "line": 75, - "column": 91 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 75, - "column": 5 - }, - "end": { - "line": 75, - "column": 92 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "i_var", - "typeAnnotation": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 76, - "column": 16 - }, - "end": { - "line": 76, - "column": 21 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 76, - "column": 9 - }, - "end": { - "line": 76, - "column": 14 - } - } - }, - "init": { - "type": "MemberExpression", - "object": { - "type": "Identifier", - "name": "h_var", - "decorators": [], - "loc": { - "start": { - "line": 76, - "column": 24 - }, - "end": { - "line": 76, - "column": 29 - } - } - }, - "property": { - "type": "NumberLiteral", - "value": 1, - "loc": { - "start": { - "line": 76, - "column": 30 - }, - "end": { - "line": 76, - "column": 31 - } - } - }, - "computed": true, - "optional": false, - "loc": { - "start": { - "line": 76, - "column": 24 - }, - "end": { - "line": 76, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 76, - "column": 9 - }, - "end": { - "line": 76, - "column": 32 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 76, - "column": 5 - }, - "end": { - "line": 76, - "column": 33 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "j_var", - "typeAnnotation": { - "type": "ETSTuple", - "types": [ - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 78, - "column": 17 - }, - "end": { - "line": 78, - "column": 20 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "number", - "decorators": [], - "loc": { - "start": { - "line": 78, - "column": 22 - }, - "end": { - "line": 78, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 78, - "column": 22 - }, - "end": { - "line": 78, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 78, - "column": 22 - }, - "end": { - "line": 78, - "column": 29 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], - "loc": { - "start": { - "line": 78, - "column": 30 - }, - "end": { - "line": 78, - "column": 36 - } - } - }, - "loc": { - "start": { - "line": 78, - "column": 30 - }, - "end": { - "line": 78, - "column": 37 - } - } - }, - "loc": { - "start": { - "line": 78, - "column": 30 - }, - "end": { - "line": 78, - "column": 37 - } - } - }, - { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 78, - "column": 38 - }, - "end": { - "line": 78, - "column": 45 - } - } - }, - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 78, - "column": 47 - }, - "end": { - "line": 78, - "column": 53 - } - } - }, - "loc": { - "start": { - "line": 78, - "column": 47 - }, - "end": { - "line": 78, - "column": 54 - } - } - }, - "loc": { - "start": { - "line": 78, - "column": 47 - }, - "end": { - "line": 78, - "column": 54 - } - } - } - ], - "spreadType": null, - "loc": { - "start": { - "line": 78, - "column": 16 - }, - "end": { - "line": 78, - "column": 56 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 78, - "column": 9 - }, - "end": { - "line": 78, - "column": 14 - } - } - }, - "init": { - "type": "ArrayExpression", - "elements": [ - { - "type": "NumberLiteral", - "value": 6, - "loc": { - "start": { - "line": 78, - "column": 58 - }, - "end": { - "line": 78, - "column": 59 - } - } - }, - { - "type": "NumberLiteral", - "value": 7, - "loc": { - "start": { - "line": 78, - "column": 61 - }, - "end": { - "line": 78, - "column": 62 - } - } - }, - { - "type": "StringLiteral", - "value": "abc", - "loc": { - "start": { - "line": 78, - "column": 64 - }, - "end": { - "line": 78, - "column": 69 - } - } - }, - { - "type": "BooleanLiteral", - "value": true, - "loc": { - "start": { - "line": 78, - "column": 71 - }, - "end": { - "line": 78, - "column": 75 - } - } - }, - { - "type": "NumberLiteral", - "value": 666, - "loc": { - "start": { - "line": 78, - "column": 77 - }, - "end": { - "line": 78, - "column": 80 - } - } - } - ], - "loc": { - "start": { - "line": 78, - "column": 57 - }, - "end": { - "line": 78, - "column": 81 - } - } - }, - "loc": { - "start": { - "line": 78, - "column": 9 - }, - "end": { - "line": 78, - "column": 81 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 78, - "column": 5 - }, - "end": { - "line": 78, - "column": 82 - } - } - }, { "type": "VariableDeclaration", "declarations": [ diff --git a/ets2panda/test/compiler/ets/tuple_types_1.ets b/ets2panda/test/compiler/ets/tuple_types_1.ets index 72de48fbadc209f634d2b658c732986ddcfb5be4..656398211bf7272c9e005e62b8ac1ac71bffca25 100644 --- a/ets2panda/test/compiler/ets/tuple_types_1.ets +++ b/ets2panda/test/compiler/ets/tuple_types_1.ets @@ -72,10 +72,10 @@ function main(): void { let g_var: [number, string][]; g_var = [[1, "A"], [2, "B"], [3, "C"]]; - let h_var: [number, int, string, boolean, Object] = [1, 2, "asd", false, new Object()]; - let i_var: float = h_var[1]; - - let j_var: [int, number, string, boolean, Object] = [6, 7, "abc", true, 666]; + // #15570 - test ArrayExpr assignability with individual element types + // let h_var: [number, int, string, boolean, Object] = [1, 2, "asd", false, new Object()]; + // let i_var: float = h_var[1]; + // let j_var: [int, number, string, boolean, Object] = [6, 7, "abc", true, 666]; // NOTE: Bug in op_assignment lowering (removes const from property) // j_var[0] += new Short(2 as short); diff --git a/ets2panda/test/compiler/ets/tuple_types_17-expected.txt b/ets2panda/test/compiler/ets/tuple_types_17-expected.txt index 9ed30ce235a5fc15625b543517da5111b31314ff..3e7201ee14a6b887b2462031c04ab41de70ac204 100644 --- a/ets2panda/test/compiler/ets/tuple_types_17-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_17-expected.txt @@ -22,13 +22,38 @@ "type": "ETSTuple", "types": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, "loc": { "start": { "line": 16, @@ -36,21 +61,24 @@ }, "end": { "line": 16, - "column": 16 + "column": 17 } } }, - "loc": { - "start": { - "line": 16, - "column": 13 - }, - "end": { - "line": 16, - "column": 17 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 26 + } } } - }, + ], "loc": { "start": { "line": 16, @@ -58,7 +86,7 @@ }, "end": { "line": 16, - "column": 17 + "column": 26 } } }, diff --git a/ets2panda/test/compiler/ets/tuple_types_18-expected.txt b/ets2panda/test/compiler/ets/tuple_types_18-expected.txt index ebe6fc8aab0430bd1258bc40e988200307b78fb7..936ee6de90b087d3ca304c8e1bc9e420f6646f30 100644 --- a/ets2panda/test/compiler/ets/tuple_types_18-expected.txt +++ b/ets2panda/test/compiler/ets/tuple_types_18-expected.txt @@ -64,13 +64,38 @@ "type": "ETSTuple", "types": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "One", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "One", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, "loc": { "start": { "line": 18, @@ -78,21 +103,24 @@ }, "end": { "line": 18, - "column": 16 + "column": 17 } } }, - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 17 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 26 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -100,7 +128,7 @@ }, "end": { "line": 18, - "column": 17 + "column": 26 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_3-expected.txt b/ets2panda/test/compiler/ets/union_types_3-expected.txt index 6d79a7c76ac512ae1500d82f24896b0b3b73e847..a7c1cbf3c966f40f4caa428451917b3222917528 100644 --- a/ets2panda/test/compiler/ets/union_types_3-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_3-expected.txt @@ -1801,35 +1801,63 @@ "decorators": [], "loc": { "start": { - "line": 32, + "line": 33, "column": 13 }, "end": { - "line": 32, + "line": 33, "column": 15 } } }, "typeAnnotation": { - "type": "ETSPrimitiveType", + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Double", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 19 + }, + "end": { + "line": 33, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 19 + }, + "end": { + "line": 33, + "column": 26 + } + } + }, "loc": { "start": { - "line": 32, + "line": 33, "column": 19 }, "end": { - "line": 32, - "column": 25 + "line": 33, + "column": 26 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 12 }, "end": { - "line": 32, + "line": 33, "column": 26 } } @@ -1839,22 +1867,22 @@ "value": 3.14, "loc": { "start": { - "line": 32, + "line": 33, "column": 30 }, "end": { - "line": 32, + "line": 33, "column": 34 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 12 }, "end": { - "line": 32, + "line": 33, "column": 34 } } @@ -1864,22 +1892,22 @@ "value": "Error! Must be `3.14`", "loc": { "start": { - "line": 32, + "line": 33, "column": 36 }, "end": { - "line": 32, + "line": 33, "column": 59 } } }, "loc": { "start": { - "line": 32, + "line": 33, "column": 5 }, "end": { - "line": 32, + "line": 33, "column": 60 } } @@ -1891,7 +1919,7 @@ "column": 17 }, "end": { - "line": 33, + "line": 34, "column": 2 } } @@ -1902,7 +1930,7 @@ "column": 14 }, "end": { - "line": 33, + "line": 34, "column": 2 } } @@ -1913,7 +1941,7 @@ "column": 14 }, "end": { - "line": 33, + "line": 34, "column": 2 } } @@ -1926,7 +1954,7 @@ "column": 1 }, "end": { - "line": 33, + "line": 34, "column": 2 } } @@ -1961,7 +1989,7 @@ "column": 1 }, "end": { - "line": 34, + "line": 35, "column": 1 } } diff --git a/ets2panda/test/compiler/ets/union_types_3.ets b/ets2panda/test/compiler/ets/union_types_3.ets index 78a4cca1daefcbbabe4eb8c9aeb6e1aff7712740..f9f23ca5f6149d8c07c76313cd55560a7bb61aab 100644 --- a/ets2panda/test/compiler/ets/union_types_3.ets +++ b/ets2panda/test/compiler/ets/union_types_3.ets @@ -29,5 +29,6 @@ function main() { let x2 : String | boolean | int | double = true; assert (x2 as boolean) == true: "Error! Must be `true`"; let x3 : String | boolean | int | double = 3.14; - assert (x3 as double) == 3.14: "Error! Must be `3.14`"; + // assert (x3 as double) == 3.14: "Error! Must be `3.14`"; // #15576 + assert (x3 as Double) == 3.14: "Error! Must be `3.14`"; } diff --git a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt index d5501d37a78b4b9f0ffdf8acd77fb4c6087cdaf2..050b3114390a3539f0ad8e9bc7a92cdf65d5de3f 100644 --- a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt +++ b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt @@ -46,13 +46,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 17, @@ -60,21 +85,24 @@ }, "end": { "line": 17, - "column": 25 + "column": 27 } } }, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 27 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 28 + }, + "end": { + "line": 17, + "column": 32 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -82,7 +110,7 @@ }, "end": { "line": 17, - "column": 27 + "column": 32 } } }, @@ -95,7 +123,7 @@ }, "end": { "line": 17, - "column": 27 + "column": 32 } } }, @@ -123,13 +151,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 18, @@ -137,21 +190,24 @@ }, "end": { "line": 18, - "column": 26 + "column": 28 } } }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 28 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 29 + }, + "end": { + "line": 18, + "column": 33 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -159,7 +215,7 @@ }, "end": { "line": 18, - "column": 28 + "column": 33 } } }, @@ -172,7 +228,7 @@ }, "end": { "line": 18, - "column": 28 + "column": 33 } } }, @@ -276,13 +332,38 @@ "type": "Identifier", "name": "left", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 21, @@ -290,21 +371,24 @@ }, "end": { "line": 21, - "column": 29 + "column": 31 } } }, - "loc": { - "start": { - "line": 21, - "column": 21 - }, - "end": { - "line": 21, - "column": 31 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 36 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -312,7 +396,7 @@ }, "end": { "line": 21, - "column": 31 + "column": 36 } } }, @@ -324,7 +408,7 @@ }, "end": { "line": 21, - "column": 31 + "column": 36 } } }, @@ -335,7 +419,7 @@ }, "end": { "line": 21, - "column": 31 + "column": 36 } } }, @@ -345,13 +429,38 @@ "type": "Identifier", "name": "right", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "TreeNode", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 21, @@ -359,21 +468,24 @@ }, "end": { "line": 21, - "column": 53 + "column": 55 } } }, - "loc": { - "start": { - "line": 21, - "column": 45 - }, - "end": { - "line": 21, - "column": 55 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 56 + }, + "end": { + "line": 21, + "column": 60 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -381,7 +493,7 @@ }, "end": { "line": 21, - "column": 55 + "column": 60 } } }, @@ -393,7 +505,7 @@ }, "end": { "line": 21, - "column": 55 + "column": 60 } } }, @@ -404,7 +516,7 @@ }, "end": { "line": 21, - "column": 55 + "column": 60 } } }, @@ -1001,28 +1113,43 @@ "callee": { "type": "MemberExpression", "object": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 31, - "column": 26 - }, - "end": { - "line": 31, - "column": 30 + "type": "TSNonNullExpression", + "expression": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 31, + "column": 26 + }, + "end": { + "line": 31, + "column": 30 + } } - } - }, - "property": { - "type": "Identifier", - "name": "left", - "decorators": [], + }, + "property": { + "type": "Identifier", + "name": "left", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 31 + }, + "end": { + "line": 31, + "column": 35 + } + } + }, + "computed": false, + "optional": false, "loc": { "start": { "line": 31, - "column": 31 + "column": 26 }, "end": { "line": 31, @@ -1030,8 +1157,6 @@ } } }, - "computed": false, - "optional": false, "loc": { "start": { "line": 31, @@ -1039,7 +1164,7 @@ }, "end": { "line": 31, - "column": 35 + "column": 36 } } }, @@ -1050,11 +1175,11 @@ "loc": { "start": { "line": 31, - "column": 36 + "column": 37 }, "end": { "line": 31, - "column": 45 + "column": 46 } } }, @@ -1067,7 +1192,7 @@ }, "end": { "line": 31, - "column": 45 + "column": 46 } } }, @@ -1080,7 +1205,7 @@ }, "end": { "line": 31, - "column": 47 + "column": 48 } } }, @@ -1091,7 +1216,7 @@ }, "end": { "line": 31, - "column": 47 + "column": 48 } } }, @@ -1100,45 +1225,58 @@ "callee": { "type": "MemberExpression", "object": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 31, - "column": 50 - }, - "end": { - "line": 31, - "column": 54 + "type": "TSNonNullExpression", + "expression": { + "type": "MemberExpression", + "object": { + "type": "ThisExpression", + "loc": { + "start": { + "line": 31, + "column": 51 + }, + "end": { + "line": 31, + "column": 55 + } } - } - }, - "property": { - "type": "Identifier", - "name": "right", - "decorators": [], + }, + "property": { + "type": "Identifier", + "name": "right", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 56 + }, + "end": { + "line": 31, + "column": 61 + } + } + }, + "computed": false, + "optional": false, "loc": { "start": { "line": 31, - "column": 55 + "column": 51 }, "end": { "line": 31, - "column": 60 + "column": 61 } } }, - "computed": false, - "optional": false, "loc": { "start": { "line": 31, - "column": 50 + "column": 51 }, "end": { "line": 31, - "column": 60 + "column": 62 } } }, @@ -1149,11 +1287,11 @@ "loc": { "start": { "line": 31, - "column": 61 + "column": 63 }, "end": { "line": 31, - "column": 70 + "column": 72 } } }, @@ -1162,11 +1300,11 @@ "loc": { "start": { "line": 31, - "column": 50 + "column": 51 }, "end": { "line": 31, - "column": 70 + "column": 72 } } }, @@ -1175,11 +1313,11 @@ "loc": { "start": { "line": 31, - "column": 50 + "column": 51 }, "end": { "line": 31, - "column": 72 + "column": 74 } } }, @@ -1190,7 +1328,7 @@ }, "end": { "line": 31, - "column": 72 + "column": 74 } } }, @@ -1201,7 +1339,7 @@ }, "end": { "line": 31, - "column": 73 + "column": 75 } } }, @@ -1212,7 +1350,7 @@ }, "end": { "line": 31, - "column": 73 + "column": 75 } } } diff --git a/ets2panda/test/parser/ets/AccessBinaryTrees.ets b/ets2panda/test/parser/ets/AccessBinaryTrees.ets index 85ae913c28b190b2884a7733613466b4b0da8567..dd230b01868022c1eece4966925fdf6ddea9a21c 100644 --- a/ets2panda/test/parser/ets/AccessBinaryTrees.ets +++ b/ets2panda/test/parser/ets/AccessBinaryTrees.ets @@ -28,7 +28,7 @@ class TreeNode { if (this.left == null) return this.item; else - return this.item + this.left.itemCheck() - this.right.itemCheck(); + return this.item + this.left!.itemCheck() - this.right!.itemCheck(); } } diff --git a/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt b/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt index e93759c2243f392338aa46f83c9ca3eca341abe8..e6a6c14511c8e1afb1a76d939b8a23a6b21fd69b 100644 --- a/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt +++ b/ets2panda/test/parser/ets/OptionalParametersWithGenericReturnTypes-expected.txt @@ -116,13 +116,38 @@ "type": "Identifier", "name": "param", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, "loc": { "start": { "line": 17, @@ -130,21 +155,24 @@ }, "end": { "line": 17, - "column": 23 + "column": 24 } } }, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 24 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -406,13 +434,38 @@ "type": "Identifier", "name": "param", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -424,17 +477,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, @@ -1201,13 +1257,38 @@ "type": "Identifier", "name": "param", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 24 + } + } + }, "loc": { "start": { "line": 23, @@ -1215,21 +1296,24 @@ }, "end": { "line": 23, - "column": 23 + "column": 24 } } }, - "loc": { - "start": { - "line": 23, - "column": 17 - }, - "end": { - "line": 23, - "column": 24 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 15 + } } } - }, + ], "loc": { "start": { "line": 23, @@ -1532,13 +1616,38 @@ "type": "Identifier", "name": "param", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -1550,17 +1659,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt index d9ff0c65bccdf4ff3e8f29a7deff02413dc370e6..6ef51b7c7d11f6a3de5108e9df5b0a3f699f90a3 100644 --- a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt @@ -309,20 +309,48 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 16, - "column": 8 + "type": "ETSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 11 + } + } }, - "end": { - "line": 16, - "column": 11 + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 20 + } } } - }, + ], "loc": { "start": { "line": 16, @@ -330,7 +358,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 20 } } }, @@ -343,7 +371,7 @@ }, "end": { "line": 16, - "column": 15 + "column": 20 } } }, @@ -371,20 +399,48 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 17, - "column": 8 + "type": "ETSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 14 + } + } }, - "end": { - "line": 17, - "column": 14 + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -392,7 +448,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 23 } } }, @@ -405,7 +461,7 @@ }, "end": { "line": 17, - "column": 18 + "column": 23 } } }, @@ -433,15 +489,40 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 18, @@ -449,32 +530,35 @@ }, "end": { "line": 18, - "column": 14 + "column": 15 } } }, "loc": { "start": { "line": 18, - "column": 8 + "column": 17 }, "end": { "line": 18, - "column": 15 + "column": 18 } } }, - "loc": { - "start": { - "line": 18, - "column": 8 - }, - "end": { - "line": 18, - "column": 15 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -482,7 +566,7 @@ }, "end": { "line": 18, - "column": 18 + "column": 23 } } }, @@ -495,7 +579,7 @@ }, "end": { "line": 18, - "column": 18 + "column": 23 } } }, @@ -597,20 +681,48 @@ "type": "Identifier", "name": "c", "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 21, - "column": 14 + "type": "ETSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 19 + } + } }, - "end": { - "line": 21, - "column": 19 + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 28 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -618,7 +730,7 @@ }, "end": { "line": 21, - "column": 23 + "column": 28 } } }, @@ -681,20 +793,48 @@ "type": "Identifier", "name": "d", "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSPrimitiveType", - "loc": { - "start": { - "line": 22, - "column": 12 + "type": "ETSUnionType", + "types": [ + { + "type": "TSArrayType", + "elementType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 16 + } + } }, - "end": { - "line": 22, - "column": 16 + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 25 + } } } - }, + ], "loc": { "start": { "line": 22, @@ -702,7 +842,7 @@ }, "end": { "line": 22, - "column": 20 + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/array_new_failed-expected.txt b/ets2panda/test/parser/ets/array_new_failed-expected.txt index 7a1d50898a8ca2833466062a25840c411cdc8a80..9d3ca1198d87e3e42e158728975c84e0e40cedb1 100644 --- a/ets2panda/test/parser/ets/array_new_failed-expected.txt +++ b/ets2panda/test/parser/ets/array_new_failed-expected.txt @@ -371,4 +371,4 @@ } } } -TypeError: Index fracional part should not be different from 0.0 [array_new_failed.ets:17:19] +TypeError: Index fractional part should be zero. [array_new_failed.ets:17:19] diff --git a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt index 6ca5ac47b0920194410560ce064a40e53f7d4dc5..9bdd661396a7985c90535669fcd59c08112bd1dd 100644 --- a/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt +++ b/ets2panda/test/parser/ets/assignment_non-functional_variable_to_functional_type-expected.txt @@ -49,13 +49,38 @@ "type": "ETSFunctionType", "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Observable", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 63 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 53 + }, + "end": { + "line": 17, + "column": 64 + } + } + }, "loc": { "start": { "line": 17, @@ -63,21 +88,24 @@ }, "end": { "line": 17, - "column": 63 + "column": 64 } } }, - "loc": { - "start": { - "line": 17, - "column": 53 - }, - "end": { - "line": 17, - "column": 64 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 17, + "column": 64 + }, + "end": { + "line": 17, + "column": 73 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -85,7 +113,7 @@ }, "end": { "line": 17, - "column": 64 + "column": 73 } } }, @@ -96,7 +124,7 @@ }, "end": { "line": 17, - "column": 64 + "column": 73 } } }, @@ -109,7 +137,7 @@ }, "end": { "line": 17, - "column": 64 + "column": 73 } } }, @@ -370,13 +398,38 @@ "type": "Identifier", "name": "observable", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Observable", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Observable", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 49 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, "loc": { "start": { "line": 21, @@ -384,21 +437,24 @@ }, "end": { "line": 21, - "column": 59 + "column": 60 } } }, - "loc": { - "start": { - "line": 21, - "column": 49 - }, - "end": { - "line": 21, - "column": 60 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 21, + "column": 60 + }, + "end": { + "line": 21, + "column": 69 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -406,7 +462,7 @@ }, "end": { "line": 21, - "column": 60 + "column": 69 } } }, @@ -418,7 +474,7 @@ }, "end": { "line": 21, - "column": 60 + "column": 69 } } }, @@ -429,7 +485,7 @@ }, "end": { "line": 21, - "column": 60 + "column": 69 } } } diff --git a/ets2panda/test/parser/ets/async_function-expected.txt b/ets2panda/test/parser/ets/async_function-expected.txt index 5ad52c7a2102a52b95198532b56e5b1029e9a5ba..65c3c5184d3e247dd166d5a88b32b67d1fa39849 100644 --- a/ets2panda/test/parser/ets/async_function-expected.txt +++ b/ets2panda/test/parser/ets/async_function-expected.txt @@ -90,13 +90,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 41 + } + } + }, "loc": { "start": { "line": 17, @@ -104,21 +129,24 @@ }, "end": { "line": 17, - "column": 39 + "column": 41 } } }, - "loc": { - "start": { - "line": 17, - "column": 33 - }, - "end": { - "line": 17, - "column": 40 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 46 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -126,7 +154,7 @@ }, "end": { "line": 17, - "column": 40 + "column": 46 } } } @@ -138,7 +166,7 @@ }, "end": { "line": 17, - "column": 40 + "column": 47 } } }, @@ -149,7 +177,7 @@ }, "end": { "line": 17, - "column": 42 + "column": 49 } } }, @@ -160,7 +188,7 @@ }, "end": { "line": 17, - "column": 42 + "column": 49 } } }, @@ -540,13 +568,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 39 + } + } + }, "loc": { "start": { "line": 20, @@ -554,21 +607,24 @@ }, "end": { "line": 20, - "column": 37 + "column": 39 } } }, - "loc": { - "start": { - "line": 20, - "column": 31 - }, - "end": { - "line": 20, - "column": 38 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 20, + "column": 40 + }, + "end": { + "line": 20, + "column": 44 + } } } - }, + ], "loc": { "start": { "line": 20, @@ -576,7 +632,7 @@ }, "end": { "line": 20, - "column": 38 + "column": 44 } } } @@ -588,7 +644,7 @@ }, "end": { "line": 20, - "column": 38 + "column": 45 } } }, @@ -599,7 +655,7 @@ }, "end": { "line": 20, - "column": 40 + "column": 47 } } }, @@ -610,7 +666,7 @@ }, "end": { "line": 20, - "column": 40 + "column": 47 } } }, @@ -740,13 +796,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 70 + } + } + }, "loc": { "start": { "line": 22, @@ -754,21 +835,24 @@ }, "end": { "line": 22, - "column": 68 + "column": 70 } } }, - "loc": { - "start": { - "line": 22, - "column": 62 - }, - "end": { - "line": 22, - "column": 69 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 22, + "column": 71 + }, + "end": { + "line": 22, + "column": 75 + } } } - }, + ], "loc": { "start": { "line": 22, @@ -776,7 +860,7 @@ }, "end": { "line": 22, - "column": 69 + "column": 75 } } } @@ -788,7 +872,7 @@ }, "end": { "line": 22, - "column": 69 + "column": 76 } } }, @@ -799,7 +883,7 @@ }, "end": { "line": 22, - "column": 71 + "column": 79 } } }, @@ -810,7 +894,7 @@ }, "end": { "line": 22, - "column": 71 + "column": 79 } } }, @@ -910,13 +994,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 35 + } + } + }, "loc": { "start": { "line": 22, @@ -924,21 +1033,24 @@ }, "end": { "line": 22, - "column": 33 + "column": 35 } } }, - "loc": { - "start": { - "line": 22, - "column": 27 - }, - "end": { - "line": 22, - "column": 34 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 22, + "column": 36 + }, + "end": { + "line": 22, + "column": 40 + } } } - }, + ], "loc": { "start": { "line": 22, @@ -946,7 +1058,7 @@ }, "end": { "line": 22, - "column": 34 + "column": 40 } } } @@ -958,7 +1070,7 @@ }, "end": { "line": 22, - "column": 34 + "column": 41 } } }, @@ -969,7 +1081,7 @@ }, "end": { "line": 22, - "column": 36 + "column": 43 } } }, @@ -980,7 +1092,7 @@ }, "end": { "line": 22, - "column": 36 + "column": 43 } } }, @@ -991,7 +1103,7 @@ }, "end": { "line": 22, - "column": 36 + "column": 43 } } }, diff --git a/ets2panda/test/parser/ets/async_function.ets b/ets2panda/test/parser/ets/async_function.ets index 326f6cfefd1ec9de9d40a9c39beb9de9db9020d7..ff5cdf22ca9c51e1af96df6eaf7d25f5bb01e65a 100644 --- a/ets2panda/test/parser/ets/async_function.ets +++ b/ets2panda/test/parser/ets/async_function.ets @@ -14,9 +14,9 @@ */ class Class { - public async bar(): Promise | null { return null; } + public async bar(): Promise { return null; } } -async function foo(): Promise | null { return null; } +async function foo(): Promise { return null; } -let lambda: () => Promise | null = async (): Promise | null => { return null; } +let lambda: () => Promise = async (): Promise => { return null; } diff --git a/ets2panda/test/parser/ets/async_overload-expected.txt b/ets2panda/test/parser/ets/async_overload-expected.txt index 5e103098465eac12ce4bc95270494443db78b42d..6ac9016e647e4b49321ad7c0c9b6de21626a5e94 100644 --- a/ets2panda/test/parser/ets/async_overload-expected.txt +++ b/ets2panda/test/parser/ets/async_overload-expected.txt @@ -132,13 +132,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 40 + } + } + }, "loc": { "start": { "line": 17, @@ -146,21 +171,24 @@ }, "end": { "line": 17, - "column": 38 + "column": 40 } } }, - "loc": { - "start": { - "line": 17, - "column": 32 - }, - "end": { - "line": 17, - "column": 39 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 41 + }, + "end": { + "line": 17, + "column": 45 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -168,7 +196,7 @@ }, "end": { "line": 17, - "column": 39 + "column": 45 } } } @@ -180,7 +208,7 @@ }, "end": { "line": 17, - "column": 39 + "column": 46 } } }, @@ -191,7 +219,7 @@ }, "end": { "line": 17, - "column": 41 + "column": 48 } } }, @@ -202,7 +230,7 @@ }, "end": { "line": 17, - "column": 41 + "column": 48 } } }, @@ -322,13 +350,38 @@ "type": "Identifier", "name": "o", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 21, @@ -336,21 +389,24 @@ }, "end": { "line": 21, - "column": 24 + "column": 26 } } }, - "loc": { - "start": { - "line": 21, - "column": 18 - }, - "end": { - "line": 21, - "column": 26 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 31 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -358,7 +414,7 @@ }, "end": { "line": 21, - "column": 26 + "column": 31 } } }, @@ -370,7 +426,7 @@ }, "end": { "line": 21, - "column": 26 + "column": 31 } } }, @@ -381,7 +437,7 @@ }, "end": { "line": 21, - "column": 26 + "column": 31 } } }, @@ -450,13 +506,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 58 + } + } + }, "loc": { "start": { "line": 21, @@ -464,21 +545,24 @@ }, "end": { "line": 21, - "column": 56 + "column": 58 } } }, - "loc": { - "start": { - "line": 21, - "column": 50 - }, - "end": { - "line": 21, - "column": 57 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 59 + }, + "end": { + "line": 21, + "column": 63 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -486,7 +570,7 @@ }, "end": { "line": 21, - "column": 57 + "column": 63 } } } @@ -498,7 +582,7 @@ }, "end": { "line": 21, - "column": 57 + "column": 64 } } }, @@ -509,7 +593,7 @@ }, "end": { "line": 21, - "column": 59 + "column": 66 } } }, @@ -520,7 +604,7 @@ }, "end": { "line": 21, - "column": 59 + "column": 66 } } }, @@ -927,13 +1011,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 45 + } + } + }, "loc": { "start": { "line": 25, @@ -941,21 +1050,24 @@ }, "end": { "line": 25, - "column": 43 + "column": 45 } } }, - "loc": { - "start": { - "line": 25, - "column": 37 - }, - "end": { - "line": 25, - "column": 44 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 25, + "column": 46 + }, + "end": { + "line": 25, + "column": 50 + } } } - }, + ], "loc": { "start": { "line": 25, @@ -963,7 +1075,7 @@ }, "end": { "line": 25, - "column": 44 + "column": 50 } } } @@ -975,7 +1087,7 @@ }, "end": { "line": 25, - "column": 44 + "column": 51 } } }, @@ -986,7 +1098,7 @@ }, "end": { "line": 25, - "column": 46 + "column": 53 } } }, @@ -997,7 +1109,7 @@ }, "end": { "line": 25, - "column": 46 + "column": 53 } } }, @@ -1117,13 +1229,38 @@ "type": "Identifier", "name": "o", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 29, @@ -1131,21 +1268,24 @@ }, "end": { "line": 29, - "column": 29 + "column": 31 } } }, - "loc": { - "start": { - "line": 29, - "column": 23 - }, - "end": { - "line": 29, - "column": 31 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 29, + "column": 32 + }, + "end": { + "line": 29, + "column": 36 + } } } - }, + ], "loc": { "start": { "line": 29, @@ -1153,7 +1293,7 @@ }, "end": { "line": 29, - "column": 31 + "column": 36 } } }, @@ -1165,7 +1305,7 @@ }, "end": { "line": 29, - "column": 31 + "column": 36 } } }, @@ -1176,7 +1316,7 @@ }, "end": { "line": 29, - "column": 31 + "column": 36 } } }, @@ -1245,13 +1385,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 63 + } + } + }, "loc": { "start": { "line": 29, @@ -1259,21 +1424,24 @@ }, "end": { "line": 29, - "column": 61 + "column": 63 } } }, - "loc": { - "start": { - "line": 29, - "column": 55 - }, - "end": { - "line": 29, - "column": 62 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 29, + "column": 64 + }, + "end": { + "line": 29, + "column": 68 + } } } - }, + ], "loc": { "start": { "line": 29, @@ -1281,7 +1449,7 @@ }, "end": { "line": 29, - "column": 62 + "column": 68 } } } @@ -1293,7 +1461,7 @@ }, "end": { "line": 29, - "column": 62 + "column": 69 } } }, @@ -1304,7 +1472,7 @@ }, "end": { "line": 29, - "column": 64 + "column": 70 } } }, @@ -1315,7 +1483,7 @@ }, "end": { "line": 29, - "column": 64 + "column": 70 } } }, diff --git a/ets2panda/test/parser/ets/async_overload.ets b/ets2panda/test/parser/ets/async_overload.ets index 8758cf049dd0b28f651c758df7b201960d2c2ea3..0e6a30b750cd5ca439de13610b71d0233c6e2214 100644 --- a/ets2panda/test/parser/ets/async_overload.ets +++ b/ets2panda/test/parser/ets/async_overload.ets @@ -14,19 +14,19 @@ */ class Foo { - async foo(i: int): Promise | null { + async foo(i: int): Promise { return null; } - async foo(o: Object | null, i: int): Promise | null { + async foo(o: Object | null, i: int): Promise { } } -async function bar(i: int): Promise | null { +async function bar(i: int): Promise { return null; } -async function bar(o: Object | null, i: int): Promise | null{ +async function bar(o: Object | null, i: int): Promise{ return null; } diff --git a/ets2panda/test/parser/ets/async_with_lambda-expected.txt b/ets2panda/test/parser/ets/async_with_lambda-expected.txt index 657afa171455554c64b5d2a5cf2dd6abbcda280e..dba529e9ed9788b0123a95fdd1887750019f3d7f 100644 --- a/ets2panda/test/parser/ets/async_with_lambda-expected.txt +++ b/ets2panda/test/parser/ets/async_with_lambda-expected.txt @@ -275,13 +275,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 50 + } + } + }, "loc": { "start": { "line": 18, @@ -289,21 +314,24 @@ }, "end": { "line": 18, - "column": 48 + "column": 50 } } }, - "loc": { - "start": { - "line": 18, - "column": 42 - }, - "end": { - "line": 18, - "column": 49 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 51 + }, + "end": { + "line": 18, + "column": 55 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -311,7 +339,7 @@ }, "end": { "line": 18, - "column": 49 + "column": 55 } } } @@ -323,7 +351,7 @@ }, "end": { "line": 18, - "column": 49 + "column": 56 } } }, @@ -334,7 +362,7 @@ }, "end": { "line": 18, - "column": 51 + "column": 58 } } }, @@ -345,7 +373,7 @@ }, "end": { "line": 18, - "column": 51 + "column": 58 } } }, @@ -772,13 +800,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 45 + } + } + }, "loc": { "start": { "line": 26, @@ -786,21 +839,24 @@ }, "end": { "line": 26, - "column": 43 + "column": 45 } } }, - "loc": { - "start": { - "line": 26, - "column": 37 - }, - "end": { - "line": 26, - "column": 44 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 26, + "column": 46 + }, + "end": { + "line": 26, + "column": 50 + } } } - }, + ], "loc": { "start": { "line": 26, @@ -808,7 +864,7 @@ }, "end": { "line": 26, - "column": 44 + "column": 50 } } } @@ -820,7 +876,7 @@ }, "end": { "line": 26, - "column": 44 + "column": 51 } } }, @@ -831,7 +887,7 @@ }, "end": { "line": 26, - "column": 46 + "column": 53 } } }, @@ -842,7 +898,7 @@ }, "end": { "line": 26, - "column": 46 + "column": 53 } } }, @@ -853,7 +909,7 @@ }, "end": { "line": 26, - "column": 46 + "column": 53 } } }, @@ -901,13 +957,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 80 + } + } + }, "loc": { "start": { "line": 26, @@ -915,21 +996,24 @@ }, "end": { "line": 26, - "column": 78 + "column": 80 } } }, - "loc": { - "start": { - "line": 26, - "column": 72 - }, - "end": { - "line": 26, - "column": 79 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 26, + "column": 81 + }, + "end": { + "line": 26, + "column": 85 + } } } - }, + ], "loc": { "start": { "line": 26, @@ -937,7 +1021,7 @@ }, "end": { "line": 26, - "column": 79 + "column": 85 } } } @@ -949,7 +1033,7 @@ }, "end": { "line": 26, - "column": 79 + "column": 86 } } }, @@ -960,7 +1044,7 @@ }, "end": { "line": 26, - "column": 81 + "column": 89 } } }, @@ -971,7 +1055,7 @@ }, "end": { "line": 26, - "column": 81 + "column": 89 } } }, diff --git a/ets2panda/test/parser/ets/async_with_lambda.ets b/ets2panda/test/parser/ets/async_with_lambda.ets index 2e24244a521406fdbcf82260603e0fc124645559..2bd1a59f5d4ac6ea30e00735c5636e634ac83e84 100644 --- a/ets2panda/test/parser/ets/async_with_lambda.ets +++ b/ets2panda/test/parser/ets/async_with_lambda.ets @@ -15,7 +15,7 @@ let global: int; -async function func(param: int): Promise | null { +async function func(param: int): Promise { let local: int; let lambda: () => void = (): void => { param; @@ -23,7 +23,7 @@ async function func(param: int): Promise | null { global; let x = 0; } - let async_lambda: () => Promise | null = async (): Promise | null => { + let async_lambda: () => Promise = async (): Promise => { param; local; global; diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 2159d4df660a84e8b58988960fd248006cbbf539..da5fba9bfde3651bc7d0b6c2d8dfdf51a14bc87b 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -96,11 +96,11 @@ "loc": { "start": { "line": 38, - "column": 39 + "column": 46 }, "end": { "line": 38, - "column": 43 + "column": 50 } } }, @@ -111,7 +111,7 @@ }, "end": { "line": 38, - "column": 43 + "column": 50 } } }, @@ -122,7 +122,7 @@ }, "end": { "line": 38, - "column": 44 + "column": 51 } } }, @@ -149,28 +149,41 @@ "right": { "type": "AwaitExpression", "argument": { - "type": "Identifier", - "name": "promise", - "decorators": [], + "type": "TSNonNullExpression", + "expression": { + "type": "Identifier", + "name": "promise", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 32 + }, + "end": { + "line": 39, + "column": 39 + } + } + }, "loc": { "start": { - "line": 39, - "column": 25 + "line": 1, + "column": 1 }, "end": { - "line": 39, - "column": 32 + "line": 1, + "column": 1 } } }, "loc": { "start": { "line": 39, - "column": 19 + "column": 26 }, "end": { "line": 39, - "column": 33 + "column": 41 } } }, @@ -181,7 +194,7 @@ }, "end": { "line": 39, - "column": 33 + "column": 41 } } }, @@ -192,7 +205,7 @@ }, "end": { "line": 39, - "column": 33 + "column": 41 } } } @@ -311,13 +324,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 44 + } + } + }, "loc": { "start": { "line": 16, @@ -325,21 +363,24 @@ }, "end": { "line": 16, - "column": 42 + "column": 44 } } }, - "loc": { - "start": { - "line": 16, - "column": 36 - }, - "end": { - "line": 16, - "column": 43 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 16, + "column": 45 + }, + "end": { + "line": 16, + "column": 49 + } } } - }, + ], "loc": { "start": { "line": 16, @@ -347,7 +388,7 @@ }, "end": { "line": 16, - "column": 43 + "column": 49 } } } @@ -359,7 +400,7 @@ }, "end": { "line": 16, - "column": 43 + "column": 50 } } }, @@ -370,7 +411,7 @@ }, "end": { "line": 16, - "column": 45 + "column": 52 } } }, @@ -381,7 +422,7 @@ }, "end": { "line": 16, - "column": 45 + "column": 52 } } }, @@ -397,35 +438,88 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 18 + "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 + } + } }, - "end": { - "line": 17, - "column": 25 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSUnionType", + "types": [ + { + "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": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 26 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 39 + } + } + } + ], "loc": { "start": { "line": 17, @@ -433,55 +527,58 @@ }, "end": { "line": 17, - "column": 32 + "column": 39 } } - }, - "loc": { - "start": { - "line": 17, - "column": 26 - }, - "end": { - "line": 17, - "column": 33 - } } - }, + ], "loc": { "start": { "line": 17, - "column": 26 + "column": 25 }, "end": { "line": 17, - "column": 33 + "column": 40 } } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 42 + } } - ], + }, "loc": { "start": { "line": 17, - "column": 25 + "column": 18 }, "end": { "line": 17, - "column": 33 + "column": 42 } } }, - "loc": { - "start": { - "line": 17, - "column": 18 - }, - "end": { - "line": 17, - "column": 35 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 43 + }, + "end": { + "line": 17, + "column": 47 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -489,7 +586,7 @@ }, "end": { "line": 17, - "column": 35 + "column": 47 } } }, @@ -511,11 +608,11 @@ "loc": { "start": { "line": 17, - "column": 43 + "column": 50 }, "end": { "line": 17, - "column": 47 + "column": 54 } } }, @@ -526,7 +623,7 @@ }, "end": { "line": 17, - "column": 47 + "column": 54 } } } @@ -539,7 +636,7 @@ }, "end": { "line": 17, - "column": 48 + "column": 55 } } }, @@ -552,13 +649,38 @@ "type": "Identifier", "name": "obj", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, "loc": { "start": { "line": 18, @@ -566,21 +688,24 @@ }, "end": { "line": 18, - "column": 20 + "column": 22 } } }, - "loc": { - "start": { - "line": 18, - "column": 14 - }, - "end": { - "line": 18, - "column": 22 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -588,7 +713,7 @@ }, "end": { "line": 18, - "column": 22 + "column": 27 } } }, @@ -607,28 +732,41 @@ "init": { "type": "AwaitExpression", "argument": { - "type": "Identifier", - "name": "promise", - "decorators": [], + "type": "TSNonNullExpression", + "expression": { + "type": "Identifier", + "name": "promise", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 36 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, "loc": { "start": { "line": 18, - "column": 29 + "column": 36 }, "end": { "line": 18, - "column": 36 + "column": 44 } } }, "loc": { "start": { "line": 18, - "column": 23 + "column": 30 }, "end": { "line": 18, - "column": 37 + "column": 45 } } }, @@ -639,7 +777,7 @@ }, "end": { "line": 18, - "column": 37 + "column": 45 } } } @@ -652,7 +790,7 @@ }, "end": { "line": 18, - "column": 37 + "column": 45 } } }, @@ -780,13 +918,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 75 + } + } + }, "loc": { "start": { "line": 22, @@ -794,21 +957,24 @@ }, "end": { "line": 22, - "column": 73 + "column": 75 } } }, - "loc": { - "start": { - "line": 22, - "column": 67 - }, - "end": { - "line": 22, - "column": 74 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 22, + "column": 76 + }, + "end": { + "line": 22, + "column": 80 + } } } - }, + ], "loc": { "start": { "line": 22, @@ -816,7 +982,7 @@ }, "end": { "line": 22, - "column": 74 + "column": 80 } } } @@ -828,7 +994,7 @@ }, "end": { "line": 22, - "column": 74 + "column": 81 } } }, @@ -839,7 +1005,7 @@ }, "end": { "line": 22, - "column": 76 + "column": 84 } } }, @@ -850,7 +1016,7 @@ }, "end": { "line": 22, - "column": 76 + "column": 84 } } }, @@ -866,35 +1032,88 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 18 + "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 + } + } }, - "end": { - "line": 23, - "column": 25 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSUnionType", + "types": [ + { + "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": 34 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 34 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 23, + "column": 35 + }, + "end": { + "line": 23, + "column": 39 + } + } + } + ], "loc": { "start": { "line": 23, @@ -902,55 +1121,58 @@ }, "end": { "line": 23, - "column": 32 + "column": 39 } } - }, - "loc": { - "start": { - "line": 23, - "column": 26 - }, - "end": { - "line": 23, - "column": 33 - } } - }, + ], "loc": { "start": { "line": 23, - "column": 26 + "column": 25 }, "end": { "line": 23, - "column": 33 + "column": 40 } } + }, + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 42 + } } - ], + }, "loc": { "start": { "line": 23, - "column": 25 + "column": 18 }, "end": { "line": 23, - "column": 33 + "column": 42 } } }, - "loc": { - "start": { - "line": 23, - "column": 18 - }, - "end": { - "line": 23, - "column": 35 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 23, + "column": 43 + }, + "end": { + "line": 23, + "column": 47 + } } } - }, + ], "loc": { "start": { "line": 23, @@ -958,7 +1180,7 @@ }, "end": { "line": 23, - "column": 35 + "column": 47 } } }, @@ -980,11 +1202,11 @@ "loc": { "start": { "line": 23, - "column": 43 + "column": 50 }, "end": { "line": 23, - "column": 47 + "column": 54 } } }, @@ -995,7 +1217,7 @@ }, "end": { "line": 23, - "column": 47 + "column": 54 } } } @@ -1008,7 +1230,7 @@ }, "end": { "line": 23, - "column": 48 + "column": 55 } } }, @@ -1021,13 +1243,38 @@ "type": "Identifier", "name": "obj", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 22 + } + } + }, "loc": { "start": { "line": 24, @@ -1035,29 +1282,32 @@ }, "end": { "line": 24, - "column": 20 + "column": 22 } } }, - "loc": { - "start": { - "line": 24, - "column": 14 - }, - "end": { - "line": 24, - "column": 22 - } - } - }, - "loc": { - "start": { + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 24, + "column": 23 + }, + "end": { + "line": 24, + "column": 27 + } + } + } + ], + "loc": { + "start": { "line": 24, "column": 14 }, "end": { "line": 24, - "column": 22 + "column": 27 } } }, @@ -1076,28 +1326,41 @@ "init": { "type": "AwaitExpression", "argument": { - "type": "Identifier", - "name": "promise", - "decorators": [], + "type": "TSNonNullExpression", + "expression": { + "type": "Identifier", + "name": "promise", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 36 + }, + "end": { + "line": 24, + "column": 43 + } + } + }, "loc": { "start": { "line": 24, - "column": 29 + "column": 36 }, "end": { "line": 24, - "column": 36 + "column": 44 } } }, "loc": { "start": { "line": 24, - "column": 23 + "column": 30 }, "end": { "line": 24, - "column": 37 + "column": 45 } } }, @@ -1108,7 +1371,7 @@ }, "end": { "line": 24, - "column": 37 + "column": 45 } } } @@ -1121,7 +1384,7 @@ }, "end": { "line": 24, - "column": 37 + "column": 45 } } }, @@ -1219,13 +1482,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "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": 40 + } + } + }, "loc": { "start": { "line": 22, @@ -1233,21 +1521,24 @@ }, "end": { "line": 22, - "column": 38 + "column": 40 } } }, - "loc": { - "start": { - "line": 22, - "column": 32 - }, - "end": { - "line": 22, - "column": 39 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 22, + "column": 41 + }, + "end": { + "line": 22, + "column": 45 + } } } - }, + ], "loc": { "start": { "line": 22, @@ -1255,7 +1546,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 45 } } } @@ -1267,7 +1558,7 @@ }, "end": { "line": 22, - "column": 39 + "column": 46 } } }, @@ -1278,7 +1569,7 @@ }, "end": { "line": 22, - "column": 41 + "column": 48 } } }, @@ -1289,7 +1580,7 @@ }, "end": { "line": 22, - "column": 41 + "column": 48 } } }, @@ -1300,7 +1591,7 @@ }, "end": { "line": 22, - "column": 41 + "column": 48 } } }, @@ -1415,35 +1706,88 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 29, - "column": 18 + "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 + } + } }, - "end": { - "line": 29, - "column": 25 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSUnionType", + "types": [ + { + "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": 34 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 34 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 29, + "column": 35 + }, + "end": { + "line": 29, + "column": 39 + } + } + } + ], "loc": { "start": { "line": 29, @@ -1451,55 +1795,58 @@ }, "end": { "line": 29, - "column": 32 + "column": 39 } } - }, - "loc": { - "start": { - "line": 29, - "column": 26 - }, - "end": { - "line": 29, - "column": 33 - } } - }, + ], "loc": { "start": { "line": 29, - "column": 26 + "column": 25 }, "end": { "line": 29, - "column": 33 + "column": 40 } } + }, + "loc": { + "start": { + "line": 29, + "column": 18 + }, + "end": { + "line": 29, + "column": 42 + } } - ], + }, "loc": { "start": { "line": 29, - "column": 25 + "column": 18 }, "end": { "line": 29, - "column": 33 + "column": 42 } } }, - "loc": { - "start": { - "line": 29, - "column": 18 - }, - "end": { - "line": 29, - "column": 35 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 29, + "column": 43 + }, + "end": { + "line": 29, + "column": 47 + } } } - }, + ], "loc": { "start": { "line": 29, @@ -1507,7 +1854,7 @@ }, "end": { "line": 29, - "column": 35 + "column": 47 } } }, @@ -1529,11 +1876,11 @@ "loc": { "start": { "line": 29, - "column": 43 + "column": 50 }, "end": { "line": 29, - "column": 47 + "column": 54 } } }, @@ -1544,7 +1891,7 @@ }, "end": { "line": 29, - "column": 47 + "column": 54 } } } @@ -1557,7 +1904,7 @@ }, "end": { "line": 29, - "column": 48 + "column": 55 } } }, @@ -1570,13 +1917,38 @@ "type": "Identifier", "name": "obj", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 22 + } + } + }, "loc": { "start": { "line": 30, @@ -1584,21 +1956,24 @@ }, "end": { "line": 30, - "column": 20 + "column": 22 } } }, - "loc": { - "start": { - "line": 30, - "column": 14 - }, - "end": { - "line": 30, - "column": 22 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 30, + "column": 23 + }, + "end": { + "line": 30, + "column": 27 + } } } - }, + ], "loc": { "start": { "line": 30, @@ -1606,7 +1981,7 @@ }, "end": { "line": 30, - "column": 22 + "column": 27 } } }, @@ -1625,28 +2000,41 @@ "init": { "type": "AwaitExpression", "argument": { - "type": "Identifier", - "name": "promise", - "decorators": [], + "type": "TSNonNullExpression", + "expression": { + "type": "Identifier", + "name": "promise", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 36 + }, + "end": { + "line": 30, + "column": 43 + } + } + }, "loc": { "start": { "line": 30, - "column": 29 + "column": 36 }, "end": { "line": 30, - "column": 36 + "column": 44 } } }, "loc": { "start": { "line": 30, - "column": 23 + "column": 30 }, "end": { "line": 30, - "column": 37 + "column": 45 } } }, @@ -1657,7 +2045,7 @@ }, "end": { "line": 30, - "column": 37 + "column": 45 } } } @@ -1670,7 +2058,7 @@ }, "end": { "line": 30, - "column": 37 + "column": 45 } } } @@ -1800,35 +2188,88 @@ "type": "Identifier", "name": "promise", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 34, - "column": 18 + "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 + } + } }, - "end": { - "line": 34, - "column": 25 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSUnionType", + "types": [ + { + "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": 34 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 26 + }, + "end": { + "line": 34, + "column": 34 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 34, + "column": 35 + }, + "end": { + "line": 34, + "column": 39 + } + } + } + ], "loc": { "start": { "line": 34, @@ -1836,55 +2277,58 @@ }, "end": { "line": 34, - "column": 32 + "column": 39 } } - }, - "loc": { - "start": { - "line": 34, - "column": 26 - }, - "end": { - "line": 34, - "column": 33 - } } - }, + ], "loc": { "start": { "line": 34, - "column": 26 + "column": 25 }, "end": { "line": 34, - "column": 33 + "column": 40 } } + }, + "loc": { + "start": { + "line": 34, + "column": 18 + }, + "end": { + "line": 34, + "column": 42 + } } - ], + }, "loc": { "start": { "line": 34, - "column": 25 + "column": 18 }, "end": { "line": 34, - "column": 33 + "column": 42 } } }, - "loc": { - "start": { - "line": 34, - "column": 18 - }, - "end": { - "line": 34, - "column": 35 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 34, + "column": 43 + }, + "end": { + "line": 34, + "column": 47 + } } } - }, + ], "loc": { "start": { "line": 34, @@ -1892,7 +2336,7 @@ }, "end": { "line": 34, - "column": 35 + "column": 47 } } }, @@ -1914,11 +2358,11 @@ "loc": { "start": { "line": 34, - "column": 43 + "column": 50 }, "end": { "line": 34, - "column": 47 + "column": 54 } } }, @@ -1929,7 +2373,7 @@ }, "end": { "line": 34, - "column": 47 + "column": 54 } } } @@ -1942,7 +2386,7 @@ }, "end": { "line": 34, - "column": 48 + "column": 55 } } }, @@ -1955,13 +2399,38 @@ "type": "Identifier", "name": "obj", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 35, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 35, + "column": 22 + } + } + }, "loc": { "start": { "line": 35, @@ -1969,21 +2438,24 @@ }, "end": { "line": 35, - "column": 20 + "column": 22 } } }, - "loc": { - "start": { - "line": 35, - "column": 14 - }, - "end": { - "line": 35, - "column": 22 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 35, + "column": 23 + }, + "end": { + "line": 35, + "column": 27 + } } } - }, + ], "loc": { "start": { "line": 35, @@ -1991,7 +2463,7 @@ }, "end": { "line": 35, - "column": 22 + "column": 27 } } }, @@ -2010,28 +2482,41 @@ "init": { "type": "AwaitExpression", "argument": { - "type": "Identifier", - "name": "promise", - "decorators": [], + "type": "TSNonNullExpression", + "expression": { + "type": "Identifier", + "name": "promise", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 36 + }, + "end": { + "line": 35, + "column": 43 + } + } + }, "loc": { "start": { "line": 35, - "column": 29 + "column": 36 }, "end": { "line": 35, - "column": 36 + "column": 44 } } }, "loc": { "start": { "line": 35, - "column": 23 + "column": 30 }, "end": { "line": 35, - "column": 37 + "column": 45 } } }, @@ -2042,7 +2527,7 @@ }, "end": { "line": 35, - "column": 37 + "column": 45 } } } @@ -2055,7 +2540,7 @@ }, "end": { "line": 35, - "column": 37 + "column": 45 } } } @@ -2191,35 +2676,88 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Promise", - "decorators": [], - "loc": { - "start": { - "line": 38, - "column": 14 + "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 + } + } }, - "end": { - "line": 38, - "column": 21 - } - } - }, - "typeParams": { - "type": "TSTypeParameterInstantiation", - "params": [ - { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSUnionType", + "types": [ + { + "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": 30 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 22 + }, + "end": { + "line": 38, + "column": 30 + } + } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 38, + "column": 31 + }, + "end": { + "line": 38, + "column": 35 + } + } + } + ], "loc": { "start": { "line": 38, @@ -2227,55 +2765,58 @@ }, "end": { "line": 38, - "column": 28 + "column": 35 } } - }, - "loc": { - "start": { - "line": 38, - "column": 22 - }, - "end": { - "line": 38, - "column": 29 - } } - }, + ], "loc": { "start": { "line": 38, - "column": 22 + "column": 21 }, "end": { "line": 38, - "column": 29 + "column": 36 } } + }, + "loc": { + "start": { + "line": 38, + "column": 14 + }, + "end": { + "line": 38, + "column": 38 + } } - ], + }, "loc": { "start": { "line": 38, - "column": 21 + "column": 14 }, "end": { "line": 38, - "column": 29 + "column": 38 } } }, - "loc": { - "start": { - "line": 38, - "column": 14 - }, - "end": { - "line": 38, - "column": 31 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 38, + "column": 39 + }, + "end": { + "line": 38, + "column": 43 + } } } - }, + ], "loc": { "start": { "line": 38, @@ -2283,7 +2824,7 @@ }, "end": { "line": 38, - "column": 31 + "column": 43 } } }, @@ -2296,7 +2837,7 @@ }, "end": { "line": 38, - "column": 31 + "column": 43 } } }, @@ -2324,13 +2865,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 10 + }, + "end": { + "line": 39, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 10 + }, + "end": { + "line": 39, + "column": 18 + } + } + }, "loc": { "start": { "line": 39, @@ -2338,21 +2904,24 @@ }, "end": { "line": 39, - "column": 16 + "column": 18 } } }, - "loc": { - "start": { - "line": 39, - "column": 10 - }, - "end": { - "line": 39, - "column": 18 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 39, + "column": 19 + }, + "end": { + "line": 39, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 39, @@ -2360,7 +2929,7 @@ }, "end": { "line": 39, - "column": 18 + "column": 23 } } }, @@ -2373,7 +2942,7 @@ }, "end": { "line": 39, - "column": 18 + "column": 23 } } } diff --git a/ets2panda/test/parser/ets/await_keyword.ets b/ets2panda/test/parser/ets/await_keyword.ets index a12846bd93cb69719a768c8fbe986830b66720fa..d1165c90c4da9279e032ab36b10fb25dfb9e166e 100644 --- a/ets2panda/test/parser/ets/await_keyword.ets +++ b/ets2panda/test/parser/ets/await_keyword.ets @@ -13,27 +13,27 @@ * limitations under the License. */ -async function asyncFoo(): Promise | null { - let promise: Promise | null = null; - let obj: Object = await promise; +async function asyncFoo(): Promise { + let promise: Promise | null = null; + let obj: Object | null = await promise!; return promise; } -let asyncLambda: () => Promise | null = async (): Promise | null => { - let promise: Promise | null = null; - let obj: Object = await promise; +let asyncLambda: () => Promise = async (): Promise => { + let promise: Promise | null = null; + let obj: Object | null = await promise!; return promise; } function foo(): void { - let promise: Promise | null = null; - let obj: Object = await promise; + let promise: Promise | null = null; + let obj: Object | null = await promise!; } let lambda: () => void = (): void => { - let promise: Promise | null = null; - let obj: Object = await promise; + let promise: Promise | null = null; + let obj: Object | null = await promise!; } -let promise: Promise | null = null; -let obj: Object = await promise; +let promise: Promise | null = null; +let obj: Object | null = await promise!; diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index f491c8074d578921dbadc41b6583978df7d70555..236412573011d97f1796e515513040139fb18188 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -5325,13 +5325,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 22, @@ -5339,21 +5364,24 @@ }, "end": { "line": 22, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 22, - "column": 9 - }, - "end": { - "line": 22, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 22, + "column": 18 + }, + "end": { + "line": 22, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 22, @@ -5361,7 +5389,7 @@ }, "end": { "line": 22, - "column": 17 + "column": 22 } } }, @@ -5374,7 +5402,7 @@ }, "end": { "line": 22, - "column": 17 + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/cast_expressions-expected.txt b/ets2panda/test/parser/ets/cast_expressions-expected.txt index 9d787e3515c8a646761b8ef9fb751e0378698c13..ce3c9ff7fbefe3afd659a0764aa39f9d8d6e9914 100644 --- a/ets2panda/test/parser/ets/cast_expressions-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions-expected.txt @@ -116,1038 +116,6 @@ } } }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "null_test", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10 - }, - "end": { - "line": 16, - "column": 19 - } - } - }, - "kind": "method", - "accessibility": "public", - "static": true, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "null_test", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10 - }, - "end": { - "line": 16, - "column": 19 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "void", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 16, - "column": 27 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 16, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 16, - "column": 29 - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Byte_", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 7 - }, - "end": { - "line": 17, - "column": 12 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Byte", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 17 - }, - "end": { - "line": 17, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 7 - }, - "end": { - "line": 17, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 17, - "column": 3 - }, - "end": { - "line": 17, - "column": 30 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Short_", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 7 - }, - "end": { - "line": 18, - "column": 13 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 18, - "column": 17 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Short", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 25 - }, - "end": { - "line": 18, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 25 - }, - "end": { - "line": 18, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 25 - }, - "end": { - "line": 18, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 17 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 7 - }, - "end": { - "line": 18, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 18, - "column": 3 - }, - "end": { - "line": 18, - "column": 31 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Char_", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 7 - }, - "end": { - "line": 19, - "column": 12 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 19, - "column": 17 - }, - "end": { - "line": 19, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Char", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 25 - }, - "end": { - "line": 19, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 25 - }, - "end": { - "line": 19, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 25 - }, - "end": { - "line": 19, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 17 - }, - "end": { - "line": 19, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 7 - }, - "end": { - "line": 19, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 19, - "column": 3 - }, - "end": { - "line": 19, - "column": 30 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Int_", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 7 - }, - "end": { - "line": 20, - "column": 11 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 20, - "column": 17 - }, - "end": { - "line": 20, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 20, - "column": 25 - }, - "end": { - "line": 20, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 25 - }, - "end": { - "line": 20, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 25 - }, - "end": { - "line": 20, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 17 - }, - "end": { - "line": 20, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 20, - "column": 7 - }, - "end": { - "line": 20, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 20, - "column": 3 - }, - "end": { - "line": 20, - "column": 29 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Long_", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 7 - }, - "end": { - "line": 21, - "column": 12 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 21, - "column": 17 - }, - "end": { - "line": 21, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Long", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 25 - }, - "end": { - "line": 21, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 25 - }, - "end": { - "line": 21, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 25 - }, - "end": { - "line": 21, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 17 - }, - "end": { - "line": 21, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 7 - }, - "end": { - "line": 21, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 21, - "column": 3 - }, - "end": { - "line": 21, - "column": 30 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Float_", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 7 - }, - "end": { - "line": 22, - "column": 13 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 22, - "column": 17 - }, - "end": { - "line": 22, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Float", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 30 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25 - }, - "end": { - "line": 22, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 17 - }, - "end": { - "line": 22, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 7 - }, - "end": { - "line": 22, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 22, - "column": 3 - }, - "end": { - "line": 22, - "column": 31 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Double_", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 7 - }, - "end": { - "line": 23, - "column": 14 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 23, - "column": 17 - }, - "end": { - "line": 23, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Double", - "decorators": [], - "loc": { - "start": { - "line": 23, - "column": 25 - }, - "end": { - "line": 23, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 25 - }, - "end": { - "line": 23, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 25 - }, - "end": { - "line": 23, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 17 - }, - "end": { - "line": 23, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 23, - "column": 7 - }, - "end": { - "line": 23, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 23, - "column": 3 - }, - "end": { - "line": 23, - "column": 32 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 7 - }, - "end": { - "line": 24, - "column": 13 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 24, - "column": 17 - }, - "end": { - "line": 24, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 24, - "column": 25 - }, - "end": { - "line": 24, - "column": 31 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 25 - }, - "end": { - "line": 24, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 25 - }, - "end": { - "line": 24, - "column": 32 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 17 - }, - "end": { - "line": 24, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 24, - "column": 7 - }, - "end": { - "line": 24, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 24, - "column": 3 - }, - "end": { - "line": 24, - "column": 32 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 28 - }, - "end": { - "line": 25, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 25, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 19 - }, - "end": { - "line": 25, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 25, - "column": 2 - } - } - }, { "type": "MethodDefinition", "key": { @@ -1156,11 +124,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 16, "column": 10 }, "end": { - "line": 27, + "line": 16, "column": 19 } } @@ -1180,11 +148,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 16, "column": 10 }, "end": { - "line": 27, + "line": 16, "column": 19 } } @@ -1203,33 +171,33 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 16, "column": 23 }, "end": { - "line": 27, + "line": 16, "column": 27 } } }, "loc": { "start": { - "line": 27, + "line": 16, "column": 23 }, "end": { - "line": 27, + "line": 16, "column": 29 } } }, "loc": { "start": { - "line": 27, + "line": 16, "column": 23 }, "end": { - "line": 27, + "line": 16, "column": 29 } } @@ -1249,11 +217,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 28, + "line": 17, "column": 14 }, "end": { - "line": 28, + "line": 17, "column": 18 } } @@ -1261,11 +229,11 @@ "decorators": [], "loc": { "start": { - "line": 28, + "line": 17, "column": 7 }, "end": { - "line": 28, + "line": 17, "column": 12 } } @@ -1275,22 +243,22 @@ "value": 42, "loc": { "start": { - "line": 28, + "line": 17, "column": 21 }, "end": { - "line": 28, + "line": 17, "column": 23 } } }, "loc": { "start": { - "line": 28, + "line": 17, "column": 7 }, "end": { - "line": 28, + "line": 17, "column": 23 } } @@ -1299,11 +267,11 @@ "kind": "let", "loc": { "start": { - "line": 28, + "line": 17, "column": 3 }, "end": { - "line": 28, + "line": 17, "column": 24 } } @@ -1326,33 +294,33 @@ "decorators": [], "loc": { "start": { - "line": 29, + "line": 18, "column": 14 }, "end": { - "line": 29, + "line": 18, "column": 18 } } }, "loc": { "start": { - "line": 29, + "line": 18, "column": 14 }, "end": { - "line": 29, + "line": 18, "column": 20 } } }, "loc": { "start": { - "line": 29, + "line": 18, "column": 14 }, "end": { - "line": 29, + "line": 18, "column": 20 } } @@ -1360,11 +328,11 @@ "decorators": [], "loc": { "start": { - "line": 29, + "line": 18, "column": 7 }, "end": { - "line": 29, + "line": 18, "column": 12 } } @@ -1381,33 +349,33 @@ "decorators": [], "loc": { "start": { - "line": 29, + "line": 18, "column": 25 }, "end": { - "line": 29, + "line": 18, "column": 29 } } }, "loc": { "start": { - "line": 29, + "line": 18, "column": 25 }, "end": { - "line": 29, + "line": 18, "column": 30 } } }, "loc": { "start": { - "line": 29, + "line": 18, "column": 25 }, "end": { - "line": 29, + "line": 18, "column": 30 } } @@ -1420,11 +388,11 @@ "value": 42, "loc": { "start": { - "line": 29, + "line": 18, "column": 30 }, "end": { - "line": 29, + "line": 18, "column": 32 } } @@ -1433,22 +401,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 29, + "line": 18, "column": 36 }, "end": { - "line": 29, + "line": 18, "column": 40 } } }, "loc": { "start": { - "line": 29, + "line": 18, "column": 30 }, "end": { - "line": 29, + "line": 18, "column": 32 } } @@ -1456,22 +424,22 @@ ], "loc": { "start": { - "line": 29, + "line": 18, "column": 21 }, "end": { - "line": 29, + "line": 18, "column": 42 } } }, "loc": { "start": { - "line": 29, + "line": 18, "column": 7 }, "end": { - "line": 29, + "line": 18, "column": 42 } } @@ -1480,11 +448,11 @@ "kind": "let", "loc": { "start": { - "line": 29, + "line": 18, "column": 3 }, "end": { - "line": 29, + "line": 18, "column": 42 } } @@ -1503,11 +471,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 22, "column": 9 }, "end": { - "line": 33, + "line": 22, "column": 18 } } @@ -1520,11 +488,11 @@ "decorators": [], "loc": { "start": { - "line": 33, + "line": 22, "column": 23 }, "end": { - "line": 33, + "line": 22, "column": 28 } } @@ -1533,33 +501,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 33, + "line": 22, "column": 32 }, "end": { - "line": 33, + "line": 22, "column": 36 } } }, "loc": { "start": { - "line": 33, + "line": 22, "column": 23 }, "end": { - "line": 33, + "line": 22, "column": 28 } } }, "loc": { "start": { - "line": 33, + "line": 22, "column": 9 }, "end": { - "line": 33, + "line": 22, "column": 28 } } @@ -1568,11 +536,11 @@ "kind": "let", "loc": { "start": { - "line": 33, + "line": 22, "column": 5 }, "end": { - "line": 33, + "line": 22, "column": 37 } } @@ -1588,11 +556,11 @@ "decorators": [], "loc": { "start": { - "line": 34, + "line": 23, "column": 9 }, "end": { - "line": 34, + "line": 23, "column": 19 } } @@ -1605,11 +573,11 @@ "decorators": [], "loc": { "start": { - "line": 34, + "line": 23, "column": 23 }, "end": { - "line": 34, + "line": 23, "column": 28 } } @@ -1618,33 +586,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 34, + "line": 23, "column": 32 }, "end": { - "line": 34, + "line": 23, "column": 37 } } }, "loc": { "start": { - "line": 34, + "line": 23, "column": 23 }, "end": { - "line": 34, + "line": 23, "column": 28 } } }, "loc": { "start": { - "line": 34, + "line": 23, "column": 9 }, "end": { - "line": 34, + "line": 23, "column": 28 } } @@ -1653,11 +621,11 @@ "kind": "let", "loc": { "start": { - "line": 34, + "line": 23, "column": 5 }, "end": { - "line": 34, + "line": 23, "column": 38 } } @@ -1673,11 +641,11 @@ "decorators": [], "loc": { "start": { - "line": 35, + "line": 24, "column": 9 }, "end": { - "line": 35, + "line": 24, "column": 18 } } @@ -1690,11 +658,11 @@ "decorators": [], "loc": { "start": { - "line": 35, + "line": 24, "column": 23 }, "end": { - "line": 35, + "line": 24, "column": 28 } } @@ -1703,33 +671,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 35, + "line": 24, "column": 32 }, "end": { - "line": 35, + "line": 24, "column": 36 } } }, "loc": { "start": { - "line": 35, + "line": 24, "column": 23 }, "end": { - "line": 35, + "line": 24, "column": 28 } } }, "loc": { "start": { - "line": 35, + "line": 24, "column": 9 }, "end": { - "line": 35, + "line": 24, "column": 28 } } @@ -1738,11 +706,11 @@ "kind": "let", "loc": { "start": { - "line": 35, + "line": 24, "column": 5 }, "end": { - "line": 35, + "line": 24, "column": 37 } } @@ -1758,11 +726,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 25, "column": 9 }, "end": { - "line": 36, + "line": 25, "column": 17 } } @@ -1775,11 +743,11 @@ "decorators": [], "loc": { "start": { - "line": 36, + "line": 25, "column": 23 }, "end": { - "line": 36, + "line": 25, "column": 28 } } @@ -1788,33 +756,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 36, + "line": 25, "column": 32 }, "end": { - "line": 36, + "line": 25, "column": 35 } } }, "loc": { "start": { - "line": 36, + "line": 25, "column": 23 }, "end": { - "line": 36, + "line": 25, "column": 28 } } }, "loc": { "start": { - "line": 36, + "line": 25, "column": 9 }, "end": { - "line": 36, + "line": 25, "column": 28 } } @@ -1823,11 +791,11 @@ "kind": "let", "loc": { "start": { - "line": 36, + "line": 25, "column": 5 }, "end": { - "line": 36, + "line": 25, "column": 36 } } @@ -1843,11 +811,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 26, "column": 9 }, "end": { - "line": 37, + "line": 26, "column": 18 } } @@ -1860,11 +828,11 @@ "decorators": [], "loc": { "start": { - "line": 37, + "line": 26, "column": 23 }, "end": { - "line": 37, + "line": 26, "column": 28 } } @@ -1873,33 +841,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 37, + "line": 26, "column": 32 }, "end": { - "line": 37, + "line": 26, "column": 36 } } }, "loc": { "start": { - "line": 37, + "line": 26, "column": 23 }, "end": { - "line": 37, + "line": 26, "column": 28 } } }, "loc": { "start": { - "line": 37, + "line": 26, "column": 9 }, "end": { - "line": 37, + "line": 26, "column": 28 } } @@ -1908,11 +876,11 @@ "kind": "let", "loc": { "start": { - "line": 37, + "line": 26, "column": 5 }, "end": { - "line": 37, + "line": 26, "column": 37 } } @@ -1928,11 +896,11 @@ "decorators": [], "loc": { "start": { - "line": 38, + "line": 27, "column": 9 }, "end": { - "line": 38, + "line": 27, "column": 19 } } @@ -1945,11 +913,11 @@ "decorators": [], "loc": { "start": { - "line": 38, + "line": 27, "column": 23 }, "end": { - "line": 38, + "line": 27, "column": 28 } } @@ -1958,33 +926,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 38, + "line": 27, "column": 32 }, "end": { - "line": 38, + "line": 27, "column": 37 } } }, "loc": { "start": { - "line": 38, + "line": 27, "column": 23 }, "end": { - "line": 38, + "line": 27, "column": 28 } } }, "loc": { "start": { - "line": 38, + "line": 27, "column": 9 }, "end": { - "line": 38, + "line": 27, "column": 28 } } @@ -1993,11 +961,11 @@ "kind": "let", "loc": { "start": { - "line": 38, + "line": 27, "column": 5 }, "end": { - "line": 38, + "line": 27, "column": 38 } } @@ -2013,11 +981,11 @@ "decorators": [], "loc": { "start": { - "line": 39, + "line": 28, "column": 9 }, "end": { - "line": 39, + "line": 28, "column": 20 } } @@ -2030,11 +998,11 @@ "decorators": [], "loc": { "start": { - "line": 39, + "line": 28, "column": 23 }, "end": { - "line": 39, + "line": 28, "column": 28 } } @@ -2043,33 +1011,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 39, + "line": 28, "column": 32 }, "end": { - "line": 39, + "line": 28, "column": 38 } } }, "loc": { "start": { - "line": 39, + "line": 28, "column": 23 }, "end": { - "line": 39, + "line": 28, "column": 28 } } }, "loc": { "start": { - "line": 39, + "line": 28, "column": 9 }, "end": { - "line": 39, + "line": 28, "column": 28 } } @@ -2078,11 +1046,11 @@ "kind": "let", "loc": { "start": { - "line": 39, + "line": 28, "column": 5 }, "end": { - "line": 39, + "line": 28, "column": 39 } } @@ -2098,11 +1066,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 30, "column": 9 }, "end": { - "line": 41, + "line": 30, "column": 18 } } @@ -2115,11 +1083,11 @@ "decorators": [], "loc": { "start": { - "line": 41, + "line": 30, "column": 23 }, "end": { - "line": 41, + "line": 30, "column": 28 } } @@ -2128,33 +1096,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 41, + "line": 30, "column": 32 }, "end": { - "line": 41, + "line": 30, "column": 36 } } }, "loc": { "start": { - "line": 41, + "line": 30, "column": 23 }, "end": { - "line": 41, + "line": 30, "column": 28 } } }, "loc": { "start": { - "line": 41, + "line": 30, "column": 9 }, "end": { - "line": 41, + "line": 30, "column": 28 } } @@ -2163,11 +1131,11 @@ "kind": "let", "loc": { "start": { - "line": 41, + "line": 30, "column": 5 }, "end": { - "line": 41, + "line": 30, "column": 37 } } @@ -2183,11 +1151,11 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 31, "column": 9 }, "end": { - "line": 42, + "line": 31, "column": 19 } } @@ -2200,11 +1168,11 @@ "decorators": [], "loc": { "start": { - "line": 42, + "line": 31, "column": 23 }, "end": { - "line": 42, + "line": 31, "column": 28 } } @@ -2213,33 +1181,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 42, + "line": 31, "column": 32 }, "end": { - "line": 42, + "line": 31, "column": 37 } } }, "loc": { "start": { - "line": 42, + "line": 31, "column": 23 }, "end": { - "line": 42, + "line": 31, "column": 28 } } }, "loc": { "start": { - "line": 42, + "line": 31, "column": 9 }, "end": { - "line": 42, + "line": 31, "column": 28 } } @@ -2248,11 +1216,11 @@ "kind": "let", "loc": { "start": { - "line": 42, + "line": 31, "column": 5 }, "end": { - "line": 42, + "line": 31, "column": 38 } } @@ -2268,11 +1236,11 @@ "decorators": [], "loc": { "start": { - "line": 43, + "line": 32, "column": 9 }, "end": { - "line": 43, + "line": 32, "column": 17 } } @@ -2285,11 +1253,11 @@ "decorators": [], "loc": { "start": { - "line": 43, + "line": 32, "column": 23 }, "end": { - "line": 43, + "line": 32, "column": 28 } } @@ -2298,33 +1266,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 43, + "line": 32, "column": 32 }, "end": { - "line": 43, + "line": 32, "column": 35 } } }, "loc": { "start": { - "line": 43, + "line": 32, "column": 23 }, "end": { - "line": 43, + "line": 32, "column": 28 } } }, "loc": { "start": { - "line": 43, + "line": 32, "column": 9 }, "end": { - "line": 43, + "line": 32, "column": 28 } } @@ -2333,11 +1301,11 @@ "kind": "let", "loc": { "start": { - "line": 43, + "line": 32, "column": 5 }, "end": { - "line": 43, + "line": 32, "column": 36 } } @@ -2353,11 +1321,11 @@ "decorators": [], "loc": { "start": { - "line": 44, + "line": 33, "column": 9 }, "end": { - "line": 44, + "line": 33, "column": 18 } } @@ -2370,11 +1338,11 @@ "decorators": [], "loc": { "start": { - "line": 44, + "line": 33, "column": 23 }, "end": { - "line": 44, + "line": 33, "column": 28 } } @@ -2383,33 +1351,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 44, + "line": 33, "column": 32 }, "end": { - "line": 44, + "line": 33, "column": 36 } } }, "loc": { "start": { - "line": 44, + "line": 33, "column": 23 }, "end": { - "line": 44, + "line": 33, "column": 28 } } }, "loc": { "start": { - "line": 44, + "line": 33, "column": 9 }, "end": { - "line": 44, + "line": 33, "column": 28 } } @@ -2418,11 +1386,11 @@ "kind": "let", "loc": { "start": { - "line": 44, + "line": 33, "column": 5 }, "end": { - "line": 44, + "line": 33, "column": 37 } } @@ -2438,11 +1406,11 @@ "decorators": [], "loc": { "start": { - "line": 45, + "line": 34, "column": 9 }, "end": { - "line": 45, + "line": 34, "column": 19 } } @@ -2455,11 +1423,11 @@ "decorators": [], "loc": { "start": { - "line": 45, + "line": 34, "column": 23 }, "end": { - "line": 45, + "line": 34, "column": 28 } } @@ -2468,33 +1436,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 45, + "line": 34, "column": 32 }, "end": { - "line": 45, + "line": 34, "column": 37 } } }, "loc": { "start": { - "line": 45, + "line": 34, "column": 23 }, "end": { - "line": 45, + "line": 34, "column": 28 } } }, "loc": { "start": { - "line": 45, + "line": 34, "column": 9 }, "end": { - "line": 45, + "line": 34, "column": 28 } } @@ -2503,11 +1471,11 @@ "kind": "let", "loc": { "start": { - "line": 45, + "line": 34, "column": 5 }, "end": { - "line": 45, + "line": 34, "column": 38 } } @@ -2523,11 +1491,11 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 35, "column": 9 }, "end": { - "line": 46, + "line": 35, "column": 20 } } @@ -2540,11 +1508,11 @@ "decorators": [], "loc": { "start": { - "line": 46, + "line": 35, "column": 23 }, "end": { - "line": 46, + "line": 35, "column": 28 } } @@ -2553,33 +1521,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 46, + "line": 35, "column": 32 }, "end": { - "line": 46, + "line": 35, "column": 38 } } }, "loc": { "start": { - "line": 46, + "line": 35, "column": 23 }, "end": { - "line": 46, + "line": 35, "column": 28 } } }, "loc": { "start": { - "line": 46, + "line": 35, "column": 9 }, "end": { - "line": 46, + "line": 35, "column": 28 } } @@ -2588,11 +1556,11 @@ "kind": "let", "loc": { "start": { - "line": 46, + "line": 35, "column": 5 }, "end": { - "line": 46, + "line": 35, "column": 39 } } @@ -2600,11 +1568,11 @@ ], "loc": { "start": { - "line": 31, + "line": 20, "column": 3 }, "end": { - "line": 47, + "line": 36, "column": 4 } } @@ -2623,11 +1591,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 40, "column": 9 }, "end": { - "line": 51, + "line": 40, "column": 18 } } @@ -2640,11 +1608,11 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 40, "column": 23 }, "end": { - "line": 51, + "line": 40, "column": 28 } } @@ -2659,55 +1627,55 @@ "decorators": [], "loc": { "start": { - "line": 51, + "line": 40, "column": 32 }, "end": { - "line": 51, + "line": 40, "column": 36 } } }, "loc": { "start": { - "line": 51, + "line": 40, "column": 32 }, "end": { - "line": 51, + "line": 40, "column": 37 } } }, "loc": { "start": { - "line": 51, + "line": 40, "column": 32 }, "end": { - "line": 51, + "line": 40, "column": 37 } } }, "loc": { "start": { - "line": 51, + "line": 40, "column": 23 }, "end": { - "line": 51, + "line": 40, "column": 28 } } }, "loc": { "start": { - "line": 51, + "line": 40, "column": 9 }, "end": { - "line": 51, + "line": 40, "column": 28 } } @@ -2716,11 +1684,11 @@ "kind": "let", "loc": { "start": { - "line": 51, + "line": 40, "column": 5 }, "end": { - "line": 51, + "line": 40, "column": 37 } } @@ -2736,11 +1704,11 @@ "decorators": [], "loc": { "start": { - "line": 52, + "line": 41, "column": 9 }, "end": { - "line": 52, + "line": 41, "column": 18 } } @@ -2753,11 +1721,11 @@ "decorators": [], "loc": { "start": { - "line": 52, + "line": 41, "column": 23 }, "end": { - "line": 52, + "line": 41, "column": 28 } } @@ -2772,55 +1740,55 @@ "decorators": [], "loc": { "start": { - "line": 52, + "line": 41, "column": 32 }, "end": { - "line": 52, + "line": 41, "column": 36 } } }, "loc": { "start": { - "line": 52, + "line": 41, "column": 32 }, "end": { - "line": 52, + "line": 41, "column": 37 } } }, "loc": { "start": { - "line": 52, + "line": 41, "column": 32 }, "end": { - "line": 52, + "line": 41, "column": 37 } } }, "loc": { "start": { - "line": 52, + "line": 41, "column": 23 }, "end": { - "line": 52, + "line": 41, "column": 28 } } }, "loc": { "start": { - "line": 52, + "line": 41, "column": 9 }, "end": { - "line": 52, + "line": 41, "column": 28 } } @@ -2829,11 +1797,11 @@ "kind": "let", "loc": { "start": { - "line": 52, + "line": 41, "column": 5 }, "end": { - "line": 52, + "line": 41, "column": 37 } } @@ -2849,11 +1817,11 @@ "decorators": [], "loc": { "start": { - "line": 53, + "line": 42, "column": 9 }, "end": { - "line": 53, + "line": 42, "column": 20 } } @@ -2866,11 +1834,11 @@ "decorators": [], "loc": { "start": { - "line": 53, + "line": 42, "column": 23 }, "end": { - "line": 53, + "line": 42, "column": 28 } } @@ -2885,55 +1853,55 @@ "decorators": [], "loc": { "start": { - "line": 53, + "line": 42, "column": 32 }, "end": { - "line": 53, + "line": 42, "column": 38 } } }, "loc": { "start": { - "line": 53, + "line": 42, "column": 32 }, "end": { - "line": 53, + "line": 42, "column": 39 } } }, "loc": { "start": { - "line": 53, + "line": 42, "column": 32 }, "end": { - "line": 53, + "line": 42, "column": 39 } } }, "loc": { "start": { - "line": 53, + "line": 42, "column": 23 }, "end": { - "line": 53, + "line": 42, "column": 28 } } }, "loc": { "start": { - "line": 53, + "line": 42, "column": 9 }, "end": { - "line": 53, + "line": 42, "column": 28 } } @@ -2942,11 +1910,11 @@ "kind": "let", "loc": { "start": { - "line": 53, + "line": 42, "column": 5 }, "end": { - "line": 53, + "line": 42, "column": 39 } } @@ -2954,11 +1922,11 @@ ], "loc": { "start": { - "line": 49, + "line": 38, "column": 3 }, "end": { - "line": 54, + "line": 43, "column": 4 } } @@ -2966,33 +1934,33 @@ ], "loc": { "start": { - "line": 27, + "line": 16, "column": 28 }, "end": { - "line": 55, + "line": 44, "column": 2 } } }, "loc": { "start": { - "line": 27, + "line": 16, "column": 19 }, "end": { - "line": 55, + "line": 44, "column": 2 } } }, "loc": { "start": { - "line": 27, + "line": 16, "column": 19 }, "end": { - "line": 55, + "line": 44, "column": 2 } } @@ -3001,11 +1969,11 @@ "decorators": [], "loc": { "start": { - "line": 27, + "line": 16, "column": 1 }, "end": { - "line": 55, + "line": 44, "column": 2 } } @@ -3018,11 +1986,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 46, "column": 10 }, "end": { - "line": 57, + "line": 46, "column": 20 } } @@ -3042,11 +2010,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 46, "column": 10 }, "end": { - "line": 57, + "line": 46, "column": 20 } } @@ -3065,33 +2033,33 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 46, "column": 24 }, "end": { - "line": 57, + "line": 46, "column": 28 } } }, "loc": { "start": { - "line": 57, + "line": 46, "column": 24 }, "end": { - "line": 57, + "line": 46, "column": 30 } } }, "loc": { "start": { - "line": 57, + "line": 46, "column": 24 }, "end": { - "line": 57, + "line": 46, "column": 30 } } @@ -3111,11 +2079,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 58, + "line": 47, "column": 15 }, "end": { - "line": 58, + "line": 47, "column": 20 } } @@ -3123,11 +2091,11 @@ "decorators": [], "loc": { "start": { - "line": 58, + "line": 47, "column": 7 }, "end": { - "line": 58, + "line": 47, "column": 13 } } @@ -3137,22 +2105,22 @@ "value": 42, "loc": { "start": { - "line": 58, + "line": 47, "column": 23 }, "end": { - "line": 58, + "line": 47, "column": 25 } } }, "loc": { "start": { - "line": 58, + "line": 47, "column": 7 }, "end": { - "line": 58, + "line": 47, "column": 25 } } @@ -3161,11 +2129,11 @@ "kind": "let", "loc": { "start": { - "line": 58, + "line": 47, "column": 3 }, "end": { - "line": 58, + "line": 47, "column": 26 } } @@ -3188,33 +2156,33 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 48, "column": 15 }, "end": { - "line": 59, + "line": 48, "column": 20 } } }, "loc": { "start": { - "line": 59, + "line": 48, "column": 15 }, "end": { - "line": 59, + "line": 48, "column": 22 } } }, "loc": { "start": { - "line": 59, + "line": 48, "column": 15 }, "end": { - "line": 59, + "line": 48, "column": 22 } } @@ -3222,11 +2190,11 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 48, "column": 7 }, "end": { - "line": 59, + "line": 48, "column": 13 } } @@ -3243,33 +2211,33 @@ "decorators": [], "loc": { "start": { - "line": 59, + "line": 48, "column": 27 }, "end": { - "line": 59, + "line": 48, "column": 32 } } }, "loc": { "start": { - "line": 59, + "line": 48, "column": 27 }, "end": { - "line": 59, + "line": 48, "column": 33 } } }, "loc": { "start": { - "line": 59, + "line": 48, "column": 27 }, "end": { - "line": 59, + "line": 48, "column": 33 } } @@ -3282,11 +2250,11 @@ "value": 42, "loc": { "start": { - "line": 59, + "line": 48, "column": 33 }, "end": { - "line": 59, + "line": 48, "column": 35 } } @@ -3295,22 +2263,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 59, + "line": 48, "column": 39 }, "end": { - "line": 59, + "line": 48, "column": 44 } } }, "loc": { "start": { - "line": 59, + "line": 48, "column": 33 }, "end": { - "line": 59, + "line": 48, "column": 35 } } @@ -3318,22 +2286,22 @@ ], "loc": { "start": { - "line": 59, + "line": 48, "column": 23 }, "end": { - "line": 59, + "line": 48, "column": 46 } } }, "loc": { "start": { - "line": 59, + "line": 48, "column": 7 }, "end": { - "line": 59, + "line": 48, "column": 46 } } @@ -3342,11 +2310,11 @@ "kind": "let", "loc": { "start": { - "line": 59, + "line": 48, "column": 3 }, "end": { - "line": 59, + "line": 48, "column": 46 } } @@ -3365,11 +2333,11 @@ "decorators": [], "loc": { "start": { - "line": 63, + "line": 52, "column": 9 }, "end": { - "line": 63, + "line": 52, "column": 19 } } @@ -3382,11 +2350,11 @@ "decorators": [], "loc": { "start": { - "line": 63, + "line": 52, "column": 24 }, "end": { - "line": 63, + "line": 52, "column": 30 } } @@ -3395,33 +2363,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 63, + "line": 52, "column": 34 }, "end": { - "line": 63, + "line": 52, "column": 38 } } }, "loc": { "start": { - "line": 63, + "line": 52, "column": 24 }, "end": { - "line": 63, + "line": 52, "column": 30 } } }, "loc": { "start": { - "line": 63, + "line": 52, "column": 9 }, "end": { - "line": 63, + "line": 52, "column": 30 } } @@ -3430,11 +2398,11 @@ "kind": "let", "loc": { "start": { - "line": 63, + "line": 52, "column": 5 }, "end": { - "line": 63, + "line": 52, "column": 39 } } @@ -3450,11 +2418,11 @@ "decorators": [], "loc": { "start": { - "line": 64, + "line": 53, "column": 9 }, "end": { - "line": 64, + "line": 53, "column": 20 } } @@ -3467,11 +2435,11 @@ "decorators": [], "loc": { "start": { - "line": 64, + "line": 53, "column": 24 }, "end": { - "line": 64, + "line": 53, "column": 30 } } @@ -3480,33 +2448,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 64, + "line": 53, "column": 34 }, "end": { - "line": 64, + "line": 53, "column": 39 } } }, "loc": { "start": { - "line": 64, + "line": 53, "column": 24 }, "end": { - "line": 64, + "line": 53, "column": 30 } } }, "loc": { "start": { - "line": 64, + "line": 53, "column": 9 }, "end": { - "line": 64, + "line": 53, "column": 30 } } @@ -3515,11 +2483,11 @@ "kind": "let", "loc": { "start": { - "line": 64, + "line": 53, "column": 5 }, "end": { - "line": 64, + "line": 53, "column": 40 } } @@ -3535,11 +2503,11 @@ "decorators": [], "loc": { "start": { - "line": 65, + "line": 54, "column": 9 }, "end": { - "line": 65, + "line": 54, "column": 19 } } @@ -3552,11 +2520,11 @@ "decorators": [], "loc": { "start": { - "line": 65, + "line": 54, "column": 24 }, "end": { - "line": 65, + "line": 54, "column": 30 } } @@ -3565,33 +2533,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 65, + "line": 54, "column": 34 }, "end": { - "line": 65, + "line": 54, "column": 38 } } }, "loc": { "start": { - "line": 65, + "line": 54, "column": 24 }, "end": { - "line": 65, + "line": 54, "column": 30 } } }, "loc": { "start": { - "line": 65, + "line": 54, "column": 9 }, "end": { - "line": 65, + "line": 54, "column": 30 } } @@ -3600,11 +2568,11 @@ "kind": "let", "loc": { "start": { - "line": 65, + "line": 54, "column": 5 }, "end": { - "line": 65, + "line": 54, "column": 39 } } @@ -3620,11 +2588,11 @@ "decorators": [], "loc": { "start": { - "line": 66, + "line": 55, "column": 9 }, "end": { - "line": 66, + "line": 55, "column": 18 } } @@ -3637,11 +2605,11 @@ "decorators": [], "loc": { "start": { - "line": 66, + "line": 55, "column": 24 }, "end": { - "line": 66, + "line": 55, "column": 30 } } @@ -3650,33 +2618,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 66, + "line": 55, "column": 34 }, "end": { - "line": 66, + "line": 55, "column": 37 } } }, "loc": { "start": { - "line": 66, + "line": 55, "column": 24 }, "end": { - "line": 66, + "line": 55, "column": 30 } } }, "loc": { "start": { - "line": 66, + "line": 55, "column": 9 }, "end": { - "line": 66, + "line": 55, "column": 30 } } @@ -3685,11 +2653,11 @@ "kind": "let", "loc": { "start": { - "line": 66, + "line": 55, "column": 5 }, "end": { - "line": 66, + "line": 55, "column": 38 } } @@ -3705,11 +2673,11 @@ "decorators": [], "loc": { "start": { - "line": 67, + "line": 56, "column": 9 }, "end": { - "line": 67, + "line": 56, "column": 19 } } @@ -3722,11 +2690,11 @@ "decorators": [], "loc": { "start": { - "line": 67, + "line": 56, "column": 24 }, "end": { - "line": 67, + "line": 56, "column": 30 } } @@ -3735,33 +2703,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 67, + "line": 56, "column": 34 }, "end": { - "line": 67, + "line": 56, "column": 38 } } }, "loc": { "start": { - "line": 67, + "line": 56, "column": 24 }, "end": { - "line": 67, + "line": 56, "column": 30 } } }, "loc": { "start": { - "line": 67, + "line": 56, "column": 9 }, "end": { - "line": 67, + "line": 56, "column": 30 } } @@ -3770,11 +2738,11 @@ "kind": "let", "loc": { "start": { - "line": 67, + "line": 56, "column": 5 }, "end": { - "line": 67, + "line": 56, "column": 39 } } @@ -3790,11 +2758,11 @@ "decorators": [], "loc": { "start": { - "line": 68, + "line": 57, "column": 9 }, "end": { - "line": 68, + "line": 57, "column": 20 } } @@ -3807,11 +2775,11 @@ "decorators": [], "loc": { "start": { - "line": 68, + "line": 57, "column": 24 }, "end": { - "line": 68, + "line": 57, "column": 30 } } @@ -3820,33 +2788,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 68, + "line": 57, "column": 34 }, "end": { - "line": 68, + "line": 57, "column": 39 } } }, "loc": { "start": { - "line": 68, + "line": 57, "column": 24 }, "end": { - "line": 68, + "line": 57, "column": 30 } } }, "loc": { "start": { - "line": 68, + "line": 57, "column": 9 }, "end": { - "line": 68, + "line": 57, "column": 30 } } @@ -3855,11 +2823,11 @@ "kind": "let", "loc": { "start": { - "line": 68, + "line": 57, "column": 5 }, "end": { - "line": 68, + "line": 57, "column": 40 } } @@ -3875,11 +2843,11 @@ "decorators": [], "loc": { "start": { - "line": 69, + "line": 58, "column": 9 }, "end": { - "line": 69, + "line": 58, "column": 21 } } @@ -3892,11 +2860,11 @@ "decorators": [], "loc": { "start": { - "line": 69, + "line": 58, "column": 24 }, "end": { - "line": 69, + "line": 58, "column": 30 } } @@ -3905,33 +2873,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 69, + "line": 58, "column": 34 }, "end": { - "line": 69, + "line": 58, "column": 40 } } }, "loc": { "start": { - "line": 69, + "line": 58, "column": 24 }, "end": { - "line": 69, + "line": 58, "column": 30 } } }, "loc": { "start": { - "line": 69, + "line": 58, "column": 9 }, "end": { - "line": 69, + "line": 58, "column": 30 } } @@ -3940,11 +2908,11 @@ "kind": "let", "loc": { "start": { - "line": 69, + "line": 58, "column": 5 }, "end": { - "line": 69, + "line": 58, "column": 41 } } @@ -3960,11 +2928,11 @@ "decorators": [], "loc": { "start": { - "line": 71, + "line": 60, "column": 9 }, "end": { - "line": 71, + "line": 60, "column": 20 } } @@ -3977,11 +2945,11 @@ "decorators": [], "loc": { "start": { - "line": 71, + "line": 60, "column": 24 }, "end": { - "line": 71, + "line": 60, "column": 30 } } @@ -3990,33 +2958,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 71, + "line": 60, "column": 34 }, "end": { - "line": 71, + "line": 60, "column": 39 } } }, "loc": { "start": { - "line": 71, + "line": 60, "column": 24 }, "end": { - "line": 71, + "line": 60, "column": 30 } } }, "loc": { "start": { - "line": 71, + "line": 60, "column": 9 }, "end": { - "line": 71, + "line": 60, "column": 30 } } @@ -4025,11 +2993,11 @@ "kind": "let", "loc": { "start": { - "line": 71, + "line": 60, "column": 5 }, "end": { - "line": 71, + "line": 60, "column": 40 } } @@ -4045,11 +3013,11 @@ "decorators": [], "loc": { "start": { - "line": 72, + "line": 61, "column": 9 }, "end": { - "line": 72, + "line": 61, "column": 18 } } @@ -4062,11 +3030,11 @@ "decorators": [], "loc": { "start": { - "line": 72, + "line": 61, "column": 24 }, "end": { - "line": 72, + "line": 61, "column": 30 } } @@ -4075,33 +3043,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 72, + "line": 61, "column": 34 }, "end": { - "line": 72, + "line": 61, "column": 37 } } }, "loc": { "start": { - "line": 72, + "line": 61, "column": 24 }, "end": { - "line": 72, + "line": 61, "column": 30 } } }, "loc": { "start": { - "line": 72, + "line": 61, "column": 9 }, "end": { - "line": 72, + "line": 61, "column": 30 } } @@ -4110,11 +3078,11 @@ "kind": "let", "loc": { "start": { - "line": 72, + "line": 61, "column": 5 }, "end": { - "line": 72, + "line": 61, "column": 38 } } @@ -4130,11 +3098,11 @@ "decorators": [], "loc": { "start": { - "line": 73, + "line": 62, "column": 9 }, "end": { - "line": 73, + "line": 62, "column": 19 } } @@ -4147,11 +3115,11 @@ "decorators": [], "loc": { "start": { - "line": 73, + "line": 62, "column": 24 }, "end": { - "line": 73, + "line": 62, "column": 30 } } @@ -4160,33 +3128,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 73, + "line": 62, "column": 34 }, "end": { - "line": 73, + "line": 62, "column": 38 } } }, "loc": { "start": { - "line": 73, + "line": 62, "column": 24 }, "end": { - "line": 73, + "line": 62, "column": 30 } } }, "loc": { "start": { - "line": 73, + "line": 62, "column": 9 }, "end": { - "line": 73, + "line": 62, "column": 30 } } @@ -4195,11 +3163,11 @@ "kind": "let", "loc": { "start": { - "line": 73, + "line": 62, "column": 5 }, "end": { - "line": 73, + "line": 62, "column": 39 } } @@ -4215,11 +3183,11 @@ "decorators": [], "loc": { "start": { - "line": 74, + "line": 63, "column": 9 }, "end": { - "line": 74, + "line": 63, "column": 20 } } @@ -4232,11 +3200,11 @@ "decorators": [], "loc": { "start": { - "line": 74, + "line": 63, "column": 24 }, "end": { - "line": 74, + "line": 63, "column": 30 } } @@ -4245,33 +3213,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 74, + "line": 63, "column": 34 }, "end": { - "line": 74, + "line": 63, "column": 39 } } }, "loc": { "start": { - "line": 74, + "line": 63, "column": 24 }, "end": { - "line": 74, + "line": 63, "column": 30 } } }, "loc": { "start": { - "line": 74, + "line": 63, "column": 9 }, "end": { - "line": 74, + "line": 63, "column": 30 } } @@ -4280,11 +3248,11 @@ "kind": "let", "loc": { "start": { - "line": 74, + "line": 63, "column": 5 }, "end": { - "line": 74, + "line": 63, "column": 40 } } @@ -4300,11 +3268,11 @@ "decorators": [], "loc": { "start": { - "line": 75, + "line": 64, "column": 9 }, "end": { - "line": 75, + "line": 64, "column": 21 } } @@ -4317,11 +3285,11 @@ "decorators": [], "loc": { "start": { - "line": 75, + "line": 64, "column": 24 }, "end": { - "line": 75, + "line": 64, "column": 30 } } @@ -4330,33 +3298,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 75, + "line": 64, "column": 34 }, "end": { - "line": 75, + "line": 64, "column": 40 } } }, "loc": { "start": { - "line": 75, + "line": 64, "column": 24 }, "end": { - "line": 75, + "line": 64, "column": 30 } } }, "loc": { "start": { - "line": 75, + "line": 64, "column": 9 }, "end": { - "line": 75, + "line": 64, "column": 30 } } @@ -4365,11 +3333,11 @@ "kind": "let", "loc": { "start": { - "line": 75, + "line": 64, "column": 5 }, "end": { - "line": 75, + "line": 64, "column": 41 } } @@ -4377,11 +3345,11 @@ ], "loc": { "start": { - "line": 61, + "line": 50, "column": 3 }, "end": { - "line": 76, + "line": 65, "column": 4 } } @@ -4400,11 +3368,11 @@ "decorators": [], "loc": { "start": { - "line": 80, + "line": 69, "column": 9 }, "end": { - "line": 80, + "line": 69, "column": 20 } } @@ -4417,11 +3385,11 @@ "decorators": [], "loc": { "start": { - "line": 80, + "line": 69, "column": 25 }, "end": { - "line": 80, + "line": 69, "column": 31 } } @@ -4436,55 +3404,55 @@ "decorators": [], "loc": { "start": { - "line": 80, + "line": 69, "column": 35 }, "end": { - "line": 80, + "line": 69, "column": 40 } } }, "loc": { "start": { - "line": 80, + "line": 69, "column": 35 }, "end": { - "line": 80, + "line": 69, "column": 41 } } }, "loc": { "start": { - "line": 80, + "line": 69, "column": 35 }, "end": { - "line": 80, + "line": 69, "column": 41 } } }, "loc": { "start": { - "line": 80, + "line": 69, "column": 25 }, "end": { - "line": 80, + "line": 69, "column": 31 } } }, "loc": { "start": { - "line": 80, + "line": 69, "column": 9 }, "end": { - "line": 80, + "line": 69, "column": 31 } } @@ -4493,11 +3461,11 @@ "kind": "let", "loc": { "start": { - "line": 80, + "line": 69, "column": 5 }, "end": { - "line": 80, + "line": 69, "column": 41 } } @@ -4513,11 +3481,11 @@ "decorators": [], "loc": { "start": { - "line": 81, + "line": 70, "column": 9 }, "end": { - "line": 81, + "line": 70, "column": 20 } } @@ -4530,11 +3498,11 @@ "decorators": [], "loc": { "start": { - "line": 81, + "line": 70, "column": 25 }, "end": { - "line": 81, + "line": 70, "column": 31 } } @@ -4549,55 +3517,55 @@ "decorators": [], "loc": { "start": { - "line": 81, + "line": 70, "column": 35 }, "end": { - "line": 81, + "line": 70, "column": 40 } } }, "loc": { "start": { - "line": 81, + "line": 70, "column": 35 }, "end": { - "line": 81, + "line": 70, "column": 41 } } }, "loc": { "start": { - "line": 81, + "line": 70, "column": 35 }, "end": { - "line": 81, + "line": 70, "column": 41 } } }, "loc": { "start": { - "line": 81, + "line": 70, "column": 25 }, "end": { - "line": 81, + "line": 70, "column": 31 } } }, "loc": { "start": { - "line": 81, + "line": 70, "column": 9 }, "end": { - "line": 81, + "line": 70, "column": 31 } } @@ -4606,11 +3574,11 @@ "kind": "let", "loc": { "start": { - "line": 81, + "line": 70, "column": 5 }, "end": { - "line": 81, + "line": 70, "column": 41 } } @@ -4626,11 +3594,11 @@ "decorators": [], "loc": { "start": { - "line": 82, + "line": 71, "column": 9 }, "end": { - "line": 82, + "line": 71, "column": 21 } } @@ -4643,11 +3611,11 @@ "decorators": [], "loc": { "start": { - "line": 82, + "line": 71, "column": 25 }, "end": { - "line": 82, + "line": 71, "column": 31 } } @@ -4662,55 +3630,55 @@ "decorators": [], "loc": { "start": { - "line": 82, + "line": 71, "column": 35 }, "end": { - "line": 82, + "line": 71, "column": 41 } } }, "loc": { "start": { - "line": 82, + "line": 71, "column": 35 }, "end": { - "line": 82, + "line": 71, "column": 42 } } }, "loc": { "start": { - "line": 82, + "line": 71, "column": 35 }, "end": { - "line": 82, + "line": 71, "column": 42 } } }, "loc": { "start": { - "line": 82, + "line": 71, "column": 25 }, "end": { - "line": 82, + "line": 71, "column": 31 } } }, "loc": { "start": { - "line": 82, + "line": 71, "column": 9 }, "end": { - "line": 82, + "line": 71, "column": 31 } } @@ -4719,11 +3687,11 @@ "kind": "let", "loc": { "start": { - "line": 82, + "line": 71, "column": 5 }, "end": { - "line": 82, + "line": 71, "column": 42 } } @@ -4731,11 +3699,11 @@ ], "loc": { "start": { - "line": 78, + "line": 67, "column": 3 }, "end": { - "line": 83, + "line": 72, "column": 4 } } @@ -4743,33 +3711,33 @@ ], "loc": { "start": { - "line": 57, + "line": 46, "column": 29 }, "end": { - "line": 84, + "line": 73, "column": 2 } } }, "loc": { "start": { - "line": 57, + "line": 46, "column": 20 }, "end": { - "line": 84, + "line": 73, "column": 2 } } }, "loc": { "start": { - "line": 57, + "line": 46, "column": 20 }, "end": { - "line": 84, + "line": 73, "column": 2 } } @@ -4778,11 +3746,11 @@ "decorators": [], "loc": { "start": { - "line": 57, + "line": 46, "column": 1 }, "end": { - "line": 84, + "line": 73, "column": 2 } } @@ -4795,11 +3763,11 @@ "decorators": [], "loc": { "start": { - "line": 86, + "line": 75, "column": 10 }, "end": { - "line": 86, + "line": 75, "column": 19 } } @@ -4819,11 +3787,11 @@ "decorators": [], "loc": { "start": { - "line": 86, + "line": 75, "column": 10 }, "end": { - "line": 86, + "line": 75, "column": 19 } } @@ -4842,33 +3810,33 @@ "decorators": [], "loc": { "start": { - "line": 86, + "line": 75, "column": 23 }, "end": { - "line": 86, + "line": 75, "column": 27 } } }, "loc": { "start": { - "line": 86, + "line": 75, "column": 23 }, "end": { - "line": 86, + "line": 75, "column": 29 } } }, "loc": { "start": { - "line": 86, + "line": 75, "column": 23 }, "end": { - "line": 86, + "line": 75, "column": 29 } } @@ -4888,11 +3856,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 87, + "line": 76, "column": 14 }, "end": { - "line": 87, + "line": 76, "column": 18 } } @@ -4900,11 +3868,11 @@ "decorators": [], "loc": { "start": { - "line": 87, + "line": 76, "column": 7 }, "end": { - "line": 87, + "line": 76, "column": 12 } } @@ -4914,22 +3882,22 @@ "value": 42, "loc": { "start": { - "line": 87, + "line": 76, "column": 21 }, "end": { - "line": 87, + "line": 76, "column": 23 } } }, "loc": { "start": { - "line": 87, + "line": 76, "column": 7 }, "end": { - "line": 87, + "line": 76, "column": 23 } } @@ -4938,11 +3906,11 @@ "kind": "let", "loc": { "start": { - "line": 87, + "line": 76, "column": 3 }, "end": { - "line": 87, + "line": 76, "column": 24 } } @@ -4965,33 +3933,33 @@ "decorators": [], "loc": { "start": { - "line": 88, + "line": 77, "column": 14 }, "end": { - "line": 88, + "line": 77, "column": 18 } } }, "loc": { "start": { - "line": 88, + "line": 77, "column": 14 }, "end": { - "line": 88, + "line": 77, "column": 20 } } }, "loc": { "start": { - "line": 88, + "line": 77, "column": 14 }, "end": { - "line": 88, + "line": 77, "column": 20 } } @@ -4999,11 +3967,11 @@ "decorators": [], "loc": { "start": { - "line": 88, + "line": 77, "column": 7 }, "end": { - "line": 88, + "line": 77, "column": 12 } } @@ -5020,33 +3988,33 @@ "decorators": [], "loc": { "start": { - "line": 88, + "line": 77, "column": 25 }, "end": { - "line": 88, + "line": 77, "column": 29 } } }, "loc": { "start": { - "line": 88, + "line": 77, "column": 25 }, "end": { - "line": 88, + "line": 77, "column": 30 } } }, "loc": { "start": { - "line": 88, + "line": 77, "column": 25 }, "end": { - "line": 88, + "line": 77, "column": 30 } } @@ -5059,11 +4027,11 @@ "value": 42, "loc": { "start": { - "line": 88, + "line": 77, "column": 30 }, "end": { - "line": 88, + "line": 77, "column": 32 } } @@ -5072,22 +4040,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 88, + "line": 77, "column": 36 }, "end": { - "line": 88, + "line": 77, "column": 40 } } }, "loc": { "start": { - "line": 88, + "line": 77, "column": 30 }, "end": { - "line": 88, + "line": 77, "column": 32 } } @@ -5095,22 +4063,22 @@ ], "loc": { "start": { - "line": 88, + "line": 77, "column": 21 }, "end": { - "line": 88, + "line": 77, "column": 42 } } }, "loc": { "start": { - "line": 88, + "line": 77, "column": 7 }, "end": { - "line": 88, + "line": 77, "column": 42 } } @@ -5119,11 +4087,11 @@ "kind": "let", "loc": { "start": { - "line": 88, + "line": 77, "column": 3 }, "end": { - "line": 88, + "line": 77, "column": 42 } } @@ -5142,11 +4110,11 @@ "decorators": [], "loc": { "start": { - "line": 92, + "line": 81, "column": 9 }, "end": { - "line": 92, + "line": 81, "column": 18 } } @@ -5159,11 +4127,11 @@ "decorators": [], "loc": { "start": { - "line": 92, + "line": 81, "column": 23 }, "end": { - "line": 92, + "line": 81, "column": 28 } } @@ -5172,33 +4140,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 92, + "line": 81, "column": 32 }, "end": { - "line": 92, + "line": 81, "column": 36 } } }, "loc": { "start": { - "line": 92, + "line": 81, "column": 23 }, "end": { - "line": 92, + "line": 81, "column": 28 } } }, "loc": { "start": { - "line": 92, + "line": 81, "column": 9 }, "end": { - "line": 92, + "line": 81, "column": 28 } } @@ -5207,11 +4175,11 @@ "kind": "let", "loc": { "start": { - "line": 92, + "line": 81, "column": 5 }, "end": { - "line": 92, + "line": 81, "column": 37 } } @@ -5227,11 +4195,11 @@ "decorators": [], "loc": { "start": { - "line": 93, + "line": 82, "column": 9 }, "end": { - "line": 93, + "line": 82, "column": 19 } } @@ -5244,11 +4212,11 @@ "decorators": [], "loc": { "start": { - "line": 93, + "line": 82, "column": 23 }, "end": { - "line": 93, + "line": 82, "column": 28 } } @@ -5257,33 +4225,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 93, + "line": 82, "column": 32 }, "end": { - "line": 93, + "line": 82, "column": 37 } } }, "loc": { "start": { - "line": 93, + "line": 82, "column": 23 }, "end": { - "line": 93, + "line": 82, "column": 28 } } }, "loc": { "start": { - "line": 93, + "line": 82, "column": 9 }, "end": { - "line": 93, + "line": 82, "column": 28 } } @@ -5292,11 +4260,11 @@ "kind": "let", "loc": { "start": { - "line": 93, + "line": 82, "column": 5 }, "end": { - "line": 93, + "line": 82, "column": 38 } } @@ -5312,11 +4280,11 @@ "decorators": [], "loc": { "start": { - "line": 94, + "line": 83, "column": 9 }, "end": { - "line": 94, + "line": 83, "column": 18 } } @@ -5329,11 +4297,11 @@ "decorators": [], "loc": { "start": { - "line": 94, + "line": 83, "column": 23 }, "end": { - "line": 94, + "line": 83, "column": 28 } } @@ -5342,33 +4310,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 94, + "line": 83, "column": 32 }, "end": { - "line": 94, + "line": 83, "column": 36 } } }, "loc": { "start": { - "line": 94, + "line": 83, "column": 23 }, "end": { - "line": 94, + "line": 83, "column": 28 } } }, "loc": { "start": { - "line": 94, + "line": 83, "column": 9 }, "end": { - "line": 94, + "line": 83, "column": 28 } } @@ -5377,11 +4345,11 @@ "kind": "let", "loc": { "start": { - "line": 94, + "line": 83, "column": 5 }, "end": { - "line": 94, + "line": 83, "column": 37 } } @@ -5397,11 +4365,11 @@ "decorators": [], "loc": { "start": { - "line": 95, + "line": 84, "column": 9 }, "end": { - "line": 95, + "line": 84, "column": 17 } } @@ -5414,11 +4382,11 @@ "decorators": [], "loc": { "start": { - "line": 95, + "line": 84, "column": 23 }, "end": { - "line": 95, + "line": 84, "column": 28 } } @@ -5427,33 +4395,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 95, + "line": 84, "column": 32 }, "end": { - "line": 95, + "line": 84, "column": 35 } } }, "loc": { "start": { - "line": 95, + "line": 84, "column": 23 }, "end": { - "line": 95, + "line": 84, "column": 28 } } }, "loc": { "start": { - "line": 95, + "line": 84, "column": 9 }, "end": { - "line": 95, + "line": 84, "column": 28 } } @@ -5462,11 +4430,11 @@ "kind": "let", "loc": { "start": { - "line": 95, + "line": 84, "column": 5 }, "end": { - "line": 95, + "line": 84, "column": 36 } } @@ -5482,11 +4450,11 @@ "decorators": [], "loc": { "start": { - "line": 96, + "line": 85, "column": 9 }, "end": { - "line": 96, + "line": 85, "column": 18 } } @@ -5499,11 +4467,11 @@ "decorators": [], "loc": { "start": { - "line": 96, + "line": 85, "column": 23 }, "end": { - "line": 96, + "line": 85, "column": 28 } } @@ -5512,33 +4480,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 96, + "line": 85, "column": 32 }, "end": { - "line": 96, + "line": 85, "column": 36 } } }, "loc": { "start": { - "line": 96, + "line": 85, "column": 23 }, "end": { - "line": 96, + "line": 85, "column": 28 } } }, "loc": { "start": { - "line": 96, + "line": 85, "column": 9 }, "end": { - "line": 96, + "line": 85, "column": 28 } } @@ -5547,11 +4515,11 @@ "kind": "let", "loc": { "start": { - "line": 96, + "line": 85, "column": 5 }, "end": { - "line": 96, + "line": 85, "column": 37 } } @@ -5567,11 +4535,11 @@ "decorators": [], "loc": { "start": { - "line": 97, + "line": 86, "column": 9 }, "end": { - "line": 97, + "line": 86, "column": 19 } } @@ -5584,11 +4552,11 @@ "decorators": [], "loc": { "start": { - "line": 97, + "line": 86, "column": 23 }, "end": { - "line": 97, + "line": 86, "column": 28 } } @@ -5597,33 +4565,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 97, + "line": 86, "column": 32 }, "end": { - "line": 97, + "line": 86, "column": 37 } } }, "loc": { "start": { - "line": 97, + "line": 86, "column": 23 }, "end": { - "line": 97, + "line": 86, "column": 28 } } }, "loc": { "start": { - "line": 97, + "line": 86, "column": 9 }, "end": { - "line": 97, + "line": 86, "column": 28 } } @@ -5632,11 +4600,11 @@ "kind": "let", "loc": { "start": { - "line": 97, + "line": 86, "column": 5 }, "end": { - "line": 97, + "line": 86, "column": 38 } } @@ -5652,11 +4620,11 @@ "decorators": [], "loc": { "start": { - "line": 98, + "line": 87, "column": 9 }, "end": { - "line": 98, + "line": 87, "column": 20 } } @@ -5669,11 +4637,11 @@ "decorators": [], "loc": { "start": { - "line": 98, + "line": 87, "column": 23 }, "end": { - "line": 98, + "line": 87, "column": 28 } } @@ -5682,33 +4650,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 98, + "line": 87, "column": 32 }, "end": { - "line": 98, + "line": 87, "column": 38 } } }, "loc": { "start": { - "line": 98, + "line": 87, "column": 23 }, "end": { - "line": 98, + "line": 87, "column": 28 } } }, "loc": { "start": { - "line": 98, + "line": 87, "column": 9 }, "end": { - "line": 98, + "line": 87, "column": 28 } } @@ -5717,11 +4685,11 @@ "kind": "let", "loc": { "start": { - "line": 98, + "line": 87, "column": 5 }, "end": { - "line": 98, + "line": 87, "column": 39 } } @@ -5737,11 +4705,11 @@ "decorators": [], "loc": { "start": { - "line": 100, + "line": 89, "column": 9 }, "end": { - "line": 100, + "line": 89, "column": 18 } } @@ -5754,11 +4722,11 @@ "decorators": [], "loc": { "start": { - "line": 100, + "line": 89, "column": 23 }, "end": { - "line": 100, + "line": 89, "column": 28 } } @@ -5767,33 +4735,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 100, + "line": 89, "column": 32 }, "end": { - "line": 100, + "line": 89, "column": 36 } } }, "loc": { "start": { - "line": 100, + "line": 89, "column": 23 }, "end": { - "line": 100, + "line": 89, "column": 28 } } }, "loc": { "start": { - "line": 100, + "line": 89, "column": 9 }, "end": { - "line": 100, + "line": 89, "column": 28 } } @@ -5802,11 +4770,11 @@ "kind": "let", "loc": { "start": { - "line": 100, + "line": 89, "column": 5 }, "end": { - "line": 100, + "line": 89, "column": 37 } } @@ -5822,11 +4790,11 @@ "decorators": [], "loc": { "start": { - "line": 101, + "line": 90, "column": 9 }, "end": { - "line": 101, + "line": 90, "column": 17 } } @@ -5839,11 +4807,11 @@ "decorators": [], "loc": { "start": { - "line": 101, + "line": 90, "column": 23 }, "end": { - "line": 101, + "line": 90, "column": 28 } } @@ -5852,33 +4820,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 101, + "line": 90, "column": 32 }, "end": { - "line": 101, + "line": 90, "column": 35 } } }, "loc": { "start": { - "line": 101, + "line": 90, "column": 23 }, "end": { - "line": 101, + "line": 90, "column": 28 } } }, "loc": { "start": { - "line": 101, + "line": 90, "column": 9 }, "end": { - "line": 101, + "line": 90, "column": 28 } } @@ -5887,11 +4855,11 @@ "kind": "let", "loc": { "start": { - "line": 101, + "line": 90, "column": 5 }, "end": { - "line": 101, + "line": 90, "column": 36 } } @@ -5907,11 +4875,11 @@ "decorators": [], "loc": { "start": { - "line": 102, + "line": 91, "column": 9 }, "end": { - "line": 102, + "line": 91, "column": 18 } } @@ -5924,11 +4892,11 @@ "decorators": [], "loc": { "start": { - "line": 102, + "line": 91, "column": 23 }, "end": { - "line": 102, + "line": 91, "column": 28 } } @@ -5937,33 +4905,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 102, + "line": 91, "column": 32 }, "end": { - "line": 102, + "line": 91, "column": 36 } } }, "loc": { "start": { - "line": 102, + "line": 91, "column": 23 }, "end": { - "line": 102, + "line": 91, "column": 28 } } }, "loc": { "start": { - "line": 102, + "line": 91, "column": 9 }, "end": { - "line": 102, + "line": 91, "column": 28 } } @@ -5972,11 +4940,11 @@ "kind": "let", "loc": { "start": { - "line": 102, + "line": 91, "column": 5 }, "end": { - "line": 102, + "line": 91, "column": 37 } } @@ -5992,11 +4960,11 @@ "decorators": [], "loc": { "start": { - "line": 103, + "line": 92, "column": 9 }, "end": { - "line": 103, + "line": 92, "column": 19 } } @@ -6009,11 +4977,11 @@ "decorators": [], "loc": { "start": { - "line": 103, + "line": 92, "column": 23 }, "end": { - "line": 103, + "line": 92, "column": 28 } } @@ -6022,33 +4990,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 103, + "line": 92, "column": 32 }, "end": { - "line": 103, + "line": 92, "column": 37 } } }, "loc": { "start": { - "line": 103, + "line": 92, "column": 23 }, "end": { - "line": 103, + "line": 92, "column": 28 } } }, "loc": { "start": { - "line": 103, + "line": 92, "column": 9 }, "end": { - "line": 103, + "line": 92, "column": 28 } } @@ -6057,11 +5025,11 @@ "kind": "let", "loc": { "start": { - "line": 103, + "line": 92, "column": 5 }, "end": { - "line": 103, + "line": 92, "column": 38 } } @@ -6077,11 +5045,11 @@ "decorators": [], "loc": { "start": { - "line": 104, + "line": 93, "column": 9 }, "end": { - "line": 104, + "line": 93, "column": 20 } } @@ -6094,11 +5062,11 @@ "decorators": [], "loc": { "start": { - "line": 104, + "line": 93, "column": 23 }, "end": { - "line": 104, + "line": 93, "column": 28 } } @@ -6107,33 +5075,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 104, + "line": 93, "column": 32 }, "end": { - "line": 104, + "line": 93, "column": 38 } } }, "loc": { "start": { - "line": 104, + "line": 93, "column": 23 }, "end": { - "line": 104, + "line": 93, "column": 28 } } }, "loc": { "start": { - "line": 104, + "line": 93, "column": 9 }, "end": { - "line": 104, + "line": 93, "column": 28 } } @@ -6142,11 +5110,11 @@ "kind": "let", "loc": { "start": { - "line": 104, + "line": 93, "column": 5 }, "end": { - "line": 104, + "line": 93, "column": 39 } } @@ -6154,11 +5122,11 @@ ], "loc": { "start": { - "line": 90, + "line": 79, "column": 3 }, "end": { - "line": 105, + "line": 94, "column": 4 } } @@ -6177,11 +5145,11 @@ "decorators": [], "loc": { "start": { - "line": 109, + "line": 98, "column": 9 }, "end": { - "line": 109, + "line": 98, "column": 18 } } @@ -6194,11 +5162,11 @@ "decorators": [], "loc": { "start": { - "line": 109, + "line": 98, "column": 23 }, "end": { - "line": 109, + "line": 98, "column": 28 } } @@ -6213,55 +5181,55 @@ "decorators": [], "loc": { "start": { - "line": 109, + "line": 98, "column": 32 }, "end": { - "line": 109, + "line": 98, "column": 36 } } }, "loc": { "start": { - "line": 109, + "line": 98, "column": 32 }, "end": { - "line": 109, + "line": 98, "column": 37 } } }, "loc": { "start": { - "line": 109, + "line": 98, "column": 32 }, "end": { - "line": 109, + "line": 98, "column": 37 } } }, "loc": { "start": { - "line": 109, + "line": 98, "column": 23 }, "end": { - "line": 109, + "line": 98, "column": 28 } } }, "loc": { "start": { - "line": 109, + "line": 98, "column": 9 }, "end": { - "line": 109, + "line": 98, "column": 28 } } @@ -6270,11 +5238,11 @@ "kind": "let", "loc": { "start": { - "line": 109, + "line": 98, "column": 5 }, "end": { - "line": 109, + "line": 98, "column": 37 } } @@ -6290,11 +5258,11 @@ "decorators": [], "loc": { "start": { - "line": 110, + "line": 99, "column": 9 }, "end": { - "line": 110, + "line": 99, "column": 18 } } @@ -6307,11 +5275,11 @@ "decorators": [], "loc": { "start": { - "line": 110, + "line": 99, "column": 23 }, "end": { - "line": 110, + "line": 99, "column": 28 } } @@ -6326,55 +5294,55 @@ "decorators": [], "loc": { "start": { - "line": 110, + "line": 99, "column": 32 }, "end": { - "line": 110, + "line": 99, "column": 36 } } }, "loc": { "start": { - "line": 110, + "line": 99, "column": 32 }, "end": { - "line": 110, + "line": 99, "column": 37 } } }, "loc": { "start": { - "line": 110, + "line": 99, "column": 32 }, "end": { - "line": 110, + "line": 99, "column": 37 } } }, "loc": { "start": { - "line": 110, + "line": 99, "column": 23 }, "end": { - "line": 110, + "line": 99, "column": 28 } } }, "loc": { "start": { - "line": 110, + "line": 99, "column": 9 }, "end": { - "line": 110, + "line": 99, "column": 28 } } @@ -6383,11 +5351,11 @@ "kind": "let", "loc": { "start": { - "line": 110, + "line": 99, "column": 5 }, "end": { - "line": 110, + "line": 99, "column": 37 } } @@ -6403,11 +5371,11 @@ "decorators": [], "loc": { "start": { - "line": 111, + "line": 100, "column": 9 }, "end": { - "line": 111, + "line": 100, "column": 20 } } @@ -6420,11 +5388,11 @@ "decorators": [], "loc": { "start": { - "line": 111, + "line": 100, "column": 23 }, "end": { - "line": 111, + "line": 100, "column": 28 } } @@ -6439,55 +5407,55 @@ "decorators": [], "loc": { "start": { - "line": 111, + "line": 100, "column": 32 }, "end": { - "line": 111, + "line": 100, "column": 38 } } }, "loc": { "start": { - "line": 111, + "line": 100, "column": 32 }, "end": { - "line": 111, + "line": 100, "column": 39 } } }, "loc": { "start": { - "line": 111, + "line": 100, "column": 32 }, "end": { - "line": 111, + "line": 100, "column": 39 } } }, "loc": { "start": { - "line": 111, + "line": 100, "column": 23 }, "end": { - "line": 111, + "line": 100, "column": 28 } } }, "loc": { "start": { - "line": 111, + "line": 100, "column": 9 }, "end": { - "line": 111, + "line": 100, "column": 28 } } @@ -6496,11 +5464,11 @@ "kind": "let", "loc": { "start": { - "line": 111, + "line": 100, "column": 5 }, "end": { - "line": 111, + "line": 100, "column": 39 } } @@ -6508,11 +5476,11 @@ ], "loc": { "start": { - "line": 107, + "line": 96, "column": 3 }, "end": { - "line": 112, + "line": 101, "column": 4 } } @@ -6520,33 +5488,33 @@ ], "loc": { "start": { - "line": 86, + "line": 75, "column": 28 }, "end": { - "line": 113, + "line": 102, "column": 2 } } }, "loc": { "start": { - "line": 86, + "line": 75, "column": 19 }, "end": { - "line": 113, + "line": 102, "column": 2 } } }, "loc": { "start": { - "line": 86, + "line": 75, "column": 19 }, "end": { - "line": 113, + "line": 102, "column": 2 } } @@ -6555,11 +5523,11 @@ "decorators": [], "loc": { "start": { - "line": 86, + "line": 75, "column": 1 }, "end": { - "line": 113, + "line": 102, "column": 2 } } @@ -6572,11 +5540,11 @@ "decorators": [], "loc": { "start": { - "line": 115, + "line": 104, "column": 10 }, "end": { - "line": 115, + "line": 104, "column": 18 } } @@ -6596,11 +5564,11 @@ "decorators": [], "loc": { "start": { - "line": 115, + "line": 104, "column": 10 }, "end": { - "line": 115, + "line": 104, "column": 18 } } @@ -6619,33 +5587,33 @@ "decorators": [], "loc": { "start": { - "line": 115, + "line": 104, "column": 22 }, "end": { - "line": 115, + "line": 104, "column": 26 } } }, "loc": { "start": { - "line": 115, + "line": 104, "column": 22 }, "end": { - "line": 115, + "line": 104, "column": 28 } } }, "loc": { "start": { - "line": 115, + "line": 104, "column": 22 }, "end": { - "line": 115, + "line": 104, "column": 28 } } @@ -6665,11 +5633,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 116, + "line": 105, "column": 13 }, "end": { - "line": 116, + "line": 105, "column": 16 } } @@ -6677,11 +5645,11 @@ "decorators": [], "loc": { "start": { - "line": 116, + "line": 105, "column": 7 }, "end": { - "line": 116, + "line": 105, "column": 11 } } @@ -6691,22 +5659,22 @@ "value": 42, "loc": { "start": { - "line": 116, + "line": 105, "column": 19 }, "end": { - "line": 116, + "line": 105, "column": 21 } } }, "loc": { "start": { - "line": 116, + "line": 105, "column": 7 }, "end": { - "line": 116, + "line": 105, "column": 21 } } @@ -6715,11 +5683,11 @@ "kind": "let", "loc": { "start": { - "line": 116, + "line": 105, "column": 3 }, "end": { - "line": 116, + "line": 105, "column": 22 } } @@ -6742,33 +5710,33 @@ "decorators": [], "loc": { "start": { - "line": 117, + "line": 106, "column": 13 }, "end": { - "line": 117, + "line": 106, "column": 16 } } }, "loc": { "start": { - "line": 117, + "line": 106, "column": 13 }, "end": { - "line": 117, + "line": 106, "column": 18 } } }, "loc": { "start": { - "line": 117, + "line": 106, "column": 13 }, "end": { - "line": 117, + "line": 106, "column": 18 } } @@ -6776,11 +5744,11 @@ "decorators": [], "loc": { "start": { - "line": 117, + "line": 106, "column": 7 }, "end": { - "line": 117, + "line": 106, "column": 11 } } @@ -6797,33 +5765,33 @@ "decorators": [], "loc": { "start": { - "line": 117, + "line": 106, "column": 23 }, "end": { - "line": 117, + "line": 106, "column": 26 } } }, "loc": { "start": { - "line": 117, + "line": 106, "column": 23 }, "end": { - "line": 117, + "line": 106, "column": 27 } } }, "loc": { "start": { - "line": 117, + "line": 106, "column": 23 }, "end": { - "line": 117, + "line": 106, "column": 27 } } @@ -6836,11 +5804,11 @@ "value": 42, "loc": { "start": { - "line": 117, + "line": 106, "column": 27 }, "end": { - "line": 117, + "line": 106, "column": 29 } } @@ -6849,22 +5817,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 117, + "line": 106, "column": 33 }, "end": { - "line": 117, + "line": 106, "column": 36 } } }, "loc": { "start": { - "line": 117, + "line": 106, "column": 27 }, "end": { - "line": 117, + "line": 106, "column": 29 } } @@ -6872,22 +5840,22 @@ ], "loc": { "start": { - "line": 117, + "line": 106, "column": 19 }, "end": { - "line": 117, + "line": 106, "column": 38 } } }, "loc": { "start": { - "line": 117, + "line": 106, "column": 7 }, "end": { - "line": 117, + "line": 106, "column": 38 } } @@ -6896,11 +5864,11 @@ "kind": "let", "loc": { "start": { - "line": 117, + "line": 106, "column": 3 }, "end": { - "line": 117, + "line": 106, "column": 38 } } @@ -6919,11 +5887,11 @@ "decorators": [], "loc": { "start": { - "line": 121, + "line": 110, "column": 9 }, "end": { - "line": 121, + "line": 110, "column": 17 } } @@ -6936,11 +5904,11 @@ "decorators": [], "loc": { "start": { - "line": 121, + "line": 110, "column": 23 }, "end": { - "line": 121, + "line": 110, "column": 27 } } @@ -6949,33 +5917,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 121, + "line": 110, "column": 31 }, "end": { - "line": 121, + "line": 110, "column": 35 } } }, "loc": { "start": { - "line": 121, + "line": 110, "column": 23 }, "end": { - "line": 121, + "line": 110, "column": 27 } } }, "loc": { "start": { - "line": 121, + "line": 110, "column": 9 }, "end": { - "line": 121, + "line": 110, "column": 27 } } @@ -6984,11 +5952,11 @@ "kind": "let", "loc": { "start": { - "line": 121, + "line": 110, "column": 5 }, "end": { - "line": 121, + "line": 110, "column": 36 } } @@ -7004,11 +5972,11 @@ "decorators": [], "loc": { "start": { - "line": 122, + "line": 111, "column": 9 }, "end": { - "line": 122, + "line": 111, "column": 18 } } @@ -7021,11 +5989,11 @@ "decorators": [], "loc": { "start": { - "line": 122, + "line": 111, "column": 23 }, "end": { - "line": 122, + "line": 111, "column": 27 } } @@ -7034,33 +6002,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 122, + "line": 111, "column": 31 }, "end": { - "line": 122, + "line": 111, "column": 36 } } }, "loc": { "start": { - "line": 122, + "line": 111, "column": 23 }, "end": { - "line": 122, + "line": 111, "column": 27 } } }, "loc": { "start": { - "line": 122, + "line": 111, "column": 9 }, "end": { - "line": 122, + "line": 111, "column": 27 } } @@ -7069,11 +6037,11 @@ "kind": "let", "loc": { "start": { - "line": 122, + "line": 111, "column": 5 }, "end": { - "line": 122, + "line": 111, "column": 37 } } @@ -7089,11 +6057,11 @@ "decorators": [], "loc": { "start": { - "line": 123, + "line": 112, "column": 9 }, "end": { - "line": 123, + "line": 112, "column": 17 } } @@ -7106,11 +6074,11 @@ "decorators": [], "loc": { "start": { - "line": 123, + "line": 112, "column": 23 }, "end": { - "line": 123, + "line": 112, "column": 27 } } @@ -7119,33 +6087,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 123, + "line": 112, "column": 31 }, "end": { - "line": 123, + "line": 112, "column": 35 } } }, "loc": { "start": { - "line": 123, + "line": 112, "column": 23 }, "end": { - "line": 123, + "line": 112, "column": 27 } } }, "loc": { "start": { - "line": 123, + "line": 112, "column": 9 }, "end": { - "line": 123, + "line": 112, "column": 27 } } @@ -7154,11 +6122,11 @@ "kind": "let", "loc": { "start": { - "line": 123, + "line": 112, "column": 5 }, "end": { - "line": 123, + "line": 112, "column": 36 } } @@ -7174,11 +6142,11 @@ "decorators": [], "loc": { "start": { - "line": 124, + "line": 113, "column": 9 }, "end": { - "line": 124, + "line": 113, "column": 16 } } @@ -7191,11 +6159,11 @@ "decorators": [], "loc": { "start": { - "line": 124, + "line": 113, "column": 23 }, "end": { - "line": 124, + "line": 113, "column": 27 } } @@ -7204,33 +6172,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 124, + "line": 113, "column": 31 }, "end": { - "line": 124, + "line": 113, "column": 34 } } }, "loc": { "start": { - "line": 124, + "line": 113, "column": 23 }, "end": { - "line": 124, + "line": 113, "column": 27 } } }, "loc": { "start": { - "line": 124, + "line": 113, "column": 9 }, "end": { - "line": 124, + "line": 113, "column": 27 } } @@ -7239,11 +6207,11 @@ "kind": "let", "loc": { "start": { - "line": 124, + "line": 113, "column": 5 }, "end": { - "line": 124, + "line": 113, "column": 35 } } @@ -7259,11 +6227,11 @@ "decorators": [], "loc": { "start": { - "line": 125, + "line": 114, "column": 9 }, "end": { - "line": 125, + "line": 114, "column": 17 } } @@ -7276,11 +6244,11 @@ "decorators": [], "loc": { "start": { - "line": 125, + "line": 114, "column": 23 }, "end": { - "line": 125, + "line": 114, "column": 27 } } @@ -7289,33 +6257,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 125, + "line": 114, "column": 31 }, "end": { - "line": 125, + "line": 114, "column": 35 } } }, "loc": { "start": { - "line": 125, + "line": 114, "column": 23 }, "end": { - "line": 125, + "line": 114, "column": 27 } } }, "loc": { "start": { - "line": 125, + "line": 114, "column": 9 }, "end": { - "line": 125, + "line": 114, "column": 27 } } @@ -7324,11 +6292,11 @@ "kind": "let", "loc": { "start": { - "line": 125, + "line": 114, "column": 5 }, "end": { - "line": 125, + "line": 114, "column": 36 } } @@ -7344,11 +6312,11 @@ "decorators": [], "loc": { "start": { - "line": 126, + "line": 115, "column": 9 }, "end": { - "line": 126, + "line": 115, "column": 18 } } @@ -7361,11 +6329,11 @@ "decorators": [], "loc": { "start": { - "line": 126, + "line": 115, "column": 23 }, "end": { - "line": 126, + "line": 115, "column": 27 } } @@ -7374,33 +6342,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 126, + "line": 115, "column": 31 }, "end": { - "line": 126, + "line": 115, "column": 36 } } }, "loc": { "start": { - "line": 126, + "line": 115, "column": 23 }, "end": { - "line": 126, + "line": 115, "column": 27 } } }, "loc": { "start": { - "line": 126, + "line": 115, "column": 9 }, "end": { - "line": 126, + "line": 115, "column": 27 } } @@ -7409,11 +6377,11 @@ "kind": "let", "loc": { "start": { - "line": 126, + "line": 115, "column": 5 }, "end": { - "line": 126, + "line": 115, "column": 37 } } @@ -7429,11 +6397,11 @@ "decorators": [], "loc": { "start": { - "line": 127, + "line": 116, "column": 9 }, "end": { - "line": 127, + "line": 116, "column": 19 } } @@ -7446,11 +6414,11 @@ "decorators": [], "loc": { "start": { - "line": 127, + "line": 116, "column": 23 }, "end": { - "line": 127, + "line": 116, "column": 27 } } @@ -7459,33 +6427,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 127, + "line": 116, "column": 31 }, "end": { - "line": 127, + "line": 116, "column": 37 } } }, "loc": { "start": { - "line": 127, + "line": 116, "column": 23 }, "end": { - "line": 127, + "line": 116, "column": 27 } } }, "loc": { "start": { - "line": 127, + "line": 116, "column": 9 }, "end": { - "line": 127, + "line": 116, "column": 27 } } @@ -7494,11 +6462,11 @@ "kind": "let", "loc": { "start": { - "line": 127, + "line": 116, "column": 5 }, "end": { - "line": 127, + "line": 116, "column": 38 } } @@ -7514,11 +6482,11 @@ "decorators": [], "loc": { "start": { - "line": 129, + "line": 118, "column": 9 }, "end": { - "line": 129, + "line": 118, "column": 16 } } @@ -7531,11 +6499,11 @@ "decorators": [], "loc": { "start": { - "line": 129, + "line": 118, "column": 23 }, "end": { - "line": 129, + "line": 118, "column": 27 } } @@ -7544,33 +6512,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 129, + "line": 118, "column": 31 }, "end": { - "line": 129, + "line": 118, "column": 34 } } }, "loc": { "start": { - "line": 129, + "line": 118, "column": 23 }, "end": { - "line": 129, + "line": 118, "column": 27 } } }, "loc": { "start": { - "line": 129, + "line": 118, "column": 9 }, "end": { - "line": 129, + "line": 118, "column": 27 } } @@ -7579,11 +6547,11 @@ "kind": "let", "loc": { "start": { - "line": 129, + "line": 118, "column": 5 }, "end": { - "line": 129, + "line": 118, "column": 35 } } @@ -7599,11 +6567,11 @@ "decorators": [], "loc": { "start": { - "line": 130, + "line": 119, "column": 9 }, "end": { - "line": 130, + "line": 119, "column": 17 } } @@ -7616,11 +6584,11 @@ "decorators": [], "loc": { "start": { - "line": 130, + "line": 119, "column": 23 }, "end": { - "line": 130, + "line": 119, "column": 27 } } @@ -7629,33 +6597,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 130, + "line": 119, "column": 31 }, "end": { - "line": 130, + "line": 119, "column": 35 } } }, "loc": { "start": { - "line": 130, + "line": 119, "column": 23 }, "end": { - "line": 130, + "line": 119, "column": 27 } } }, "loc": { "start": { - "line": 130, + "line": 119, "column": 9 }, "end": { - "line": 130, + "line": 119, "column": 27 } } @@ -7664,11 +6632,11 @@ "kind": "let", "loc": { "start": { - "line": 130, + "line": 119, "column": 5 }, "end": { - "line": 130, + "line": 119, "column": 36 } } @@ -7684,11 +6652,11 @@ "decorators": [], "loc": { "start": { - "line": 131, + "line": 120, "column": 9 }, "end": { - "line": 131, + "line": 120, "column": 18 } } @@ -7701,11 +6669,11 @@ "decorators": [], "loc": { "start": { - "line": 131, + "line": 120, "column": 23 }, "end": { - "line": 131, + "line": 120, "column": 27 } } @@ -7714,33 +6682,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 131, + "line": 120, "column": 31 }, "end": { - "line": 131, + "line": 120, "column": 36 } } }, "loc": { "start": { - "line": 131, + "line": 120, "column": 23 }, "end": { - "line": 131, + "line": 120, "column": 27 } } }, "loc": { "start": { - "line": 131, + "line": 120, "column": 9 }, "end": { - "line": 131, + "line": 120, "column": 27 } } @@ -7749,11 +6717,11 @@ "kind": "let", "loc": { "start": { - "line": 131, + "line": 120, "column": 5 }, "end": { - "line": 131, + "line": 120, "column": 37 } } @@ -7769,11 +6737,11 @@ "decorators": [], "loc": { "start": { - "line": 132, + "line": 121, "column": 9 }, "end": { - "line": 132, + "line": 121, "column": 19 } } @@ -7786,11 +6754,11 @@ "decorators": [], "loc": { "start": { - "line": 132, + "line": 121, "column": 23 }, "end": { - "line": 132, + "line": 121, "column": 27 } } @@ -7799,33 +6767,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 132, + "line": 121, "column": 31 }, "end": { - "line": 132, + "line": 121, "column": 37 } } }, "loc": { "start": { - "line": 132, + "line": 121, "column": 23 }, "end": { - "line": 132, + "line": 121, "column": 27 } } }, "loc": { "start": { - "line": 132, + "line": 121, "column": 9 }, "end": { - "line": 132, + "line": 121, "column": 27 } } @@ -7834,11 +6802,11 @@ "kind": "let", "loc": { "start": { - "line": 132, + "line": 121, "column": 5 }, "end": { - "line": 132, + "line": 121, "column": 38 } } @@ -7846,11 +6814,11 @@ ], "loc": { "start": { - "line": 119, + "line": 108, "column": 3 }, "end": { - "line": 133, + "line": 122, "column": 4 } } @@ -7869,11 +6837,11 @@ "decorators": [], "loc": { "start": { - "line": 137, + "line": 126, "column": 9 }, "end": { - "line": 137, + "line": 126, "column": 16 } } @@ -7886,11 +6854,11 @@ "decorators": [], "loc": { "start": { - "line": 137, + "line": 126, "column": 23 }, "end": { - "line": 137, + "line": 126, "column": 27 } } @@ -7905,55 +6873,55 @@ "decorators": [], "loc": { "start": { - "line": 137, + "line": 126, "column": 31 }, "end": { - "line": 137, + "line": 126, "column": 34 } } }, "loc": { "start": { - "line": 137, + "line": 126, "column": 31 }, "end": { - "line": 137, + "line": 126, "column": 35 } } }, "loc": { "start": { - "line": 137, + "line": 126, "column": 31 }, "end": { - "line": 137, + "line": 126, "column": 35 } } }, "loc": { "start": { - "line": 137, + "line": 126, "column": 23 }, "end": { - "line": 137, + "line": 126, "column": 27 } } }, "loc": { "start": { - "line": 137, + "line": 126, "column": 9 }, "end": { - "line": 137, + "line": 126, "column": 27 } } @@ -7962,11 +6930,11 @@ "kind": "let", "loc": { "start": { - "line": 137, + "line": 126, "column": 5 }, "end": { - "line": 137, + "line": 126, "column": 35 } } @@ -7982,11 +6950,11 @@ "decorators": [], "loc": { "start": { - "line": 138, + "line": 127, "column": 9 }, "end": { - "line": 138, + "line": 127, "column": 16 } } @@ -7999,11 +6967,11 @@ "decorators": [], "loc": { "start": { - "line": 138, + "line": 127, "column": 23 }, "end": { - "line": 138, + "line": 127, "column": 27 } } @@ -8018,55 +6986,55 @@ "decorators": [], "loc": { "start": { - "line": 138, + "line": 127, "column": 31 }, "end": { - "line": 138, + "line": 127, "column": 34 } } }, "loc": { "start": { - "line": 138, + "line": 127, "column": 31 }, "end": { - "line": 138, + "line": 127, "column": 35 } } }, "loc": { "start": { - "line": 138, + "line": 127, "column": 31 }, "end": { - "line": 138, + "line": 127, "column": 35 } } }, "loc": { "start": { - "line": 138, + "line": 127, "column": 23 }, "end": { - "line": 138, + "line": 127, "column": 27 } } }, "loc": { "start": { - "line": 138, + "line": 127, "column": 9 }, "end": { - "line": 138, + "line": 127, "column": 27 } } @@ -8075,11 +7043,11 @@ "kind": "let", "loc": { "start": { - "line": 138, + "line": 127, "column": 5 }, "end": { - "line": 138, + "line": 127, "column": 35 } } @@ -8095,11 +7063,11 @@ "decorators": [], "loc": { "start": { - "line": 139, + "line": 128, "column": 9 }, "end": { - "line": 139, + "line": 128, "column": 19 } } @@ -8112,11 +7080,11 @@ "decorators": [], "loc": { "start": { - "line": 139, + "line": 128, "column": 23 }, "end": { - "line": 139, + "line": 128, "column": 27 } } @@ -8131,55 +7099,55 @@ "decorators": [], "loc": { "start": { - "line": 139, + "line": 128, "column": 31 }, "end": { - "line": 139, + "line": 128, "column": 37 } } }, "loc": { "start": { - "line": 139, + "line": 128, "column": 31 }, "end": { - "line": 139, + "line": 128, "column": 38 } } }, "loc": { "start": { - "line": 139, + "line": 128, "column": 31 }, "end": { - "line": 139, + "line": 128, "column": 38 } } }, "loc": { "start": { - "line": 139, + "line": 128, "column": 23 }, "end": { - "line": 139, + "line": 128, "column": 27 } } }, "loc": { "start": { - "line": 139, + "line": 128, "column": 9 }, "end": { - "line": 139, + "line": 128, "column": 27 } } @@ -8188,11 +7156,11 @@ "kind": "let", "loc": { "start": { - "line": 139, + "line": 128, "column": 5 }, "end": { - "line": 139, + "line": 128, "column": 38 } } @@ -8200,11 +7168,11 @@ ], "loc": { "start": { - "line": 135, + "line": 124, "column": 3 }, "end": { - "line": 140, + "line": 129, "column": 4 } } @@ -8212,33 +7180,33 @@ ], "loc": { "start": { - "line": 115, + "line": 104, "column": 27 }, "end": { - "line": 141, + "line": 130, "column": 2 } } }, "loc": { "start": { - "line": 115, + "line": 104, "column": 18 }, "end": { - "line": 141, + "line": 130, "column": 2 } } }, "loc": { "start": { - "line": 115, + "line": 104, "column": 18 }, "end": { - "line": 141, + "line": 130, "column": 2 } } @@ -8247,11 +7215,11 @@ "decorators": [], "loc": { "start": { - "line": 115, + "line": 104, "column": 1 }, "end": { - "line": 141, + "line": 130, "column": 2 } } @@ -8264,11 +7232,11 @@ "decorators": [], "loc": { "start": { - "line": 143, + "line": 132, "column": 10 }, "end": { - "line": 143, + "line": 132, "column": 19 } } @@ -8288,11 +7256,11 @@ "decorators": [], "loc": { "start": { - "line": 143, + "line": 132, "column": 10 }, "end": { - "line": 143, + "line": 132, "column": 19 } } @@ -8311,33 +7279,33 @@ "decorators": [], "loc": { "start": { - "line": 143, + "line": 132, "column": 23 }, "end": { - "line": 143, + "line": 132, "column": 27 } } }, "loc": { "start": { - "line": 143, + "line": 132, "column": 23 }, "end": { - "line": 143, + "line": 132, "column": 29 } } }, "loc": { "start": { - "line": 143, + "line": 132, "column": 23 }, "end": { - "line": 143, + "line": 132, "column": 29 } } @@ -8357,11 +7325,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 144, + "line": 133, "column": 14 }, "end": { - "line": 144, + "line": 133, "column": 18 } } @@ -8369,11 +7337,11 @@ "decorators": [], "loc": { "start": { - "line": 144, + "line": 133, "column": 7 }, "end": { - "line": 144, + "line": 133, "column": 12 } } @@ -8383,22 +7351,22 @@ "value": 42, "loc": { "start": { - "line": 144, + "line": 133, "column": 21 }, "end": { - "line": 144, + "line": 133, "column": 23 } } }, "loc": { "start": { - "line": 144, + "line": 133, "column": 7 }, "end": { - "line": 144, + "line": 133, "column": 23 } } @@ -8407,11 +7375,11 @@ "kind": "let", "loc": { "start": { - "line": 144, + "line": 133, "column": 3 }, "end": { - "line": 144, + "line": 133, "column": 24 } } @@ -8434,33 +7402,33 @@ "decorators": [], "loc": { "start": { - "line": 145, + "line": 134, "column": 14 }, "end": { - "line": 145, + "line": 134, "column": 18 } } }, "loc": { "start": { - "line": 145, + "line": 134, "column": 14 }, "end": { - "line": 145, + "line": 134, "column": 20 } } }, "loc": { "start": { - "line": 145, + "line": 134, "column": 14 }, "end": { - "line": 145, + "line": 134, "column": 20 } } @@ -8468,11 +7436,11 @@ "decorators": [], "loc": { "start": { - "line": 145, + "line": 134, "column": 7 }, "end": { - "line": 145, + "line": 134, "column": 12 } } @@ -8489,33 +7457,33 @@ "decorators": [], "loc": { "start": { - "line": 145, + "line": 134, "column": 25 }, "end": { - "line": 145, + "line": 134, "column": 29 } } }, "loc": { "start": { - "line": 145, + "line": 134, "column": 25 }, "end": { - "line": 145, + "line": 134, "column": 30 } } }, "loc": { "start": { - "line": 145, + "line": 134, "column": 25 }, "end": { - "line": 145, + "line": 134, "column": 30 } } @@ -8528,11 +7496,11 @@ "value": 42, "loc": { "start": { - "line": 145, + "line": 134, "column": 30 }, "end": { - "line": 145, + "line": 134, "column": 32 } } @@ -8541,22 +7509,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 145, + "line": 134, "column": 36 }, "end": { - "line": 145, + "line": 134, "column": 40 } } }, "loc": { "start": { - "line": 145, + "line": 134, "column": 30 }, "end": { - "line": 145, + "line": 134, "column": 32 } } @@ -8564,22 +7532,22 @@ ], "loc": { "start": { - "line": 145, + "line": 134, "column": 21 }, "end": { - "line": 145, + "line": 134, "column": 42 } } }, "loc": { "start": { - "line": 145, + "line": 134, "column": 7 }, "end": { - "line": 145, + "line": 134, "column": 42 } } @@ -8588,11 +7556,11 @@ "kind": "let", "loc": { "start": { - "line": 145, + "line": 134, "column": 3 }, "end": { - "line": 145, + "line": 134, "column": 42 } } @@ -8611,11 +7579,11 @@ "decorators": [], "loc": { "start": { - "line": 149, + "line": 138, "column": 9 }, "end": { - "line": 149, + "line": 138, "column": 18 } } @@ -8628,11 +7596,11 @@ "decorators": [], "loc": { "start": { - "line": 149, + "line": 138, "column": 23 }, "end": { - "line": 149, + "line": 138, "column": 28 } } @@ -8641,33 +7609,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 149, + "line": 138, "column": 32 }, "end": { - "line": 149, + "line": 138, "column": 36 } } }, "loc": { "start": { - "line": 149, + "line": 138, "column": 23 }, "end": { - "line": 149, + "line": 138, "column": 28 } } }, "loc": { "start": { - "line": 149, + "line": 138, "column": 9 }, "end": { - "line": 149, + "line": 138, "column": 28 } } @@ -8676,11 +7644,11 @@ "kind": "let", "loc": { "start": { - "line": 149, + "line": 138, "column": 5 }, "end": { - "line": 149, + "line": 138, "column": 37 } } @@ -8696,11 +7664,11 @@ "decorators": [], "loc": { "start": { - "line": 150, + "line": 139, "column": 9 }, "end": { - "line": 150, + "line": 139, "column": 19 } } @@ -8713,11 +7681,11 @@ "decorators": [], "loc": { "start": { - "line": 150, + "line": 139, "column": 23 }, "end": { - "line": 150, + "line": 139, "column": 28 } } @@ -8726,33 +7694,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 150, + "line": 139, "column": 32 }, "end": { - "line": 150, + "line": 139, "column": 37 } } }, "loc": { "start": { - "line": 150, + "line": 139, "column": 23 }, "end": { - "line": 150, + "line": 139, "column": 28 } } }, "loc": { "start": { - "line": 150, + "line": 139, "column": 9 }, "end": { - "line": 150, + "line": 139, "column": 28 } } @@ -8761,11 +7729,11 @@ "kind": "let", "loc": { "start": { - "line": 150, + "line": 139, "column": 5 }, "end": { - "line": 150, + "line": 139, "column": 38 } } @@ -8781,11 +7749,11 @@ "decorators": [], "loc": { "start": { - "line": 151, + "line": 140, "column": 9 }, "end": { - "line": 151, + "line": 140, "column": 18 } } @@ -8798,11 +7766,11 @@ "decorators": [], "loc": { "start": { - "line": 151, + "line": 140, "column": 23 }, "end": { - "line": 151, + "line": 140, "column": 28 } } @@ -8811,33 +7779,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 151, + "line": 140, "column": 32 }, "end": { - "line": 151, + "line": 140, "column": 36 } } }, "loc": { "start": { - "line": 151, + "line": 140, "column": 23 }, "end": { - "line": 151, + "line": 140, "column": 28 } } }, "loc": { "start": { - "line": 151, + "line": 140, "column": 9 }, "end": { - "line": 151, + "line": 140, "column": 28 } } @@ -8846,11 +7814,11 @@ "kind": "let", "loc": { "start": { - "line": 151, + "line": 140, "column": 5 }, "end": { - "line": 151, + "line": 140, "column": 37 } } @@ -8866,11 +7834,11 @@ "decorators": [], "loc": { "start": { - "line": 152, + "line": 141, "column": 9 }, "end": { - "line": 152, + "line": 141, "column": 17 } } @@ -8883,11 +7851,11 @@ "decorators": [], "loc": { "start": { - "line": 152, + "line": 141, "column": 23 }, "end": { - "line": 152, + "line": 141, "column": 28 } } @@ -8896,33 +7864,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 152, + "line": 141, "column": 32 }, "end": { - "line": 152, + "line": 141, "column": 35 } } }, "loc": { "start": { - "line": 152, + "line": 141, "column": 23 }, "end": { - "line": 152, + "line": 141, "column": 28 } } }, "loc": { "start": { - "line": 152, + "line": 141, "column": 9 }, "end": { - "line": 152, + "line": 141, "column": 28 } } @@ -8931,11 +7899,11 @@ "kind": "let", "loc": { "start": { - "line": 152, + "line": 141, "column": 5 }, "end": { - "line": 152, + "line": 141, "column": 36 } } @@ -8951,11 +7919,11 @@ "decorators": [], "loc": { "start": { - "line": 153, + "line": 142, "column": 9 }, "end": { - "line": 153, + "line": 142, "column": 18 } } @@ -8968,11 +7936,11 @@ "decorators": [], "loc": { "start": { - "line": 153, + "line": 142, "column": 23 }, "end": { - "line": 153, + "line": 142, "column": 28 } } @@ -8981,33 +7949,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 153, + "line": 142, "column": 32 }, "end": { - "line": 153, + "line": 142, "column": 36 } } }, "loc": { "start": { - "line": 153, + "line": 142, "column": 23 }, "end": { - "line": 153, + "line": 142, "column": 28 } } }, "loc": { "start": { - "line": 153, + "line": 142, "column": 9 }, "end": { - "line": 153, + "line": 142, "column": 28 } } @@ -9016,11 +7984,11 @@ "kind": "let", "loc": { "start": { - "line": 153, + "line": 142, "column": 5 }, "end": { - "line": 153, + "line": 142, "column": 37 } } @@ -9036,11 +8004,11 @@ "decorators": [], "loc": { "start": { - "line": 154, + "line": 143, "column": 9 }, "end": { - "line": 154, + "line": 143, "column": 19 } } @@ -9053,11 +8021,11 @@ "decorators": [], "loc": { "start": { - "line": 154, + "line": 143, "column": 23 }, "end": { - "line": 154, + "line": 143, "column": 28 } } @@ -9066,33 +8034,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 154, + "line": 143, "column": 32 }, "end": { - "line": 154, + "line": 143, "column": 37 } } }, "loc": { "start": { - "line": 154, + "line": 143, "column": 23 }, "end": { - "line": 154, + "line": 143, "column": 28 } } }, "loc": { "start": { - "line": 154, + "line": 143, "column": 9 }, "end": { - "line": 154, + "line": 143, "column": 28 } } @@ -9101,11 +8069,11 @@ "kind": "let", "loc": { "start": { - "line": 154, + "line": 143, "column": 5 }, "end": { - "line": 154, + "line": 143, "column": 38 } } @@ -9121,11 +8089,11 @@ "decorators": [], "loc": { "start": { - "line": 155, + "line": 144, "column": 9 }, "end": { - "line": 155, + "line": 144, "column": 20 } } @@ -9138,11 +8106,11 @@ "decorators": [], "loc": { "start": { - "line": 155, + "line": 144, "column": 23 }, "end": { - "line": 155, + "line": 144, "column": 28 } } @@ -9151,33 +8119,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 155, + "line": 144, "column": 32 }, "end": { - "line": 155, + "line": 144, "column": 38 } } }, "loc": { "start": { - "line": 155, + "line": 144, "column": 23 }, "end": { - "line": 155, + "line": 144, "column": 28 } } }, "loc": { "start": { - "line": 155, + "line": 144, "column": 9 }, "end": { - "line": 155, + "line": 144, "column": 28 } } @@ -9186,11 +8154,11 @@ "kind": "let", "loc": { "start": { - "line": 155, + "line": 144, "column": 5 }, "end": { - "line": 155, + "line": 144, "column": 39 } } @@ -9206,11 +8174,11 @@ "decorators": [], "loc": { "start": { - "line": 157, + "line": 146, "column": 9 }, "end": { - "line": 157, + "line": 146, "column": 18 } } @@ -9223,11 +8191,11 @@ "decorators": [], "loc": { "start": { - "line": 157, + "line": 146, "column": 23 }, "end": { - "line": 157, + "line": 146, "column": 28 } } @@ -9236,33 +8204,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 157, + "line": 146, "column": 32 }, "end": { - "line": 157, + "line": 146, "column": 36 } } }, "loc": { "start": { - "line": 157, + "line": 146, "column": 23 }, "end": { - "line": 157, + "line": 146, "column": 28 } } }, "loc": { "start": { - "line": 157, + "line": 146, "column": 9 }, "end": { - "line": 157, + "line": 146, "column": 28 } } @@ -9271,11 +8239,11 @@ "kind": "let", "loc": { "start": { - "line": 157, + "line": 146, "column": 5 }, "end": { - "line": 157, + "line": 146, "column": 37 } } @@ -9291,11 +8259,11 @@ "decorators": [], "loc": { "start": { - "line": 158, + "line": 147, "column": 9 }, "end": { - "line": 158, + "line": 147, "column": 19 } } @@ -9308,11 +8276,11 @@ "decorators": [], "loc": { "start": { - "line": 158, + "line": 147, "column": 23 }, "end": { - "line": 158, + "line": 147, "column": 28 } } @@ -9321,33 +8289,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 158, + "line": 147, "column": 32 }, "end": { - "line": 158, + "line": 147, "column": 37 } } }, "loc": { "start": { - "line": 158, + "line": 147, "column": 23 }, "end": { - "line": 158, + "line": 147, "column": 28 } } }, "loc": { "start": { - "line": 158, + "line": 147, "column": 9 }, "end": { - "line": 158, + "line": 147, "column": 28 } } @@ -9356,11 +8324,11 @@ "kind": "let", "loc": { "start": { - "line": 158, + "line": 147, "column": 5 }, "end": { - "line": 158, + "line": 147, "column": 38 } } @@ -9376,11 +8344,11 @@ "decorators": [], "loc": { "start": { - "line": 159, + "line": 148, "column": 9 }, "end": { - "line": 159, + "line": 148, "column": 20 } } @@ -9393,11 +8361,11 @@ "decorators": [], "loc": { "start": { - "line": 159, + "line": 148, "column": 23 }, "end": { - "line": 159, + "line": 148, "column": 28 } } @@ -9406,33 +8374,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 159, + "line": 148, "column": 32 }, "end": { - "line": 159, + "line": 148, "column": 38 } } }, "loc": { "start": { - "line": 159, + "line": 148, "column": 23 }, "end": { - "line": 159, + "line": 148, "column": 28 } } }, "loc": { "start": { - "line": 159, + "line": 148, "column": 9 }, "end": { - "line": 159, + "line": 148, "column": 28 } } @@ -9441,11 +8409,11 @@ "kind": "let", "loc": { "start": { - "line": 159, + "line": 148, "column": 5 }, "end": { - "line": 159, + "line": 148, "column": 39 } } @@ -9453,11 +8421,11 @@ ], "loc": { "start": { - "line": 147, + "line": 136, "column": 3 }, "end": { - "line": 160, + "line": 149, "column": 4 } } @@ -9476,11 +8444,11 @@ "decorators": [], "loc": { "start": { - "line": 164, + "line": 153, "column": 9 }, "end": { - "line": 164, + "line": 153, "column": 18 } } @@ -9493,11 +8461,11 @@ "decorators": [], "loc": { "start": { - "line": 164, + "line": 153, "column": 23 }, "end": { - "line": 164, + "line": 153, "column": 28 } } @@ -9512,55 +8480,55 @@ "decorators": [], "loc": { "start": { - "line": 164, + "line": 153, "column": 32 }, "end": { - "line": 164, + "line": 153, "column": 36 } } }, "loc": { "start": { - "line": 164, + "line": 153, "column": 32 }, "end": { - "line": 164, + "line": 153, "column": 37 } } }, "loc": { "start": { - "line": 164, + "line": 153, "column": 32 }, "end": { - "line": 164, + "line": 153, "column": 37 } } }, "loc": { "start": { - "line": 164, + "line": 153, "column": 23 }, "end": { - "line": 164, + "line": 153, "column": 28 } } }, "loc": { "start": { - "line": 164, + "line": 153, "column": 9 }, "end": { - "line": 164, + "line": 153, "column": 28 } } @@ -9569,11 +8537,11 @@ "kind": "let", "loc": { "start": { - "line": 164, + "line": 153, "column": 5 }, "end": { - "line": 164, + "line": 153, "column": 37 } } @@ -9589,11 +8557,11 @@ "decorators": [], "loc": { "start": { - "line": 165, + "line": 154, "column": 9 }, "end": { - "line": 165, + "line": 154, "column": 18 } } @@ -9606,11 +8574,11 @@ "decorators": [], "loc": { "start": { - "line": 165, + "line": 154, "column": 23 }, "end": { - "line": 165, + "line": 154, "column": 28 } } @@ -9625,55 +8593,55 @@ "decorators": [], "loc": { "start": { - "line": 165, + "line": 154, "column": 32 }, "end": { - "line": 165, + "line": 154, "column": 36 } } }, "loc": { "start": { - "line": 165, + "line": 154, "column": 32 }, "end": { - "line": 165, + "line": 154, "column": 37 } } }, "loc": { "start": { - "line": 165, + "line": 154, "column": 32 }, "end": { - "line": 165, + "line": 154, "column": 37 } } }, "loc": { "start": { - "line": 165, + "line": 154, "column": 23 }, "end": { - "line": 165, + "line": 154, "column": 28 } } }, "loc": { "start": { - "line": 165, + "line": 154, "column": 9 }, "end": { - "line": 165, + "line": 154, "column": 28 } } @@ -9682,11 +8650,11 @@ "kind": "let", "loc": { "start": { - "line": 165, + "line": 154, "column": 5 }, "end": { - "line": 165, + "line": 154, "column": 37 } } @@ -9702,11 +8670,11 @@ "decorators": [], "loc": { "start": { - "line": 166, + "line": 155, "column": 9 }, "end": { - "line": 166, + "line": 155, "column": 20 } } @@ -9719,11 +8687,11 @@ "decorators": [], "loc": { "start": { - "line": 166, + "line": 155, "column": 23 }, "end": { - "line": 166, + "line": 155, "column": 28 } } @@ -9738,55 +8706,55 @@ "decorators": [], "loc": { "start": { - "line": 166, + "line": 155, "column": 32 }, "end": { - "line": 166, + "line": 155, "column": 38 } } }, "loc": { "start": { - "line": 166, + "line": 155, "column": 32 }, "end": { - "line": 166, + "line": 155, "column": 39 } } }, "loc": { "start": { - "line": 166, + "line": 155, "column": 32 }, "end": { - "line": 166, + "line": 155, "column": 39 } } }, "loc": { "start": { - "line": 166, + "line": 155, "column": 23 }, "end": { - "line": 166, + "line": 155, "column": 28 } } }, "loc": { "start": { - "line": 166, + "line": 155, "column": 9 }, "end": { - "line": 166, + "line": 155, "column": 28 } } @@ -9795,11 +8763,11 @@ "kind": "let", "loc": { "start": { - "line": 166, + "line": 155, "column": 5 }, "end": { - "line": 166, + "line": 155, "column": 39 } } @@ -9807,11 +8775,11 @@ ], "loc": { "start": { - "line": 162, + "line": 151, "column": 3 }, "end": { - "line": 167, + "line": 156, "column": 4 } } @@ -9819,33 +8787,33 @@ ], "loc": { "start": { - "line": 143, + "line": 132, "column": 28 }, "end": { - "line": 168, + "line": 157, "column": 2 } } }, "loc": { "start": { - "line": 143, + "line": 132, "column": 19 }, "end": { - "line": 168, + "line": 157, "column": 2 } } }, "loc": { "start": { - "line": 143, + "line": 132, "column": 19 }, "end": { - "line": 168, + "line": 157, "column": 2 } } @@ -9854,11 +8822,11 @@ "decorators": [], "loc": { "start": { - "line": 143, + "line": 132, "column": 1 }, "end": { - "line": 168, + "line": 157, "column": 2 } } @@ -9871,11 +8839,11 @@ "decorators": [], "loc": { "start": { - "line": 170, + "line": 159, "column": 10 }, "end": { - "line": 170, + "line": 159, "column": 20 } } @@ -9895,11 +8863,11 @@ "decorators": [], "loc": { "start": { - "line": 170, + "line": 159, "column": 10 }, "end": { - "line": 170, + "line": 159, "column": 20 } } @@ -9918,33 +8886,33 @@ "decorators": [], "loc": { "start": { - "line": 170, + "line": 159, "column": 24 }, "end": { - "line": 170, + "line": 159, "column": 28 } } }, "loc": { "start": { - "line": 170, + "line": 159, "column": 24 }, "end": { - "line": 170, + "line": 159, "column": 30 } } }, "loc": { "start": { - "line": 170, + "line": 159, "column": 24 }, "end": { - "line": 170, + "line": 159, "column": 30 } } @@ -9964,11 +8932,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 171, + "line": 160, "column": 15 }, "end": { - "line": 171, + "line": 160, "column": 20 } } @@ -9976,11 +8944,11 @@ "decorators": [], "loc": { "start": { - "line": 171, + "line": 160, "column": 7 }, "end": { - "line": 171, + "line": 160, "column": 13 } } @@ -9990,22 +8958,22 @@ "value": 42, "loc": { "start": { - "line": 171, + "line": 160, "column": 23 }, "end": { - "line": 171, + "line": 160, "column": 25 } } }, "loc": { "start": { - "line": 171, + "line": 160, "column": 7 }, "end": { - "line": 171, + "line": 160, "column": 25 } } @@ -10014,11 +8982,11 @@ "kind": "let", "loc": { "start": { - "line": 171, + "line": 160, "column": 3 }, "end": { - "line": 171, + "line": 160, "column": 26 } } @@ -10041,33 +9009,33 @@ "decorators": [], "loc": { "start": { - "line": 172, + "line": 161, "column": 15 }, "end": { - "line": 172, + "line": 161, "column": 20 } } }, "loc": { "start": { - "line": 172, + "line": 161, "column": 15 }, "end": { - "line": 172, + "line": 161, "column": 22 } } }, "loc": { "start": { - "line": 172, + "line": 161, "column": 15 }, "end": { - "line": 172, + "line": 161, "column": 22 } } @@ -10075,11 +9043,11 @@ "decorators": [], "loc": { "start": { - "line": 172, + "line": 161, "column": 7 }, "end": { - "line": 172, + "line": 161, "column": 13 } } @@ -10096,33 +9064,33 @@ "decorators": [], "loc": { "start": { - "line": 172, + "line": 161, "column": 27 }, "end": { - "line": 172, + "line": 161, "column": 32 } } }, "loc": { "start": { - "line": 172, + "line": 161, "column": 27 }, "end": { - "line": 172, + "line": 161, "column": 33 } } }, "loc": { "start": { - "line": 172, + "line": 161, "column": 27 }, "end": { - "line": 172, + "line": 161, "column": 33 } } @@ -10135,11 +9103,11 @@ "value": 42, "loc": { "start": { - "line": 172, + "line": 161, "column": 33 }, "end": { - "line": 172, + "line": 161, "column": 35 } } @@ -10148,22 +9116,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 172, + "line": 161, "column": 39 }, "end": { - "line": 172, + "line": 161, "column": 44 } } }, "loc": { "start": { - "line": 172, + "line": 161, "column": 33 }, "end": { - "line": 172, + "line": 161, "column": 35 } } @@ -10171,22 +9139,22 @@ ], "loc": { "start": { - "line": 172, + "line": 161, "column": 23 }, "end": { - "line": 172, + "line": 161, "column": 46 } } }, "loc": { "start": { - "line": 172, + "line": 161, "column": 7 }, "end": { - "line": 172, + "line": 161, "column": 46 } } @@ -10195,11 +9163,11 @@ "kind": "let", "loc": { "start": { - "line": 172, + "line": 161, "column": 3 }, "end": { - "line": 172, + "line": 161, "column": 46 } } @@ -10218,11 +9186,11 @@ "decorators": [], "loc": { "start": { - "line": 176, + "line": 165, "column": 9 }, "end": { - "line": 176, + "line": 165, "column": 19 } } @@ -10235,11 +9203,11 @@ "decorators": [], "loc": { "start": { - "line": 176, + "line": 165, "column": 24 }, "end": { - "line": 176, + "line": 165, "column": 30 } } @@ -10248,33 +9216,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 176, + "line": 165, "column": 34 }, "end": { - "line": 176, + "line": 165, "column": 38 } } }, "loc": { "start": { - "line": 176, + "line": 165, "column": 24 }, "end": { - "line": 176, + "line": 165, "column": 30 } } }, "loc": { "start": { - "line": 176, + "line": 165, "column": 9 }, "end": { - "line": 176, + "line": 165, "column": 30 } } @@ -10283,11 +9251,11 @@ "kind": "let", "loc": { "start": { - "line": 176, + "line": 165, "column": 5 }, "end": { - "line": 176, + "line": 165, "column": 39 } } @@ -10303,11 +9271,11 @@ "decorators": [], "loc": { "start": { - "line": 177, + "line": 166, "column": 9 }, "end": { - "line": 177, + "line": 166, "column": 20 } } @@ -10320,11 +9288,11 @@ "decorators": [], "loc": { "start": { - "line": 177, + "line": 166, "column": 24 }, "end": { - "line": 177, + "line": 166, "column": 30 } } @@ -10333,33 +9301,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 177, + "line": 166, "column": 34 }, "end": { - "line": 177, + "line": 166, "column": 39 } } }, "loc": { "start": { - "line": 177, + "line": 166, "column": 24 }, "end": { - "line": 177, + "line": 166, "column": 30 } } }, "loc": { "start": { - "line": 177, + "line": 166, "column": 9 }, "end": { - "line": 177, + "line": 166, "column": 30 } } @@ -10368,11 +9336,11 @@ "kind": "let", "loc": { "start": { - "line": 177, + "line": 166, "column": 5 }, "end": { - "line": 177, + "line": 166, "column": 40 } } @@ -10388,11 +9356,11 @@ "decorators": [], "loc": { "start": { - "line": 178, + "line": 167, "column": 9 }, "end": { - "line": 178, + "line": 167, "column": 19 } } @@ -10405,11 +9373,11 @@ "decorators": [], "loc": { "start": { - "line": 178, + "line": 167, "column": 24 }, "end": { - "line": 178, + "line": 167, "column": 30 } } @@ -10418,33 +9386,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 178, + "line": 167, "column": 34 }, "end": { - "line": 178, + "line": 167, "column": 38 } } }, "loc": { "start": { - "line": 178, + "line": 167, "column": 24 }, "end": { - "line": 178, + "line": 167, "column": 30 } } }, "loc": { "start": { - "line": 178, + "line": 167, "column": 9 }, "end": { - "line": 178, + "line": 167, "column": 30 } } @@ -10453,11 +9421,11 @@ "kind": "let", "loc": { "start": { - "line": 178, + "line": 167, "column": 5 }, "end": { - "line": 178, + "line": 167, "column": 39 } } @@ -10473,11 +9441,11 @@ "decorators": [], "loc": { "start": { - "line": 179, + "line": 168, "column": 9 }, "end": { - "line": 179, + "line": 168, "column": 18 } } @@ -10490,11 +9458,11 @@ "decorators": [], "loc": { "start": { - "line": 179, + "line": 168, "column": 24 }, "end": { - "line": 179, + "line": 168, "column": 30 } } @@ -10503,33 +9471,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 179, + "line": 168, "column": 34 }, "end": { - "line": 179, + "line": 168, "column": 37 } } }, "loc": { "start": { - "line": 179, + "line": 168, "column": 24 }, "end": { - "line": 179, + "line": 168, "column": 30 } } }, "loc": { "start": { - "line": 179, + "line": 168, "column": 9 }, "end": { - "line": 179, + "line": 168, "column": 30 } } @@ -10538,11 +9506,11 @@ "kind": "let", "loc": { "start": { - "line": 179, + "line": 168, "column": 5 }, "end": { - "line": 179, + "line": 168, "column": 38 } } @@ -10558,11 +9526,11 @@ "decorators": [], "loc": { "start": { - "line": 180, + "line": 169, "column": 9 }, "end": { - "line": 180, + "line": 169, "column": 19 } } @@ -10575,11 +9543,11 @@ "decorators": [], "loc": { "start": { - "line": 180, + "line": 169, "column": 24 }, "end": { - "line": 180, + "line": 169, "column": 30 } } @@ -10588,33 +9556,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 180, + "line": 169, "column": 34 }, "end": { - "line": 180, + "line": 169, "column": 38 } } }, "loc": { "start": { - "line": 180, + "line": 169, "column": 24 }, "end": { - "line": 180, + "line": 169, "column": 30 } } }, "loc": { "start": { - "line": 180, + "line": 169, "column": 9 }, "end": { - "line": 180, + "line": 169, "column": 30 } } @@ -10623,11 +9591,11 @@ "kind": "let", "loc": { "start": { - "line": 180, + "line": 169, "column": 5 }, "end": { - "line": 180, + "line": 169, "column": 39 } } @@ -10643,11 +9611,11 @@ "decorators": [], "loc": { "start": { - "line": 181, + "line": 170, "column": 9 }, "end": { - "line": 181, + "line": 170, "column": 20 } } @@ -10660,11 +9628,11 @@ "decorators": [], "loc": { "start": { - "line": 181, + "line": 170, "column": 24 }, "end": { - "line": 181, + "line": 170, "column": 30 } } @@ -10673,33 +9641,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 181, + "line": 170, "column": 34 }, "end": { - "line": 181, + "line": 170, "column": 39 } } }, "loc": { "start": { - "line": 181, + "line": 170, "column": 24 }, "end": { - "line": 181, + "line": 170, "column": 30 } } }, "loc": { "start": { - "line": 181, + "line": 170, "column": 9 }, "end": { - "line": 181, + "line": 170, "column": 30 } } @@ -10708,11 +9676,11 @@ "kind": "let", "loc": { "start": { - "line": 181, + "line": 170, "column": 5 }, "end": { - "line": 181, + "line": 170, "column": 40 } } @@ -10728,11 +9696,11 @@ "decorators": [], "loc": { "start": { - "line": 182, + "line": 171, "column": 9 }, "end": { - "line": 182, + "line": 171, "column": 21 } } @@ -10745,11 +9713,11 @@ "decorators": [], "loc": { "start": { - "line": 182, + "line": 171, "column": 24 }, "end": { - "line": 182, + "line": 171, "column": 30 } } @@ -10758,33 +9726,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 182, + "line": 171, "column": 34 }, "end": { - "line": 182, + "line": 171, "column": 40 } } }, "loc": { "start": { - "line": 182, + "line": 171, "column": 24 }, "end": { - "line": 182, + "line": 171, "column": 30 } } }, "loc": { "start": { - "line": 182, + "line": 171, "column": 9 }, "end": { - "line": 182, + "line": 171, "column": 30 } } @@ -10793,11 +9761,11 @@ "kind": "let", "loc": { "start": { - "line": 182, + "line": 171, "column": 5 }, "end": { - "line": 182, + "line": 171, "column": 41 } } @@ -10813,11 +9781,11 @@ "decorators": [], "loc": { "start": { - "line": 184, + "line": 173, "column": 9 }, "end": { - "line": 184, + "line": 173, "column": 20 } } @@ -10830,11 +9798,11 @@ "decorators": [], "loc": { "start": { - "line": 184, + "line": 173, "column": 24 }, "end": { - "line": 184, + "line": 173, "column": 30 } } @@ -10843,33 +9811,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 184, + "line": 173, "column": 34 }, "end": { - "line": 184, + "line": 173, "column": 39 } } }, "loc": { "start": { - "line": 184, + "line": 173, "column": 24 }, "end": { - "line": 184, + "line": 173, "column": 30 } } }, "loc": { "start": { - "line": 184, + "line": 173, "column": 9 }, "end": { - "line": 184, + "line": 173, "column": 30 } } @@ -10878,11 +9846,11 @@ "kind": "let", "loc": { "start": { - "line": 184, + "line": 173, "column": 5 }, "end": { - "line": 184, + "line": 173, "column": 40 } } @@ -10898,11 +9866,11 @@ "decorators": [], "loc": { "start": { - "line": 185, + "line": 174, "column": 9 }, "end": { - "line": 185, + "line": 174, "column": 21 } } @@ -10915,11 +9883,11 @@ "decorators": [], "loc": { "start": { - "line": 185, + "line": 174, "column": 24 }, "end": { - "line": 185, + "line": 174, "column": 30 } } @@ -10928,33 +9896,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 185, + "line": 174, "column": 34 }, "end": { - "line": 185, + "line": 174, "column": 40 } } }, "loc": { "start": { - "line": 185, + "line": 174, "column": 24 }, "end": { - "line": 185, + "line": 174, "column": 30 } } }, "loc": { "start": { - "line": 185, + "line": 174, "column": 9 }, "end": { - "line": 185, + "line": 174, "column": 30 } } @@ -10963,11 +9931,11 @@ "kind": "let", "loc": { "start": { - "line": 185, + "line": 174, "column": 5 }, "end": { - "line": 185, + "line": 174, "column": 41 } } @@ -10975,11 +9943,11 @@ ], "loc": { "start": { - "line": 174, + "line": 163, "column": 3 }, "end": { - "line": 186, + "line": 175, "column": 4 } } @@ -10998,11 +9966,11 @@ "decorators": [], "loc": { "start": { - "line": 190, + "line": 179, "column": 9 }, "end": { - "line": 190, + "line": 179, "column": 20 } } @@ -11015,11 +9983,11 @@ "decorators": [], "loc": { "start": { - "line": 190, + "line": 179, "column": 25 }, "end": { - "line": 190, + "line": 179, "column": 31 } } @@ -11034,55 +10002,55 @@ "decorators": [], "loc": { "start": { - "line": 190, + "line": 179, "column": 35 }, "end": { - "line": 190, + "line": 179, "column": 40 } } }, "loc": { "start": { - "line": 190, + "line": 179, "column": 35 }, "end": { - "line": 190, + "line": 179, "column": 41 } } }, "loc": { "start": { - "line": 190, + "line": 179, "column": 35 }, "end": { - "line": 190, + "line": 179, "column": 41 } } }, "loc": { "start": { - "line": 190, + "line": 179, "column": 25 }, "end": { - "line": 190, + "line": 179, "column": 31 } } }, "loc": { "start": { - "line": 190, + "line": 179, "column": 9 }, "end": { - "line": 190, + "line": 179, "column": 31 } } @@ -11091,11 +10059,11 @@ "kind": "let", "loc": { "start": { - "line": 190, + "line": 179, "column": 5 }, "end": { - "line": 190, + "line": 179, "column": 41 } } @@ -11111,11 +10079,11 @@ "decorators": [], "loc": { "start": { - "line": 191, + "line": 180, "column": 9 }, "end": { - "line": 191, + "line": 180, "column": 20 } } @@ -11128,11 +10096,11 @@ "decorators": [], "loc": { "start": { - "line": 191, + "line": 180, "column": 25 }, "end": { - "line": 191, + "line": 180, "column": 31 } } @@ -11147,55 +10115,55 @@ "decorators": [], "loc": { "start": { - "line": 191, + "line": 180, "column": 35 }, "end": { - "line": 191, + "line": 180, "column": 40 } } }, "loc": { "start": { - "line": 191, + "line": 180, "column": 35 }, "end": { - "line": 191, + "line": 180, "column": 41 } } }, "loc": { "start": { - "line": 191, + "line": 180, "column": 35 }, "end": { - "line": 191, + "line": 180, "column": 41 } } }, "loc": { "start": { - "line": 191, + "line": 180, "column": 25 }, "end": { - "line": 191, + "line": 180, "column": 31 } } }, "loc": { "start": { - "line": 191, + "line": 180, "column": 9 }, "end": { - "line": 191, + "line": 180, "column": 31 } } @@ -11204,11 +10172,11 @@ "kind": "let", "loc": { "start": { - "line": 191, + "line": 180, "column": 5 }, "end": { - "line": 191, + "line": 180, "column": 41 } } @@ -11224,11 +10192,11 @@ "decorators": [], "loc": { "start": { - "line": 192, + "line": 181, "column": 9 }, "end": { - "line": 192, + "line": 181, "column": 21 } } @@ -11241,11 +10209,11 @@ "decorators": [], "loc": { "start": { - "line": 192, + "line": 181, "column": 25 }, "end": { - "line": 192, + "line": 181, "column": 31 } } @@ -11260,55 +10228,55 @@ "decorators": [], "loc": { "start": { - "line": 192, + "line": 181, "column": 35 }, "end": { - "line": 192, + "line": 181, "column": 41 } } }, "loc": { "start": { - "line": 192, + "line": 181, "column": 35 }, "end": { - "line": 192, + "line": 181, "column": 42 } } }, "loc": { "start": { - "line": 192, + "line": 181, "column": 35 }, "end": { - "line": 192, + "line": 181, "column": 42 } } }, "loc": { "start": { - "line": 192, + "line": 181, "column": 25 }, "end": { - "line": 192, + "line": 181, "column": 31 } } }, "loc": { "start": { - "line": 192, + "line": 181, "column": 9 }, "end": { - "line": 192, + "line": 181, "column": 31 } } @@ -11317,11 +10285,11 @@ "kind": "let", "loc": { "start": { - "line": 192, + "line": 181, "column": 5 }, "end": { - "line": 192, + "line": 181, "column": 42 } } @@ -11329,11 +10297,11 @@ ], "loc": { "start": { - "line": 188, + "line": 177, "column": 3 }, "end": { - "line": 193, + "line": 182, "column": 4 } } @@ -11341,33 +10309,33 @@ ], "loc": { "start": { - "line": 170, + "line": 159, "column": 29 }, "end": { - "line": 194, + "line": 183, "column": 2 } } }, "loc": { "start": { - "line": 170, + "line": 159, "column": 20 }, "end": { - "line": 194, + "line": 183, "column": 2 } } }, "loc": { "start": { - "line": 170, + "line": 159, "column": 20 }, "end": { - "line": 194, + "line": 183, "column": 2 } } @@ -11376,11 +10344,11 @@ "decorators": [], "loc": { "start": { - "line": 170, + "line": 159, "column": 1 }, "end": { - "line": 194, + "line": 183, "column": 2 } } @@ -11393,11 +10361,11 @@ "decorators": [], "loc": { "start": { - "line": 196, + "line": 185, "column": 10 }, "end": { - "line": 196, + "line": 185, "column": 21 } } @@ -11417,11 +10385,11 @@ "decorators": [], "loc": { "start": { - "line": 196, + "line": 185, "column": 10 }, "end": { - "line": 196, + "line": 185, "column": 21 } } @@ -11440,33 +10408,33 @@ "decorators": [], "loc": { "start": { - "line": 196, + "line": 185, "column": 25 }, "end": { - "line": 196, + "line": 185, "column": 29 } } }, "loc": { "start": { - "line": 196, + "line": 185, "column": 25 }, "end": { - "line": 196, + "line": 185, "column": 31 } } }, "loc": { "start": { - "line": 196, + "line": 185, "column": 25 }, "end": { - "line": 196, + "line": 185, "column": 31 } } @@ -11486,11 +10454,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 197, + "line": 186, "column": 16 }, "end": { - "line": 197, + "line": 186, "column": 22 } } @@ -11498,11 +10466,11 @@ "decorators": [], "loc": { "start": { - "line": 197, + "line": 186, "column": 7 }, "end": { - "line": 197, + "line": 186, "column": 14 } } @@ -11512,22 +10480,22 @@ "value": 42, "loc": { "start": { - "line": 197, + "line": 186, "column": 25 }, "end": { - "line": 197, + "line": 186, "column": 27 } } }, "loc": { "start": { - "line": 197, + "line": 186, "column": 7 }, "end": { - "line": 197, + "line": 186, "column": 27 } } @@ -11536,11 +10504,11 @@ "kind": "let", "loc": { "start": { - "line": 197, + "line": 186, "column": 3 }, "end": { - "line": 197, + "line": 186, "column": 28 } } @@ -11563,33 +10531,33 @@ "decorators": [], "loc": { "start": { - "line": 198, + "line": 187, "column": 16 }, "end": { - "line": 198, + "line": 187, "column": 22 } } }, "loc": { "start": { - "line": 198, + "line": 187, "column": 16 }, "end": { - "line": 198, + "line": 187, "column": 24 } } }, "loc": { "start": { - "line": 198, + "line": 187, "column": 16 }, "end": { - "line": 198, + "line": 187, "column": 24 } } @@ -11597,11 +10565,11 @@ "decorators": [], "loc": { "start": { - "line": 198, + "line": 187, "column": 7 }, "end": { - "line": 198, + "line": 187, "column": 14 } } @@ -11618,33 +10586,33 @@ "decorators": [], "loc": { "start": { - "line": 198, + "line": 187, "column": 29 }, "end": { - "line": 198, + "line": 187, "column": 35 } } }, "loc": { "start": { - "line": 198, + "line": 187, "column": 29 }, "end": { - "line": 198, + "line": 187, "column": 36 } } }, "loc": { "start": { - "line": 198, + "line": 187, "column": 29 }, "end": { - "line": 198, + "line": 187, "column": 36 } } @@ -11657,11 +10625,11 @@ "value": 42, "loc": { "start": { - "line": 198, + "line": 187, "column": 36 }, "end": { - "line": 198, + "line": 187, "column": 38 } } @@ -11670,22 +10638,22 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 198, + "line": 187, "column": 42 }, "end": { - "line": 198, + "line": 187, "column": 48 } } }, "loc": { "start": { - "line": 198, + "line": 187, "column": 36 }, "end": { - "line": 198, + "line": 187, "column": 38 } } @@ -11693,22 +10661,22 @@ ], "loc": { "start": { - "line": 198, + "line": 187, "column": 25 }, "end": { - "line": 198, + "line": 187, "column": 50 } } }, "loc": { "start": { - "line": 198, + "line": 187, "column": 7 }, "end": { - "line": 198, + "line": 187, "column": 50 } } @@ -11717,11 +10685,11 @@ "kind": "let", "loc": { "start": { - "line": 198, + "line": 187, "column": 3 }, "end": { - "line": 198, + "line": 187, "column": 50 } } @@ -11740,11 +10708,11 @@ "decorators": [], "loc": { "start": { - "line": 202, + "line": 191, "column": 9 }, "end": { - "line": 202, + "line": 191, "column": 20 } } @@ -11757,11 +10725,11 @@ "decorators": [], "loc": { "start": { - "line": 202, + "line": 191, "column": 25 }, "end": { - "line": 202, + "line": 191, "column": 32 } } @@ -11770,33 +10738,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 202, + "line": 191, "column": 36 }, "end": { - "line": 202, + "line": 191, "column": 40 } } }, "loc": { "start": { - "line": 202, + "line": 191, "column": 25 }, "end": { - "line": 202, + "line": 191, "column": 32 } } }, "loc": { "start": { - "line": 202, + "line": 191, "column": 9 }, "end": { - "line": 202, + "line": 191, "column": 32 } } @@ -11805,11 +10773,11 @@ "kind": "let", "loc": { "start": { - "line": 202, + "line": 191, "column": 5 }, "end": { - "line": 202, + "line": 191, "column": 41 } } @@ -11825,11 +10793,11 @@ "decorators": [], "loc": { "start": { - "line": 203, + "line": 192, "column": 9 }, "end": { - "line": 203, + "line": 192, "column": 21 } } @@ -11842,11 +10810,11 @@ "decorators": [], "loc": { "start": { - "line": 203, + "line": 192, "column": 25 }, "end": { - "line": 203, + "line": 192, "column": 32 } } @@ -11855,33 +10823,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 203, + "line": 192, "column": 36 }, "end": { - "line": 203, + "line": 192, "column": 41 } } }, "loc": { "start": { - "line": 203, + "line": 192, "column": 25 }, "end": { - "line": 203, + "line": 192, "column": 32 } } }, "loc": { "start": { - "line": 203, + "line": 192, "column": 9 }, "end": { - "line": 203, + "line": 192, "column": 32 } } @@ -11890,11 +10858,11 @@ "kind": "let", "loc": { "start": { - "line": 203, + "line": 192, "column": 5 }, "end": { - "line": 203, + "line": 192, "column": 42 } } @@ -11910,11 +10878,11 @@ "decorators": [], "loc": { "start": { - "line": 204, + "line": 193, "column": 9 }, "end": { - "line": 204, + "line": 193, "column": 20 } } @@ -11927,11 +10895,11 @@ "decorators": [], "loc": { "start": { - "line": 204, + "line": 193, "column": 25 }, "end": { - "line": 204, + "line": 193, "column": 32 } } @@ -11940,33 +10908,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 204, + "line": 193, "column": 36 }, "end": { - "line": 204, + "line": 193, "column": 40 } } }, "loc": { "start": { - "line": 204, + "line": 193, "column": 25 }, "end": { - "line": 204, + "line": 193, "column": 32 } } }, "loc": { "start": { - "line": 204, + "line": 193, "column": 9 }, "end": { - "line": 204, + "line": 193, "column": 32 } } @@ -11975,11 +10943,11 @@ "kind": "let", "loc": { "start": { - "line": 204, + "line": 193, "column": 5 }, "end": { - "line": 204, + "line": 193, "column": 41 } } @@ -11995,11 +10963,11 @@ "decorators": [], "loc": { "start": { - "line": 205, + "line": 194, "column": 9 }, "end": { - "line": 205, + "line": 194, "column": 19 } } @@ -12012,11 +10980,11 @@ "decorators": [], "loc": { "start": { - "line": 205, + "line": 194, "column": 25 }, "end": { - "line": 205, + "line": 194, "column": 32 } } @@ -12025,33 +10993,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 205, + "line": 194, "column": 36 }, "end": { - "line": 205, + "line": 194, "column": 39 } } }, "loc": { "start": { - "line": 205, + "line": 194, "column": 25 }, "end": { - "line": 205, + "line": 194, "column": 32 } } }, "loc": { "start": { - "line": 205, + "line": 194, "column": 9 }, "end": { - "line": 205, + "line": 194, "column": 32 } } @@ -12060,11 +11028,11 @@ "kind": "let", "loc": { "start": { - "line": 205, + "line": 194, "column": 5 }, "end": { - "line": 205, + "line": 194, "column": 40 } } @@ -12080,11 +11048,11 @@ "decorators": [], "loc": { "start": { - "line": 206, + "line": 195, "column": 9 }, "end": { - "line": 206, + "line": 195, "column": 20 } } @@ -12097,11 +11065,11 @@ "decorators": [], "loc": { "start": { - "line": 206, + "line": 195, "column": 25 }, "end": { - "line": 206, + "line": 195, "column": 32 } } @@ -12110,33 +11078,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 206, + "line": 195, "column": 36 }, "end": { - "line": 206, + "line": 195, "column": 40 } } }, "loc": { "start": { - "line": 206, + "line": 195, "column": 25 }, "end": { - "line": 206, + "line": 195, "column": 32 } } }, "loc": { "start": { - "line": 206, + "line": 195, "column": 9 }, "end": { - "line": 206, + "line": 195, "column": 32 } } @@ -12145,11 +11113,11 @@ "kind": "let", "loc": { "start": { - "line": 206, + "line": 195, "column": 5 }, "end": { - "line": 206, + "line": 195, "column": 41 } } @@ -12165,11 +11133,11 @@ "decorators": [], "loc": { "start": { - "line": 207, + "line": 196, "column": 9 }, "end": { - "line": 207, + "line": 196, "column": 21 } } @@ -12182,11 +11150,11 @@ "decorators": [], "loc": { "start": { - "line": 207, + "line": 196, "column": 25 }, "end": { - "line": 207, + "line": 196, "column": 32 } } @@ -12195,33 +11163,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 207, + "line": 196, "column": 36 }, "end": { - "line": 207, + "line": 196, "column": 41 } } }, "loc": { "start": { - "line": 207, + "line": 196, "column": 25 }, "end": { - "line": 207, + "line": 196, "column": 32 } } }, "loc": { "start": { - "line": 207, + "line": 196, "column": 9 }, "end": { - "line": 207, + "line": 196, "column": 32 } } @@ -12230,11 +11198,11 @@ "kind": "let", "loc": { "start": { - "line": 207, + "line": 196, "column": 5 }, "end": { - "line": 207, + "line": 196, "column": 42 } } @@ -12250,11 +11218,11 @@ "decorators": [], "loc": { "start": { - "line": 208, + "line": 197, "column": 9 }, "end": { - "line": 208, + "line": 197, "column": 22 } } @@ -12267,11 +11235,11 @@ "decorators": [], "loc": { "start": { - "line": 208, + "line": 197, "column": 25 }, "end": { - "line": 208, + "line": 197, "column": 32 } } @@ -12280,33 +11248,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 208, + "line": 197, "column": 36 }, "end": { - "line": 208, + "line": 197, "column": 42 } } }, "loc": { "start": { - "line": 208, + "line": 197, "column": 25 }, "end": { - "line": 208, + "line": 197, "column": 32 } } }, "loc": { "start": { - "line": 208, + "line": 197, "column": 9 }, "end": { - "line": 208, + "line": 197, "column": 32 } } @@ -12315,11 +11283,11 @@ "kind": "let", "loc": { "start": { - "line": 208, + "line": 197, "column": 5 }, "end": { - "line": 208, + "line": 197, "column": 43 } } @@ -12335,11 +11303,11 @@ "decorators": [], "loc": { "start": { - "line": 210, + "line": 199, "column": 9 }, "end": { - "line": 210, + "line": 199, "column": 22 } } @@ -12352,11 +11320,11 @@ "decorators": [], "loc": { "start": { - "line": 210, + "line": 199, "column": 25 }, "end": { - "line": 210, + "line": 199, "column": 32 } } @@ -12365,33 +11333,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 210, + "line": 199, "column": 36 }, "end": { - "line": 210, + "line": 199, "column": 42 } } }, "loc": { "start": { - "line": 210, + "line": 199, "column": 25 }, "end": { - "line": 210, + "line": 199, "column": 32 } } }, "loc": { "start": { - "line": 210, + "line": 199, "column": 9 }, "end": { - "line": 210, + "line": 199, "column": 32 } } @@ -12400,11 +11368,11 @@ "kind": "let", "loc": { "start": { - "line": 210, + "line": 199, "column": 5 }, "end": { - "line": 210, + "line": 199, "column": 43 } } @@ -12412,11 +11380,11 @@ ], "loc": { "start": { - "line": 200, + "line": 189, "column": 3 }, "end": { - "line": 211, + "line": 200, "column": 4 } } @@ -12435,11 +11403,11 @@ "decorators": [], "loc": { "start": { - "line": 215, + "line": 204, "column": 9 }, "end": { - "line": 215, + "line": 204, "column": 22 } } @@ -12452,11 +11420,11 @@ "decorators": [], "loc": { "start": { - "line": 215, + "line": 204, "column": 27 }, "end": { - "line": 215, + "line": 204, "column": 34 } } @@ -12471,55 +11439,55 @@ "decorators": [], "loc": { "start": { - "line": 215, + "line": 204, "column": 38 }, "end": { - "line": 215, + "line": 204, "column": 44 } } }, "loc": { "start": { - "line": 215, + "line": 204, "column": 38 }, "end": { - "line": 215, + "line": 204, "column": 45 } } }, "loc": { "start": { - "line": 215, + "line": 204, "column": 38 }, "end": { - "line": 215, + "line": 204, "column": 45 } } }, "loc": { "start": { - "line": 215, + "line": 204, "column": 27 }, "end": { - "line": 215, + "line": 204, "column": 34 } } }, "loc": { "start": { - "line": 215, + "line": 204, "column": 9 }, "end": { - "line": 215, + "line": 204, "column": 34 } } @@ -12528,11 +11496,11 @@ "kind": "let", "loc": { "start": { - "line": 215, + "line": 204, "column": 5 }, "end": { - "line": 215, + "line": 204, "column": 45 } } @@ -12548,11 +11516,11 @@ "decorators": [], "loc": { "start": { - "line": 216, + "line": 205, "column": 9 }, "end": { - "line": 216, + "line": 205, "column": 22 } } @@ -12565,11 +11533,11 @@ "decorators": [], "loc": { "start": { - "line": 216, + "line": 205, "column": 27 }, "end": { - "line": 216, + "line": 205, "column": 34 } } @@ -12584,55 +11552,55 @@ "decorators": [], "loc": { "start": { - "line": 216, + "line": 205, "column": 38 }, "end": { - "line": 216, + "line": 205, "column": 44 } } }, "loc": { "start": { - "line": 216, + "line": 205, "column": 38 }, "end": { - "line": 216, + "line": 205, "column": 45 } } }, "loc": { "start": { - "line": 216, + "line": 205, "column": 38 }, "end": { - "line": 216, + "line": 205, "column": 45 } } }, "loc": { "start": { - "line": 216, + "line": 205, "column": 27 }, "end": { - "line": 216, + "line": 205, "column": 34 } } }, "loc": { "start": { - "line": 216, + "line": 205, "column": 9 }, "end": { - "line": 216, + "line": 205, "column": 34 } } @@ -12641,11 +11609,11 @@ "kind": "let", "loc": { "start": { - "line": 216, + "line": 205, "column": 5 }, "end": { - "line": 216, + "line": 205, "column": 45 } } @@ -12661,11 +11629,11 @@ "decorators": [], "loc": { "start": { - "line": 217, + "line": 206, "column": 9 }, "end": { - "line": 217, + "line": 206, "column": 22 } } @@ -12678,11 +11646,11 @@ "decorators": [], "loc": { "start": { - "line": 217, + "line": 206, "column": 27 }, "end": { - "line": 217, + "line": 206, "column": 34 } } @@ -12697,55 +11665,55 @@ "decorators": [], "loc": { "start": { - "line": 217, + "line": 206, "column": 38 }, "end": { - "line": 217, + "line": 206, "column": 44 } } }, "loc": { "start": { - "line": 217, + "line": 206, "column": 38 }, "end": { - "line": 217, + "line": 206, "column": 45 } } }, "loc": { "start": { - "line": 217, + "line": 206, "column": 38 }, "end": { - "line": 217, + "line": 206, "column": 45 } } }, "loc": { "start": { - "line": 217, + "line": 206, "column": 27 }, "end": { - "line": 217, + "line": 206, "column": 34 } } }, "loc": { "start": { - "line": 217, + "line": 206, "column": 9 }, "end": { - "line": 217, + "line": 206, "column": 34 } } @@ -12754,11 +11722,11 @@ "kind": "let", "loc": { "start": { - "line": 217, + "line": 206, "column": 5 }, "end": { - "line": 217, + "line": 206, "column": 45 } } @@ -12766,11 +11734,11 @@ ], "loc": { "start": { - "line": 213, + "line": 202, "column": 3 }, "end": { - "line": 218, + "line": 207, "column": 4 } } @@ -12778,33 +11746,33 @@ ], "loc": { "start": { - "line": 196, + "line": 185, "column": 30 }, "end": { - "line": 219, + "line": 208, "column": 2 } } }, "loc": { "start": { - "line": 196, + "line": 185, "column": 21 }, "end": { - "line": 219, + "line": 208, "column": 2 } } }, "loc": { "start": { - "line": 196, + "line": 185, "column": 21 }, "end": { - "line": 219, + "line": 208, "column": 2 } } @@ -12813,11 +11781,11 @@ "decorators": [], "loc": { "start": { - "line": 196, + "line": 185, "column": 1 }, "end": { - "line": 219, + "line": 208, "column": 2 } } @@ -12830,11 +11798,11 @@ "decorators": [], "loc": { "start": { - "line": 221, + "line": 210, "column": 10 }, "end": { - "line": 221, + "line": 210, "column": 22 } } @@ -12854,11 +11822,11 @@ "decorators": [], "loc": { "start": { - "line": 221, + "line": 210, "column": 10 }, "end": { - "line": 221, + "line": 210, "column": 22 } } @@ -12877,33 +11845,33 @@ "decorators": [], "loc": { "start": { - "line": 221, + "line": 210, "column": 26 }, "end": { - "line": 221, + "line": 210, "column": 30 } } }, "loc": { "start": { - "line": 221, + "line": 210, "column": 26 }, "end": { - "line": 221, + "line": 210, "column": 32 } } }, "loc": { "start": { - "line": 221, + "line": 210, "column": 26 }, "end": { - "line": 221, + "line": 210, "column": 32 } } @@ -12923,11 +11891,11 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 222, + "line": 211, "column": 17 }, "end": { - "line": 222, + "line": 211, "column": 24 } } @@ -12935,11 +11903,11 @@ "decorators": [], "loc": { "start": { - "line": 222, + "line": 211, "column": 7 }, "end": { - "line": 222, + "line": 211, "column": 15 } } @@ -12949,22 +11917,22 @@ "value": true, "loc": { "start": { - "line": 222, + "line": 211, "column": 27 }, "end": { - "line": 222, + "line": 211, "column": 31 } } }, "loc": { "start": { - "line": 222, + "line": 211, "column": 7 }, "end": { - "line": 222, + "line": 211, "column": 31 } } @@ -12973,11 +11941,11 @@ "kind": "let", "loc": { "start": { - "line": 222, + "line": 211, "column": 3 }, "end": { - "line": 222, + "line": 211, "column": 32 } } @@ -13000,33 +11968,33 @@ "decorators": [], "loc": { "start": { - "line": 223, + "line": 212, "column": 17 }, "end": { - "line": 223, + "line": 212, "column": 24 } } }, "loc": { "start": { - "line": 223, + "line": 212, "column": 17 }, "end": { - "line": 223, + "line": 212, "column": 26 } } }, "loc": { "start": { - "line": 223, + "line": 212, "column": 17 }, "end": { - "line": 223, + "line": 212, "column": 26 } } @@ -13034,11 +12002,11 @@ "decorators": [], "loc": { "start": { - "line": 223, + "line": 212, "column": 7 }, "end": { - "line": 223, + "line": 212, "column": 15 } } @@ -13055,33 +12023,33 @@ "decorators": [], "loc": { "start": { - "line": 223, + "line": 212, "column": 31 }, "end": { - "line": 223, + "line": 212, "column": 38 } } }, "loc": { "start": { - "line": 223, + "line": 212, "column": 31 }, "end": { - "line": 223, + "line": 212, "column": 39 } } }, "loc": { "start": { - "line": 223, + "line": 212, "column": 31 }, "end": { - "line": 223, + "line": 212, "column": 39 } } @@ -13092,11 +12060,11 @@ "value": true, "loc": { "start": { - "line": 223, + "line": 212, "column": 39 }, "end": { - "line": 223, + "line": 212, "column": 43 } } @@ -13104,22 +12072,22 @@ ], "loc": { "start": { - "line": 223, + "line": 212, "column": 27 }, "end": { - "line": 223, + "line": 212, "column": 45 } } }, "loc": { "start": { - "line": 223, + "line": 212, "column": 7 }, "end": { - "line": 223, + "line": 212, "column": 45 } } @@ -13128,11 +12096,11 @@ "kind": "let", "loc": { "start": { - "line": 223, + "line": 212, "column": 3 }, "end": { - "line": 223, + "line": 212, "column": 45 } } @@ -13151,11 +12119,11 @@ "decorators": [], "loc": { "start": { - "line": 227, + "line": 216, "column": 9 }, "end": { - "line": 227, + "line": 216, "column": 24 } } @@ -13168,11 +12136,11 @@ "decorators": [], "loc": { "start": { - "line": 227, + "line": 216, "column": 27 }, "end": { - "line": 227, + "line": 216, "column": 35 } } @@ -13181,33 +12149,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 227, + "line": 216, "column": 39 }, "end": { - "line": 227, + "line": 216, "column": 46 } } }, "loc": { "start": { - "line": 227, + "line": 216, "column": 27 }, "end": { - "line": 227, + "line": 216, "column": 35 } } }, "loc": { "start": { - "line": 227, + "line": 216, "column": 9 }, "end": { - "line": 227, + "line": 216, "column": 35 } } @@ -13216,11 +12184,11 @@ "kind": "let", "loc": { "start": { - "line": 227, + "line": 216, "column": 5 }, "end": { - "line": 227, + "line": 216, "column": 47 } } @@ -13236,11 +12204,11 @@ "decorators": [], "loc": { "start": { - "line": 228, + "line": 217, "column": 9 }, "end": { - "line": 228, + "line": 217, "column": 24 } } @@ -13253,11 +12221,11 @@ "decorators": [], "loc": { "start": { - "line": 228, + "line": 217, "column": 27 }, "end": { - "line": 228, + "line": 217, "column": 35 } } @@ -13266,33 +12234,33 @@ "type": "ETSPrimitiveType", "loc": { "start": { - "line": 228, + "line": 217, "column": 39 }, "end": { - "line": 228, + "line": 217, "column": 46 } } }, "loc": { "start": { - "line": 228, + "line": 217, "column": 27 }, "end": { - "line": 228, + "line": 217, "column": 35 } } }, "loc": { "start": { - "line": 228, + "line": 217, "column": 9 }, "end": { - "line": 228, + "line": 217, "column": 35 } } @@ -13301,11 +12269,11 @@ "kind": "let", "loc": { "start": { - "line": 228, + "line": 217, "column": 5 }, "end": { - "line": 228, + "line": 217, "column": 47 } } @@ -13313,11 +12281,11 @@ ], "loc": { "start": { - "line": 225, + "line": 214, "column": 3 }, "end": { - "line": 229, + "line": 218, "column": 4 } } @@ -13336,11 +12304,11 @@ "decorators": [], "loc": { "start": { - "line": 233, + "line": 222, "column": 9 }, "end": { - "line": 233, + "line": 222, "column": 24 } } @@ -13353,11 +12321,11 @@ "decorators": [], "loc": { "start": { - "line": 233, + "line": 222, "column": 27 }, "end": { - "line": 233, + "line": 222, "column": 35 } } @@ -13372,55 +12340,55 @@ "decorators": [], "loc": { "start": { - "line": 233, + "line": 222, "column": 39 }, "end": { - "line": 233, + "line": 222, "column": 46 } } }, "loc": { "start": { - "line": 233, + "line": 222, "column": 39 }, "end": { - "line": 233, + "line": 222, "column": 47 } } }, "loc": { "start": { - "line": 233, + "line": 222, "column": 39 }, "end": { - "line": 233, + "line": 222, "column": 47 } } }, "loc": { "start": { - "line": 233, + "line": 222, "column": 27 }, "end": { - "line": 233, + "line": 222, "column": 35 } } }, "loc": { "start": { - "line": 233, + "line": 222, "column": 9 }, "end": { - "line": 233, + "line": 222, "column": 35 } } @@ -13429,11 +12397,11 @@ "kind": "let", "loc": { "start": { - "line": 233, + "line": 222, "column": 5 }, "end": { - "line": 233, + "line": 222, "column": 47 } } @@ -13449,11 +12417,11 @@ "decorators": [], "loc": { "start": { - "line": 234, + "line": 223, "column": 9 }, "end": { - "line": 234, + "line": 223, "column": 24 } } @@ -13466,11 +12434,11 @@ "decorators": [], "loc": { "start": { - "line": 234, + "line": 223, "column": 27 }, "end": { - "line": 234, + "line": 223, "column": 35 } } @@ -13485,55 +12453,55 @@ "decorators": [], "loc": { "start": { - "line": 234, + "line": 223, "column": 39 }, "end": { - "line": 234, + "line": 223, "column": 46 } } }, "loc": { "start": { - "line": 234, + "line": 223, "column": 39 }, "end": { - "line": 234, + "line": 223, "column": 47 } } }, "loc": { "start": { - "line": 234, + "line": 223, "column": 39 }, "end": { - "line": 234, + "line": 223, "column": 47 } } }, "loc": { "start": { - "line": 234, + "line": 223, "column": 27 }, "end": { - "line": 234, + "line": 223, "column": 35 } } }, "loc": { "start": { - "line": 234, + "line": 223, "column": 9 }, "end": { - "line": 234, + "line": 223, "column": 35 } } @@ -13542,11 +12510,11 @@ "kind": "let", "loc": { "start": { - "line": 234, + "line": 223, "column": 5 }, "end": { - "line": 234, + "line": 223, "column": 47 } } @@ -13562,11 +12530,11 @@ "decorators": [], "loc": { "start": { - "line": 235, + "line": 224, "column": 9 }, "end": { - "line": 235, + "line": 224, "column": 23 } } @@ -13579,11 +12547,11 @@ "decorators": [], "loc": { "start": { - "line": 235, + "line": 224, "column": 27 }, "end": { - "line": 235, + "line": 224, "column": 35 } } @@ -13598,55 +12566,55 @@ "decorators": [], "loc": { "start": { - "line": 235, + "line": 224, "column": 39 }, "end": { - "line": 235, + "line": 224, "column": 45 } } }, "loc": { "start": { - "line": 235, + "line": 224, "column": 39 }, "end": { - "line": 235, + "line": 224, "column": 46 } } }, "loc": { "start": { - "line": 235, + "line": 224, "column": 39 }, "end": { - "line": 235, + "line": 224, "column": 46 } } }, "loc": { "start": { - "line": 235, + "line": 224, "column": 27 }, "end": { - "line": 235, + "line": 224, "column": 35 } } }, "loc": { "start": { - "line": 235, + "line": 224, "column": 9 }, "end": { - "line": 235, + "line": 224, "column": 35 } } @@ -13655,11 +12623,11 @@ "kind": "let", "loc": { "start": { - "line": 235, + "line": 224, "column": 5 }, "end": { - "line": 235, + "line": 224, "column": 46 } } @@ -13667,11 +12635,11 @@ ], "loc": { "start": { - "line": 231, + "line": 220, "column": 3 }, "end": { - "line": 236, + "line": 225, "column": 4 } } @@ -13679,33 +12647,33 @@ ], "loc": { "start": { - "line": 221, + "line": 210, "column": 31 }, "end": { - "line": 237, + "line": 226, "column": 2 } } }, "loc": { "start": { - "line": 221, + "line": 210, "column": 22 }, "end": { - "line": 237, + "line": 226, "column": 2 } } }, "loc": { "start": { - "line": 221, + "line": 210, "column": 22 }, "end": { - "line": 237, + "line": 226, "column": 2 } } @@ -13714,11 +12682,11 @@ "decorators": [], "loc": { "start": { - "line": 221, + "line": 210, "column": 1 }, "end": { - "line": 237, + "line": 226, "column": 2 } } @@ -13753,7 +12721,7 @@ "column": 1 }, "end": { - "line": 238, + "line": 227, "column": 1 } } diff --git a/ets2panda/test/parser/ets/cast_expressions.ets b/ets2panda/test/parser/ets/cast_expressions.ets index e621cec4d6443ca61227ae4d275de184434ab20d..63b1962a16306e816e1058f1b646523ae124c5a8 100644 --- a/ets2panda/test/parser/ets/cast_expressions.ets +++ b/ets2panda/test/parser/ets/cast_expressions.ets @@ -13,17 +13,6 @@ * limitations under the License. */ -function null_test(): void { - let Byte_ = null as Byte; - let Short_ = null as Short; - let Char_ = null as Char; - let Int_ = null as Int; - let Long_ = null as Long; - let Float_ = null as Float; - let Double_ = null as Double; - let Object = null as Object; -} - function byte_test(): void { let byte_: byte = 42; let Byte_: Byte = new Byte(42 as byte); diff --git a/ets2panda/test/parser/ets/cast_expressions6-expected.txt b/ets2panda/test/parser/ets/cast_expressions6-expected.txt index 90118201406286af242ed40837bf99fcf1e8b79b..3ea0bddc375f2d06ef165aa5fc16a1fd5ec6cc97 100644 --- a/ets2panda/test/parser/ets/cast_expressions6-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions6-expected.txt @@ -1,555 +1 @@ -{ - "type": "Program", - "statements": [ - { - "type": "ClassDeclaration", - "definition": { - "id": { - "type": "Identifier", - "name": "ETSGLOBAL", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "superClass": null, - "implements": [], - "body": [ - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "_$init$_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "kind": "method", - "accessibility": "public", - "static": true, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "_$init$_", - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "MethodDefinition", - "key": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10 - }, - "end": { - "line": 16, - "column": 14 - } - } - }, - "kind": "method", - "accessibility": "public", - "static": true, - "optional": false, - "computed": false, - "value": { - "type": "FunctionExpression", - "function": { - "type": "ScriptFunction", - "id": { - "type": "Identifier", - "name": "main", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 10 - }, - "end": { - "line": 16, - "column": 14 - } - } - }, - "generator": false, - "async": false, - "expression": false, - "params": [], - "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "void", - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 18 - }, - "end": { - "line": 16, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 18 - }, - "end": { - "line": 16, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 18 - }, - "end": { - "line": 16, - "column": 24 - } - } - }, - "body": { - "type": "BlockStatement", - "statements": [ - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Object_", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 22 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 24 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 24 - } - } - }, - "decorators": [], - "loc": { - "start": { - "line": 17, - "column": 7 - }, - "end": { - "line": 17, - "column": 14 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "NullLiteral", - "value": null, - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 29 - } - } - }, - "typeAnnotation": { - "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 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 33 - }, - "end": { - "line": 17, - "column": 40 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 25 - }, - "end": { - "line": 17, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 17, - "column": 7 - }, - "end": { - "line": 17, - "column": 29 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 17, - "column": 3 - }, - "end": { - "line": 17, - "column": 40 - } - } - }, - { - "type": "VariableDeclaration", - "declarations": [ - { - "type": "VariableDeclarator", - "id": { - "type": "Identifier", - "name": "Int_", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 7 - }, - "end": { - "line": 18, - "column": 11 - } - } - }, - "init": { - "type": "TSAsExpression", - "expression": { - "type": "Identifier", - "name": "Object_", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 14 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Int", - "decorators": [], - "loc": { - "start": { - "line": 18, - "column": 25 - }, - "end": { - "line": 18, - "column": 28 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 25 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 25 - }, - "end": { - "line": 18, - "column": 29 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 14 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "loc": { - "start": { - "line": 18, - "column": 7 - }, - "end": { - "line": 18, - "column": 21 - } - } - } - ], - "kind": "let", - "loc": { - "start": { - "line": 18, - "column": 3 - }, - "end": { - "line": 18, - "column": 29 - } - } - } - ], - "loc": { - "start": { - "line": 16, - "column": 23 - }, - "end": { - "line": 19, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 19, - "column": 2 - } - } - }, - "loc": { - "start": { - "line": 16, - "column": 14 - }, - "end": { - "line": 19, - "column": 2 - } - } - }, - "overloads": [], - "decorators": [], - "loc": { - "start": { - "line": 16, - "column": 1 - }, - "end": { - "line": 19, - "column": 2 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - } - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 20, - "column": 1 - } - } -} +Failed to open file: /home/snail/wdir/arkruntime/static_core/tools/es2panda/test/parser/ets/cast_expressions6.ets diff --git a/ets2panda/test/parser/ets/default_parameter7-expected.txt b/ets2panda/test/parser/ets/default_parameter7-expected.txt index c6d4b58f37b4e7b7ec71d7ec93e3d29cc8df1f35..b12cbe9c5d87532939f8e563d9e53f64cef2ca44 100644 --- a/ets2panda/test/parser/ets/default_parameter7-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter7-expected.txt @@ -483,13 +483,38 @@ "type": "Identifier", "name": "b", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, "loc": { "start": { "line": 21, @@ -497,21 +522,24 @@ }, "end": { "line": 21, - "column": 34 + "column": 35 } } }, - "loc": { - "start": { - "line": 21, - "column": 28 - }, - "end": { - "line": 21, - "column": 35 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 25 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -882,13 +910,38 @@ "type": "Identifier", "name": "b", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "String", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -900,17 +953,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt index b9803f021ffc4714d36a4bbeaddbe716a29f4bc7..b6a70f9b2ed7e2cdf74a7afe6b606d23ab8f9970 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt @@ -316,4 +316,4 @@ } } } -TypeError: Type '() => void' cannot be assigned to type '(i: int) => int' [function_implicit_return_type2.ets:17:27] +TypeError: Type '() => void' cannot be assigned to type '(p1: Int) => Int' [function_implicit_return_type2.ets:17:27] diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index 86af963d88c0da2bfb2a9312765e549b3382fb33..ef11ad3a7588f5e3f482653456dfb26ed32c6505 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -465,4 +465,4 @@ } } } -TypeError: Type '(i: int) => void' cannot be assigned to type '(i: int) => int' [function_implicit_return_type3.ets:18:27] +TypeError: Type '(i: int) => void' cannot be assigned to type '(p1: Int) => Int' [function_implicit_return_type3.ets:18:27] diff --git a/ets2panda/test/parser/ets/interface-expected.txt b/ets2panda/test/parser/ets/interface-expected.txt index a84f38f68d4849754da0362d7b5a9cd6bd526622..13e389abc2acaec44366f508159f099715f13716 100644 --- a/ets2panda/test/parser/ets/interface-expected.txt +++ b/ets2panda/test/parser/ets/interface-expected.txt @@ -156,7 +156,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Function", + "name": "FunctioN", "decorators": [], "loc": { "start": { @@ -375,4 +375,4 @@ } } } -SyntaxError: Cannot find type 'Function'. [interface.ets:17:39] +SyntaxError: Cannot find type 'FunctioN'. [interface.ets:17:39] diff --git a/ets2panda/test/parser/ets/interface.ets b/ets2panda/test/parser/ets/interface.ets index e43e384d53b1f2491e8c060ef52b7fe76e876e35..80534bb52cecbe31aa07ffe20355ce2d8675a65c 100644 --- a/ets2panda/test/parser/ets/interface.ets +++ b/ets2panda/test/parser/ets/interface.ets @@ -14,5 +14,5 @@ */ -interface G {} +interface G {} diff --git a/ets2panda/test/parser/ets/lambda-type-inference-neg-expected.txt b/ets2panda/test/parser/ets/lambda-type-inference-neg-expected.txt index b814441ff1eb97ccfdb53687762b638838cc1e19..4ac2df4d2f11ea619c64a304f402819012fa2efe 100644 --- a/ets2panda/test/parser/ets/lambda-type-inference-neg-expected.txt +++ b/ets2panda/test/parser/ets/lambda-type-inference-neg-expected.txt @@ -928,4 +928,4 @@ } } } -TypeError: Reference to foo is ambiguous [lambda-type-inference-neg.ets:23:5] +TypeError: Function with this assembly signature already declared. [lambda-type-inference-neg.ets:19:1] diff --git a/ets2panda/test/parser/ets/lambda-type-inference-overloaded-1-expected.txt b/ets2panda/test/parser/ets/lambda-type-inference-overloaded-1-expected.txt index 5c3f1759fa7bb05c48bd7259abfb0a31864cbf07..898613c8c74f3a5b76c2dd433a9588aa22013ac9 100644 --- a/ets2panda/test/parser/ets/lambda-type-inference-overloaded-1-expected.txt +++ b/ets2panda/test/parser/ets/lambda-type-inference-overloaded-1-expected.txt @@ -1963,4 +1963,4 @@ } } } -TypeError: Reference to foo is ambiguous [lambda-type-inference-overloaded-1.ets:32:5] +TypeError: Function with this assembly signature already declared. [lambda-type-inference-overloaded-1.ets:20:1] diff --git a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt index 57e9c0bfdeadebf18cd10bcaa389d9bd0c7b28f2..c61ffafce08d84585226c7b0923e1c69bbf47468 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromFunctionToNonNullable-expected.txt @@ -299,13 +299,38 @@ "expression": false, "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 18, @@ -313,21 +338,24 @@ }, "end": { "line": 18, - "column": 19 + "column": 21 } } }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 21 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 26 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -335,7 +363,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 26 } } }, diff --git a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt index 5698d12fe67bacf68dc54ada5347f73591a888de..41b3b869146c656c06e4772e144df1932b776977 100644 --- a/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableFromMethodToNullableParam-expected.txt @@ -68,13 +68,38 @@ "expression": false, "params": [], "returnType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 17, @@ -82,21 +107,24 @@ }, "end": { "line": 17, - "column": 14 + "column": 16 } } }, - "loc": { - "start": { - "line": 17, - "column": 13 - }, - "end": { - "line": 17, - "column": 16 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 21 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -104,7 +132,7 @@ }, "end": { "line": 17, - "column": 16 + "column": 21 } } }, @@ -555,13 +583,38 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 23, @@ -569,21 +622,24 @@ }, "end": { "line": 23, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 23, - "column": 14 - }, - "end": { - "line": 23, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 23, + "column": 18 + }, + "end": { + "line": 23, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 23, @@ -591,7 +647,7 @@ }, "end": { "line": 23, - "column": 17 + "column": 22 } } }, @@ -913,4 +969,4 @@ } } } -TypeError: Type 'A|null' cannot be assigned to type 'Object' [n_assignNullableFromMethodToNullableParam.ets:24:22] +TypeError: Value is possibly nullish. [n_assignNullableFromMethodToNullableParam.ets:24:22] diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt index ff8820fa74e1a33275c5f7950b96ca1814136a48..2f8cf591f848905060c4975a9d53e2ee1629f170 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullable-expected.txt @@ -437,13 +437,38 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 20, @@ -451,21 +476,24 @@ }, "end": { "line": 20, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 20, + "column": 18 + }, + "end": { + "line": 20, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 20, @@ -473,7 +501,7 @@ }, "end": { "line": 20, - "column": 17 + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt index c5df8b793939af578e1f314d0ab055d0db771f7f..d95f6878d68e681a5d4fbd77ff795ffc8212d6de 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableArray-expected.txt @@ -450,15 +450,40 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "TSArrayType", - "elementType": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 20, @@ -466,32 +491,35 @@ }, "end": { "line": 20, - "column": 15 + "column": 16 } } }, "loc": { "start": { "line": 20, - "column": 14 + "column": 18 }, "end": { "line": 20, - "column": 16 + "column": 19 } } }, - "loc": { - "start": { - "line": 20, - "column": 14 - }, - "end": { - "line": 20, - "column": 16 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 24 + } } } - }, + ], "loc": { "start": { "line": 20, @@ -499,7 +527,7 @@ }, "end": { "line": 20, - "column": 19 + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt index 28ddeff4fb1ce3f0c310d9a4dc4298e59b0c7084..ce9f84a3894291dbadc3ada34f0aa5703ae1ce31 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias-expected.txt @@ -156,13 +156,38 @@ } }, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 18, @@ -170,21 +195,24 @@ }, "end": { "line": 18, - "column": 12 + "column": 14 } } }, - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 14 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 19 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -192,7 +220,7 @@ }, "end": { "line": 18, - "column": 14 + "column": 19 } } }, @@ -566,7 +594,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "AN", + "name": "A", "decorators": [], "loc": { "start": { @@ -575,7 +603,7 @@ }, "end": { "line": 22, - "column": 25 + "column": 24 } } }, @@ -586,7 +614,7 @@ }, "end": { "line": 22, - "column": 26 + "column": 25 } } }, @@ -597,7 +625,7 @@ }, "end": { "line": 22, - "column": 26 + "column": 25 } } }, @@ -609,7 +637,7 @@ }, "end": { "line": 22, - "column": 28 + "column": 27 } } }, @@ -620,7 +648,7 @@ }, "end": { "line": 22, - "column": 28 + "column": 27 } } } @@ -633,7 +661,7 @@ }, "end": { "line": 22, - "column": 28 + "column": 27 } } }, diff --git a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias.ets b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias.ets index 7f3b0dd3c31c496583ec0399c09c7acbaebd2044..2d3123dd49cd681fa4e3a39fd7ebae9f87a5fbcd 100644 --- a/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias.ets +++ b/ets2panda/test/parser/ets/n_assignNullableToNonNullableTypeAlias.ets @@ -19,7 +19,7 @@ type AN = A | null; function main(): void { let x : Object; - let an : AN = new AN(); + let an : AN = new A(); x = an; } diff --git a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt index 229bee6d941c69d7ebe0c589517154c7e9ccf23e..d285a43cd15aba1886361653b0ce232f0b8c6509 100644 --- a/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callFunctionWithNullableParam-expected.txt @@ -556,13 +556,38 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 21, @@ -570,21 +595,24 @@ }, "end": { "line": 21, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -592,7 +620,7 @@ }, "end": { "line": 21, - "column": 17 + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt index 9e0b6dfba65ec74006a89978d032094fd9a99e23..986c26ce7624fc0641ef938df83a114b77c5ba03 100644 --- a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam-expected.txt @@ -847,13 +847,38 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "I", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 25, @@ -861,21 +886,24 @@ }, "end": { "line": 25, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 25, - "column": 14 - }, - "end": { - "line": 25, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 25, + "column": 18 + }, + "end": { + "line": 25, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 25, @@ -883,7 +911,7 @@ }, "end": { "line": 25, - "column": 17 + "column": 22 } } }, @@ -985,9 +1013,49 @@ "callee": { "type": "MemberExpression", "object": { - "type": "Identifier", - "name": "an", - "decorators": [], + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 9 + }, + "end": { + "line": 27, + "column": 11 + } + } + }, + "arguments": [], "loc": { "start": { "line": 27, @@ -995,7 +1063,7 @@ }, "end": { "line": 27, - "column": 7 + "column": 13 } } }, @@ -1006,11 +1074,11 @@ "loc": { "start": { "line": 27, - "column": 8 + "column": 13 }, "end": { "line": 27, - "column": 11 + "column": 16 } } }, @@ -1023,7 +1091,7 @@ }, "end": { "line": 27, - "column": 11 + "column": 16 } } }, @@ -1035,11 +1103,11 @@ "loc": { "start": { "line": 27, - "column": 12 + "column": 17 }, "end": { "line": 27, - "column": 14 + "column": 19 } } } @@ -1052,7 +1120,7 @@ }, "end": { "line": 27, - "column": 15 + "column": 20 } } }, @@ -1063,7 +1131,7 @@ }, "end": { "line": 27, - "column": 16 + "column": 21 } } } @@ -1149,4 +1217,4 @@ } } } -TypeError: Type 'I|null' is not compatible with type 'I' at index 1 [n_callInterfaceMethodWithNullableParam.ets:27:12] +TypeError: Type 'I|null' is not compatible with type 'I' at index 1 [n_callInterfaceMethodWithNullableParam.ets:27:17] diff --git a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam.ets b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam.ets index a28e42f2e8078b32fa05d4eeb413fdfbb996e57e..f8075116f44ad4f2772bb8644d2adbc5ce22efa3 100644 --- a/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam.ets +++ b/ets2panda/test/parser/ets/n_callInterfaceMethodWithNullableParam.ets @@ -24,5 +24,5 @@ class A implements I { function main(): void { let an : I | null = new A(); - an.foo(an); + new A().foo(an); } diff --git a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt index d671817126263aa1cff99ab62ce20a4d19d6daf2..b84e5e8ae0c275e98bfa85b07e463e24f507a2df 100644 --- a/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt +++ b/ets2panda/test/parser/ets/n_callMethodWithNullableParam-expected.txt @@ -556,13 +556,38 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 21, @@ -570,21 +595,24 @@ }, "end": { "line": 21, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 21, - "column": 14 - }, - "end": { - "line": 21, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -592,7 +620,7 @@ }, "end": { "line": 21, - "column": 17 + "column": 22 } } }, @@ -694,9 +722,49 @@ "callee": { "type": "MemberExpression", "object": { - "type": "Identifier", - "name": "an", - "decorators": [], + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 10 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 11 + } + } + }, + "arguments": [], "loc": { "start": { "line": 23, @@ -704,7 +772,7 @@ }, "end": { "line": 23, - "column": 7 + "column": 13 } } }, @@ -715,11 +783,11 @@ "loc": { "start": { "line": 23, - "column": 8 + "column": 13 }, "end": { "line": 23, - "column": 11 + "column": 16 } } }, @@ -732,7 +800,7 @@ }, "end": { "line": 23, - "column": 11 + "column": 16 } } }, @@ -744,11 +812,11 @@ "loc": { "start": { "line": 23, - "column": 12 + "column": 17 }, "end": { "line": 23, - "column": 14 + "column": 19 } } } @@ -761,7 +829,7 @@ }, "end": { "line": 23, - "column": 15 + "column": 20 } } }, @@ -772,7 +840,7 @@ }, "end": { "line": 23, - "column": 16 + "column": 21 } } } @@ -858,4 +926,4 @@ } } } -TypeError: Type 'A|null' is not compatible with type 'A' at index 1 [n_callMethodWithNullableParam.ets:23:12] +TypeError: Type 'A|null' is not compatible with type 'A' at index 1 [n_callMethodWithNullableParam.ets:23:17] diff --git a/ets2panda/test/parser/ets/n_callMethodWithNullableParam.ets b/ets2panda/test/parser/ets/n_callMethodWithNullableParam.ets index 765ae2b5c9c83d6558911fca9de62bfe66429610..7e0aa24c3cd13b192b9eafcce450234d89f14787 100644 --- a/ets2panda/test/parser/ets/n_callMethodWithNullableParam.ets +++ b/ets2panda/test/parser/ets/n_callMethodWithNullableParam.ets @@ -20,5 +20,5 @@ class A { function main(): void { let an : A | null = new A(); - an.foo(an); + new A().foo(an); } diff --git a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt index 3c41b4b7afd7ff6b017bc53cb2116d9c957c532c..06b59c0b1592e9f1bc1fa55a36b8fa81e783bef0 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromFunction-expected.txt @@ -351,13 +351,38 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 19, @@ -365,21 +390,24 @@ }, "end": { "line": 19, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 19, - "column": 14 - }, - "end": { - "line": 19, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 19, @@ -387,7 +415,7 @@ }, "end": { "line": 19, - "column": 17 + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt index 3c9ac3ca46d48e38cd0e19e2b911b6a4b746c820..bde21ce9dd5924dcbe74e8544242537f4c995100 100644 --- a/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt +++ b/ets2panda/test/parser/ets/n_returnNullableFromMethod-expected.txt @@ -120,13 +120,38 @@ "type": "Identifier", "name": "an", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "A", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 18, @@ -134,21 +159,24 @@ }, "end": { "line": 18, - "column": 19 + "column": 21 } } }, - "loc": { - "start": { - "line": 18, - "column": 18 - }, - "end": { - "line": 18, - "column": 21 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 22 + }, + "end": { + "line": 18, + "column": 26 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -156,7 +184,7 @@ }, "end": { "line": 18, - "column": 21 + "column": 26 } } }, diff --git a/ets2panda/test/parser/ets/null-expected.txt b/ets2panda/test/parser/ets/null-expected.txt index f069f5a6a679ab99caee7be78a77b7c0c31c644c..d50eba3d377d41b280149d9eb78ea792ee31fcf3 100644 --- a/ets2panda/test/parser/ets/null-expected.txt +++ b/ets2panda/test/parser/ets/null-expected.txt @@ -431,13 +431,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, "loc": { "start": { "line": 18, @@ -445,21 +470,24 @@ }, "end": { "line": 18, - "column": 12 + "column": 14 } } }, - "loc": { - "start": { - "line": 18, - "column": 9 - }, - "end": { - "line": 18, - "column": 14 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 19 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -467,7 +495,7 @@ }, "end": { "line": 18, - "column": 14 + "column": 19 } } }, @@ -480,7 +508,7 @@ }, "end": { "line": 18, - "column": 14 + "column": 19 } } }, @@ -612,13 +640,38 @@ "type": "Identifier", "name": "arg", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, "loc": { "start": { "line": 21, @@ -626,21 +679,24 @@ }, "end": { "line": 21, - "column": 22 + "column": 24 } } }, - "loc": { - "start": { - "line": 21, - "column": 19 - }, - "end": { - "line": 21, - "column": 24 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 29 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -648,7 +704,7 @@ }, "end": { "line": 21, - "column": 24 + "column": 29 } } }, @@ -660,7 +716,7 @@ }, "end": { "line": 21, - "column": 24 + "column": 29 } } }, @@ -671,7 +727,7 @@ }, "end": { "line": 21, - "column": 24 + "column": 29 } } } @@ -982,13 +1038,38 @@ "type": "Identifier", "name": "e", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "cls", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "cls", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 13 + }, + "end": { + "line": 28, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 13 + }, + "end": { + "line": 28, + "column": 18 + } + } + }, "loc": { "start": { "line": 28, @@ -996,21 +1077,24 @@ }, "end": { "line": 28, - "column": 16 + "column": 18 } } }, - "loc": { - "start": { - "line": 28, - "column": 13 - }, - "end": { - "line": 28, - "column": 18 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 28, + "column": 19 + }, + "end": { + "line": 28, + "column": 23 + } } } - }, + ], "loc": { "start": { "line": 28, @@ -1018,7 +1102,7 @@ }, "end": { "line": 28, - "column": 18 + "column": 23 } } }, diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 4f1b9e0d7c17f93af2e7ac0148a1815268a6ec7c..808411842024f692a04644ab09c3f37ce9269308 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -336,4 +336,4 @@ } } } -TypeError: Type 'Object|null' cannot be assigned to type 'Object' [null_invalid.ets:17:18] +TypeError: Type 'null' cannot be assigned to type 'Object' [null_invalid.ets:17:18] diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index 1891cfc564194d2f8b9d7038adff79c3ca03b7e2..d5877df6bdce13dfc0985c1b80484ccca72ab4e5 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -248,13 +248,38 @@ "optional": false, "computed": false, "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "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 + } + } + }, "loc": { "start": { "line": 17, @@ -262,21 +287,24 @@ }, "end": { "line": 17, - "column": 15 + "column": 17 } } }, - "loc": { - "start": { - "line": 17, - "column": 9 - }, - "end": { - "line": 17, - "column": 17 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -284,7 +312,7 @@ }, "end": { "line": 17, - "column": 17 + "column": 22 } } }, @@ -297,7 +325,7 @@ }, "end": { "line": 17, - "column": 17 + "column": 22 } } } diff --git a/ets2panda/test/parser/ets/nullableGenericSignature-expected.txt b/ets2panda/test/parser/ets/nullableGenericSignature-expected.txt index d9bf80ff9764e30ecdfc1339b5bf7c4ed4650578..21336cf2e6d42e78f7bb4f287f2b587cce038a49 100644 --- a/ets2panda/test/parser/ets/nullableGenericSignature-expected.txt +++ b/ets2panda/test/parser/ets/nullableGenericSignature-expected.txt @@ -394,13 +394,38 @@ "type": "TSTypeParameterInstantiation", "params": [ { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Object", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 23 + } + } + }, "loc": { "start": { "line": 21, @@ -408,21 +433,24 @@ }, "end": { "line": 21, - "column": 21 + "column": 23 } } }, - "loc": { - "start": { - "line": 21, - "column": 15 - }, - "end": { - "line": 21, - "column": 23 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 21, + "column": 24 + }, + "end": { + "line": 21, + "column": 28 + } } } - }, + ], "loc": { "start": { "line": 21, @@ -430,7 +458,7 @@ }, "end": { "line": 21, - "column": 23 + "column": 28 } } } diff --git a/ets2panda/test/parser/ets/nullable_union_array-expected.txt b/ets2panda/test/parser/ets/nullable_union_array-expected.txt index 25904e3cab4eaca073da67d15d40ab32eeaaf027..b2df92232380d8374f8bb98ae134da9f345d2125 100644 --- a/ets2panda/test/parser/ets/nullable_union_array-expected.txt +++ b/ets2panda/test/parser/ets/nullable_union_array-expected.txt @@ -299,6 +299,19 @@ "column": 29 } } + }, + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 29 + }, + "end": { + "line": 17, + "column": 33 + } + } } ], "loc": { @@ -308,7 +321,7 @@ }, "end": { "line": 17, - "column": 29 + "column": 33 } } }, diff --git a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt index a48d7291b63b3dff98f8a8e48ad7e488a70721dd..208cd04bad513594ab974e3de854bdf3d65479a3 100644 --- a/ets2panda/test/parser/ets/optional_union_paramter-expected.txt +++ b/ets2panda/test/parser/ets/optional_union_paramter-expected.txt @@ -198,13 +198,38 @@ "type": "Identifier", "name": "limit", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 52 + }, + "end": { + "line": 17, + "column": 58 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 52 + }, + "end": { + "line": 17, + "column": 59 + } + } + }, "loc": { "start": { "line": 17, @@ -212,21 +237,24 @@ }, "end": { "line": 17, - "column": 58 + "column": 59 } } }, - "loc": { - "start": { - "line": 17, - "column": 52 - }, - "end": { - "line": 17, - "column": 59 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 17, + "column": 49 + }, + "end": { + "line": 17, + "column": 50 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -586,13 +614,38 @@ "type": "Identifier", "name": "limit", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Number", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Number", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -604,17 +657,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/override-expected.txt b/ets2panda/test/parser/ets/override-expected.txt index 6fb7ad94956e05676418c504a74d0d2e11e20b62..594b630333ec9beafb5e96ec24910ced97fe7964 100644 --- a/ets2panda/test/parser/ets/override-expected.txt +++ b/ets2panda/test/parser/ets/override-expected.txt @@ -185,13 +185,38 @@ "type": "Identifier", "name": "op", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, "loc": { "start": { "line": 17, @@ -199,21 +224,24 @@ }, "end": { "line": 17, - "column": 19 + "column": 20 } } }, - "loc": { - "start": { - "line": 17, - "column": 18 - }, - "end": { - "line": 17, - "column": 20 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 16 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -490,13 +518,38 @@ "type": "Identifier", "name": "op", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -508,17 +561,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, @@ -1381,13 +1437,38 @@ "type": "Identifier", "name": "op", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, "loc": { "start": { "line": 20, @@ -1395,21 +1476,24 @@ }, "end": { "line": 20, - "column": 28 + "column": 29 } } }, - "loc": { - "start": { - "line": 20, - "column": 27 - }, - "end": { - "line": 20, - "column": 29 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 20, + "column": 24 + }, + "end": { + "line": 20, + "column": 25 + } } } - }, + ], "loc": { "start": { "line": 20, @@ -1686,13 +1770,38 @@ "type": "Identifier", "name": "op", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "T", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -1704,17 +1813,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt b/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt index 20b3942afa9487ecff4c39d57e45c9aa7f783ef7..867322942b5b84d52cc66a4e0d2fce6b67d62e82 100644 --- a/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt +++ b/ets2panda/test/parser/ets/proxyVoidGeneration-expected.txt @@ -73,13 +73,38 @@ "type": "Identifier", "name": "log_", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Boolean", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, "loc": { "start": { "line": 17, @@ -87,21 +112,24 @@ }, "end": { "line": 17, - "column": 23 + "column": 24 } } }, - "loc": { - "start": { - "line": 17, - "column": 16 - }, - "end": { - "line": 17, - "column": 24 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 28 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -109,7 +137,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 28 } } }, @@ -121,7 +149,7 @@ }, "end": { "line": 17, - "column": 24 + "column": 28 } } }, @@ -280,13 +308,38 @@ "type": "Identifier", "name": "log_", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Boolean", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -298,17 +351,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSNullType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, @@ -811,13 +867,38 @@ "type": "Identifier", "name": "log_", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Boolean", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, "loc": { "start": { "line": 18, @@ -825,21 +906,24 @@ }, "end": { "line": 18, - "column": 26 + "column": 27 } } }, - "loc": { - "start": { - "line": 18, - "column": 19 - }, - "end": { - "line": 18, - "column": 27 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 18, + "column": 17 + } } } - }, + ], "loc": { "start": { "line": 18, @@ -1018,13 +1102,38 @@ "type": "Identifier", "name": "log_", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Boolean", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Boolean", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -1036,17 +1145,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/proxy_method-expected.txt b/ets2panda/test/parser/ets/proxy_method-expected.txt index fa34056abf11eca128cd876f4219a2863f103f53..c185f89cfcedda08576896534bb3805654825843 100644 --- a/ets2panda/test/parser/ets/proxy_method-expected.txt +++ b/ets2panda/test/parser/ets/proxy_method-expected.txt @@ -142,13 +142,38 @@ "type": "Identifier", "name": "q", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 31 + } + } + }, "loc": { "start": { "line": 17, @@ -156,21 +181,24 @@ }, "end": { "line": 17, - "column": 30 + "column": 31 } } }, - "loc": { - "start": { - "line": 17, - "column": 24 - }, - "end": { - "line": 17, - "column": 31 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 17, + "column": 21 + }, + "end": { + "line": 17, + "column": 22 + } } } - }, + ], "loc": { "start": { "line": 17, @@ -495,13 +523,38 @@ "type": "Identifier", "name": "q", "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "string", - "decorators": [], + "type": "ETSUnionType", + "types": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, "loc": { "start": { "line": 1, @@ -513,17 +566,20 @@ } } }, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 3 + { + "type": "ETSUndefinedType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } } } - }, + ], "loc": { "start": { "line": 1, diff --git a/ets2panda/test/parser/ets/test_type_alias5-expected.txt b/ets2panda/test/parser/ets/test_type_alias5-expected.txt index baa2505ed61aee127982ec98674abd5d11904a9c..f9c570fba76c90c719653b08745b67d5636c64cd 100644 --- a/ets2panda/test/parser/ets/test_type_alias5-expected.txt +++ b/ets2panda/test/parser/ets/test_type_alias5-expected.txt @@ -1 +1,194 @@ -SyntaxError: Invalid Type [test_type_alias5.ets:16:10] +{ + "type": "Program", + "statements": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "ETSNullType", + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 17, + "column": 1 + } + } +} diff --git a/ets2panda/test/runtime/ets/AccessBinaryTrees.ets b/ets2panda/test/runtime/ets/AccessBinaryTrees.ets index 85ae913c28b190b2884a7733613466b4b0da8567..dd230b01868022c1eece4966925fdf6ddea9a21c 100644 --- a/ets2panda/test/runtime/ets/AccessBinaryTrees.ets +++ b/ets2panda/test/runtime/ets/AccessBinaryTrees.ets @@ -28,7 +28,7 @@ class TreeNode { if (this.left == null) return this.item; else - return this.item + this.left.itemCheck() - this.right.itemCheck(); + return this.item + this.left!.itemCheck() - this.right!.itemCheck(); } } diff --git a/ets2panda/test/runtime/ets/DefaultParam_1.ets b/ets2panda/test/runtime/ets/DefaultParam_1.ets index 72368a9610877e34c916d6490be473bf4c892aca..2895c692b8f80005388729d0ddd8b8942dc6049a 100644 --- a/ets2panda/test/runtime/ets/DefaultParam_1.ets +++ b/ets2panda/test/runtime/ets/DefaultParam_1.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -function main():void{ +function main(): void { assert foo1() == 10; assert foo2() == c'a'; assert foo3() == true; @@ -22,67 +22,67 @@ function main():void{ assert foo4(5) == 25; assert foo5(5) == 55; - assert foo5(5,10) == 45; + assert foo5(5, 10) == 45; - assert foo6() == 0; - assert foo7() == false; - assert foo8() == c'\u0000'; + assert foo6() == undefined; + assert foo7() == undefined; + assert foo8() == undefined; assert foo13(10) == 15; assert foo14(10) == 25; - assert foo15(10,5) == 20; - assert foo16(10,5) == 30; + assert foo15(10, 5) == 20; + assert foo16(10, 5) == 30; } -function foo1(a : int = 10) : int { +function foo1(a: int = 10): int { return a; } -function foo2(a : char = c'a') : char { +function foo2(a: char = c'a'): char { return a; } -function foo3(a : boolean = true) : boolean { +function foo3(a: boolean = true): boolean { return a; } -function foo4(a : int = 10, b : int = 20) : int { +function foo4(a: int = 10, b: int = 20): int { return a + b; } -function foo5(a : int = 10, b : int = 20, c : int = 30) : int { +function foo5(a: int = 10, b: int = 20, c: int = 30): int { assert a == 5; return a + b + c; } -function foo6(a? : int) : int { +function foo6(a?: int): int | undefined { return a; } -function foo7(a? : boolean) : boolean { +function foo7(a?: boolean): boolean | undefined { return a; } -function foo8(a? : char) : char { +function foo8(a?: char): char | undefined { return a; } -function foo13(a : int, b : int = 5) : int { +function foo13(a: int, b: int = 5): int { return a + b; } -function foo14(a : int, b : int = 5, c : int = 10) : int { +function foo14(a: int, b: int = 5, c: int = 10): int { return a + b + c; } -function foo15(a : int, b : int, c : int = 5) : int { +function foo15(a: int, b: int, c: int = 5): int { return a + b + c; } -function foo16(a : int, b : int, c : int = 10, d : int = 5) : int { +function foo16(a: int, b: int, c: int = 10, d: int = 5): int { return a + b + c + d; } diff --git a/ets2panda/test/runtime/ets/DefaultParam_3.ets b/ets2panda/test/runtime/ets/DefaultParam_3.ets index 503935f305ebe4e809b6c5c72f729ac2621a9f27..2cb07ed5509bbc7e6490af564d769c164ce39aed 100644 --- a/ets2panda/test/runtime/ets/DefaultParam_3.ets +++ b/ets2panda/test/runtime/ets/DefaultParam_3.ets @@ -15,20 +15,20 @@ class MyType { x: int = 10; - constructor(){} - constructor(a:int){ + constructor() { } + constructor(a: int) { this.x = a; } } -function main():void{ +function main(): void { assert foo1() == 8; assert foo2() == 30; assert foo2(new MyType(5)) == 25; assert foo3(new MyType(5)) == 55; - assert foo3(new MyType(5),new MyType(10)) == 45; + assert foo3(new MyType(5), new MyType(10)) == 45; assert foo4() == 0; @@ -36,7 +36,7 @@ function main():void{ assert foo5(new MyType(5)) == -1; assert foo6(new MyType(5)) == 0; - assert foo6(new MyType(5),new MyType(10)) == -1; + assert foo6(new MyType(5), new MyType(10)) == -1; assert foo7() == 0; assert foo8() == 0; @@ -44,85 +44,85 @@ function main():void{ assert foo9(new MyType(10)) == 15; assert foo10(new MyType(10)) == 25; - assert foo11(new MyType(10),new MyType(5)) == 20; - assert foo12(new MyType(10),new MyType(5)) == 30; + assert foo11(new MyType(10), new MyType(5)) == 20; + assert foo12(new MyType(10), new MyType(5)) == 30; } -function foo1(a : MyType = new MyType(8)) : int { - if (a == null){ +function foo1(a: MyType = new MyType(8)): int { + if (a == null) { return -1; } return a.x; } -function foo2(a : MyType = new MyType(10), b : MyType = new MyType(20)) : int { +function foo2(a: MyType = new MyType(10), b: MyType = new MyType(20)): int { return a.x + b.x; } -function foo3(a : MyType = new MyType(10), b : MyType = new MyType(20), c : MyType = new MyType(30)) : int { +function foo3(a: MyType = new MyType(10), b: MyType = new MyType(20), c: MyType = new MyType(30)): int { assert a.x == 5; return a.x + b.x + c.x; } -function foo4(a? : MyType) : int { - if(a == null){ +function foo4(a?: MyType): int { + if (a == null) { return 0; } - return a.x; + return a!.x; } -function foo5(a? : MyType, b? : MyType) : int { - if(a == null && b == null){ +function foo5(a?: MyType, b?: MyType): int { + if (a == null && b == null) { return 0; } - if(b == null){ + if (b == null) { return -1; } - return a.x + b.x; + return a!.x + b!.x; } -function foo6(a? : MyType, b? : MyType, c? : MyType) : int { - assert a.x == 5; - if(b == null && c == null){ +function foo6(a?: MyType, b?: MyType, c?: MyType): int { + assert a!.x == 5; + if (b == null && c == null) { return 0; } - if(c == null){ + if (c == null) { return -1; } - return a.x + b.x + c.x; + return a!.x + b!.x + c!.x; } -function foo7(a : MyType = new MyType(5), b? : MyType) : int { - if(b == null){ +function foo7(a: MyType = new MyType(5), b?: MyType): int { + if (b == null) { return 0; } - return a.x + b.x; + return a.x + b!.x; } -function foo8(a? : MyType, b : MyType = new MyType(5), c? : MyType) : int { +function foo8(a?: MyType, b: MyType = new MyType(5), c?: MyType): int { assert b.x == 5; - if(a == null && c == null){ + if (a == null && c == null) { return 0; } - return a.x + b.x + c.x; + return a!.x + b.x + c!.x; } -function foo9(a : MyType, b : MyType = new MyType(5)) : int { +function foo9(a: MyType, b: MyType = new MyType(5)): int { return a.x + b.x; } -function foo10(a : MyType, b : MyType = new MyType(5), c : MyType = new MyType(10)) : int { +function foo10(a: MyType, b: MyType = new MyType(5), c: MyType = new MyType(10)): int { return a.x + b.x + c.x; } -function foo11(a : MyType, b : MyType, c : MyType = new MyType(5)) : int { +function foo11(a: MyType, b: MyType, c: MyType = new MyType(5)): int { return a.x + b.x + c.x; } -function foo12(a : MyType, b : MyType, c : MyType = new MyType(10), d : MyType = new MyType(5)) : int { +function foo12(a: MyType, b: MyType, c: MyType = new MyType(10), d: MyType = new MyType(5)): int { return a.x + b.x + c.x + d.x; } diff --git a/ets2panda/test/runtime/ets/NullLikeTypes.ets b/ets2panda/test/runtime/ets/NullLikeTypes.ets new file mode 100644 index 0000000000000000000000000000000000000000..48899a1120f0fb6cf47e74069279e0b31d91d15a --- /dev/null +++ b/ets2panda/test/runtime/ets/NullLikeTypes.ets @@ -0,0 +1,25 @@ +/* + * 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 fnull(): null { return null } +function fundefined(): undefined { return undefined } + +function main() { + let n: null = fnull(); + let u: undefined = fundefined(); + + assert(n as null | undefined == u as null | undefined); + assert(n as null | undefined !== u as null | undefined); +} diff --git a/ets2panda/test/runtime/ets/NullishComparison.ets b/ets2panda/test/runtime/ets/NullishComparison.ets index 11530a2a41c550a81b1da0a31628a522a0178170..d9bd5c8ae79e16a56cd16e63ba109d24640f8ae3 100644 --- a/ets2panda/test/runtime/ets/NullishComparison.ets +++ b/ets2panda/test/runtime/ets/NullishComparison.ets @@ -19,7 +19,7 @@ const vobject = ((): Object | null | undefined => { return new Object() })(); function main() { assert(null === null); - assert(null !== undefined); + // assert(null !== undefined); // not compatible assert(null !== vobject); assert(undefined === undefined); assert(undefined !== vobject); diff --git a/ets2panda/test/runtime/ets/NullishConditionals.ets b/ets2panda/test/runtime/ets/NullishConditionals.ets index cc54383e4fc2de4ec402a99632470b85455c89bf..6403d013a194164064acdf8873c70fc265550f16 100644 --- a/ets2panda/test/runtime/ets/NullishConditionals.ets +++ b/ets2panda/test/runtime/ets/NullishConditionals.ets @@ -18,9 +18,9 @@ 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(test_n({} as Object)); + assert(test_u({} as Object)); + assert(test_nu({} as Object)); assert(!null); if (null) { assert(false) } diff --git a/ets2panda/test/runtime/ets/OptionalChains.ets b/ets2panda/test/runtime/ets/OptionalChains.ets new file mode 100644 index 0000000000000000000000000000000000000000..038011af09f70dfcbf576c4a18e0d571b8533181 --- /dev/null +++ b/ets2panda/test/runtime/ets/OptionalChains.ets @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2024 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 assert_n(v: Object | null | undefined) { assert(v === null); } +function assert_u(v: Object | null | undefined) { assert(v === undefined); } +function assert_o(v: Object | null | undefined) { assert(v !== null && v !== undefined); } +function assert_npe(f: () => void) { + try { + f(); + } catch (e: NullPointerException) { + return; + } + assert("npe was not thrown"); +} + +class Link { + m(): Link { return this; } + f: Link = this; + a: Link[] = [(this)]; + c: () => Link = () => this + + om(): Link | null { return this.m() } + of: Link | null = this.f; + oa: Link[] | null = this.a; + oc: (() => Link) | null = this.c; + + nm(): Link | null { return null } + nf: Link | null = null; + na: Link[] | null = null; + nc: (() => Link) | null = null; + + static noevalFlag = true; + noeval(): Link { if (Link.noevalFlag) { throw new Error("never evaluated"); } return this; } +} + +function test1(l: Link | null, nl: Link | null) { + assert_o(l?.m()); + assert_o(l?.f); + assert_o(l?.a[0]); + assert_o(l?.c()); + assert_o(l?.of!.f); + + assert_u(nl?.m()); + assert_u(nl?.f); + assert_u(nl?.a[0]); + assert_u(nl?.c()); + assert_u(nl?.of!.f); + + nl?.m().noeval(); + nl?.f.noeval(); + nl?.a[0].noeval(); + nl?.c().noeval(); + nl?.of!.f.noeval(); + assert_npe(() => { nl?.of!.f! }); +} + +function test2(l: Link | null, nl: Link | null) { + assert_o(l?.m().f.a[0].c()); + assert_o(l?.f.m().c().a[0]); + assert_o(l?.a[0].c().f.m()); + assert_o(l?.c().m().a[0].f); + assert_o(l?.c().m().of!.a[0].oc!().f); + + assert_u(nl?.m().f.a[0].c()); + assert_u(nl?.f.m().c().a[0]); + assert_u(nl?.a[0].c().f.m()); + assert_u(nl?.c().m().a[0].f); + assert_u(nl?.c().m().of!.a[0].oc!().f); + + nl?.m().f.a[0].c().noeval(); + nl?.f.m().c().a[0].noeval(); + nl?.a[0].c().f.m().noeval(); + nl?.c().m().a[0].f.noeval(); + nl?.c().m().of!.a[0].oc!().f.noeval(); +} + +function test3(l: Link | null, nl: Link | null) { + assert_o(l?.om()?.of?.oa?.[0].oc?.()); + assert_o(l?.of?.om()?.oc?.().oa?.[0]); + assert_o(l?.oa?.[0]?.oc?.().of?.om()); + assert_o(l?.oc?.().om()?.oa?.[0].of); + assert_o(l?.oc?.().om()?.of!.oa?.[0].oc!().of); + + assert_u(nl?.om()?.of?.oa?.[0].oc?.()); + assert_u(nl?.of?.om()?.oc?.().oa?.[0]); + assert_u(nl?.oa?.[0]?.oc?.().of?.om()); + assert_u(nl?.oc?.().om()?.oa?.[0].of); + assert_u(nl?.oc!().om()?.of!.oa![0].oc!().of); + + nl?.om()?.of?.oa?.[0].oc?.().noeval(); + nl?.of?.om()?.oc?.().oa?.[0].noeval(); + nl?.oa?.[0]?.oc?.().of?.om()?.noeval(); + nl?.oc?.().om()?.oa?.[0].of?.noeval(); + nl?.oc?.().om()?.of!.oa?.[0].oc!().of?.noeval(); +} + +function test4(l: Link | null, nl: Link | null) { + assert_npe(() => { nl?.of! }); + nl?.of!.f; + assert_npe(() => { nl?.nf!.f }); +} + +function test5(l: Link | null, nl: Link | null) { + l?.f.a[0]?.f.c(); + nl?.f.a[0]?.f.c().noeval(); + assert_npe(() => { nl?.f.a[0]?.f.c()! }); + assert_npe(() => { (nl?.f?.a)?.[0].f! }); + assert_u(l?.f.a[0].nf?.a[0].noeval()?.m()); + + let u: Link | undefined = l?.f.oc?.().na?.[0].noeval().f?.oa?.[0]; +} + +function main() { + test1(new Link(), null) + test2(new Link(), null) + test3(new Link(), null) + test4(new Link(), null) + test5(new Link(), null) +} diff --git a/ets2panda/test/runtime/ets/UncheckedCasts.ets b/ets2panda/test/runtime/ets/UncheckedCasts.ets index f5852a44e0815ccdac0fb1467b62f368da52e039..d111019ffd4dd3aa005d23a37444ef628fa51ca8 100644 --- a/ets2panda/test/runtime/ets/UncheckedCasts.ets +++ b/ets2panda/test/runtime/ets/UncheckedCasts.ets @@ -13,66 +13,91 @@ * limitations under the License. */ -type Nullish = Object | null | undefined; - -class Bad { } -class X { } - -function expect_ccexc(fn: () => void) { +function assert_ccexc(f: () => void) { try { - fn(); - assert false; - } catch (e: Exception) { + f(); + assert false : "exception expected"; + } catch (e) { assert(e instanceof ClassCastException); } } -class G { - erase(x: Nullish): T { return x as T; } -} -function check_G_Object(x: Nullish) { - expect_ccexc(() => { new G().erase(x); }) -} -function check_G_X(x: Nullish) { - expect_ccexc(() => { new G().erase(x); }) -} +class A { } +class B { } +class C { } +class X { } + +function erase(x: Object | null | undefined): T { return x as T; } + function test_substitution() { - //check_G_Object(null); - //check_G_Object(undefined); - //check_G_X(null); - check_G_X(undefined); - check_G_X(new Object()); - check_G_X(new Bad()); + assert_ccexc(() => { erase(null); }) + assert_ccexc(() => { erase(undefined); }) + assert_ccexc(() => { erase(null); }) + assert_ccexc(() => { erase(undefined); }) + + assert_ccexc(() => { erase(null); }) + assert_ccexc(() => { erase(undefined); }) + assert_ccexc(() => { erase(null); }) + assert_ccexc(() => { erase(undefined); }) + + assert_ccexc(() => { erase(undefined); }) + assert_ccexc(() => { erase(new Object()); }) + assert_ccexc(() => { erase(new B()); }) + + assert_ccexc(() => { erase(undefined); }) + assert_ccexc(() => { erase(new Object()); }) + assert_ccexc(() => { erase(new C()); }) + + assert_ccexc(() => { erase(new B[0]); }) } -class CG { - pass(x: Nullish) { x as T; } +class Erased { + constructor(x: Object | null | undefined) { this.t = x as T; } + t: T; } -function check_CG_X(x: Nullish) { - expect_ccexc(() => { new CG().pass(x); }) + +function test_substitution_memberexpr() { + assert_ccexc(() => { new Erased(null).t; }) + assert_ccexc(() => { new Erased(undefined).t; }) + assert_ccexc(() => { new Erased(null).t; }) + assert_ccexc(() => { new Erased(undefined).t; }) + + assert_ccexc(() => { new Erased(null).t; }) + assert_ccexc(() => { new Erased(undefined).t; }) + assert_ccexc(() => { new Erased(null).t; }) + assert_ccexc(() => { new Erased(undefined).t; }) + + assert_ccexc(() => { new Erased(undefined).t; }) + assert_ccexc(() => { new Erased(new Object()).t; }) + assert_ccexc(() => { new Erased(new B()).t; }) + + assert_ccexc(() => { new Erased(undefined).t; }) + assert_ccexc(() => { new Erased(new Object()).t; }) + assert_ccexc(() => { new Erased(new C()).t; }) + + assert_ccexc(() => { new Erased(new B[0]).t; }) } + +function cast_to_tparam(x: Object | null | undefined) { x as T; } + function test_constraint() { - //check_CG_X(null); - check_CG_X(undefined); - check_CG_X(new Object()); - check_CG_X(new Bad()); + assert_ccexc(() => { cast_to_tparam(undefined); }) + assert_ccexc(() => { cast_to_tparam(new Object()); }) + assert_ccexc(() => { cast_to_tparam(new C()); }) } -class GG { - pass(x: Nullish) { x as G; } -} -function check_GG(x: Nullish) { - expect_ccexc(() => { new GG().pass(x); }) -} +function to_basetype(x: Object | null | undefined) { return x as X; } + function test_basetype() { - //check_GG(null); - check_GG(undefined); - check_GG(new Object()); + assert_ccexc(() => { to_basetype(null); }) + assert_ccexc(() => { to_basetype(undefined); }) + assert_ccexc(() => { to_basetype(new Object()); }) + assert_ccexc(() => { to_basetype(new C()); }) } function main() { - // NOTE(vpukhov): add nullability checks, add union param/constraint tests test_substitution(); + test_substitution_memberexpr(); test_constraint(); test_basetype(); } diff --git a/ets2panda/test/runtime/ets/UnionAsAndInstanceof.ets b/ets2panda/test/runtime/ets/UnionAsAndInstanceof.ets new file mode 100644 index 0000000000000000000000000000000000000000..462131b288168ac5d3ebc2412f24daebe1fecb59 --- /dev/null +++ b/ets2panda/test/runtime/ets/UnionAsAndInstanceof.ets @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2024 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 assert_ccexc(f: () => void) { + try { + f(); + assert false : "exception expected"; + } catch (e) { + assert(e instanceof ClassCastException); + } +} + +function assert_nothrow(f: () => void) { + try { + f(); + } catch (e) { + assert false : "unexpected exception"; + } +} + +class A { } +class B { } +class C { } + +function foo(x: Object | null | undefined) { return x as Object } + +function test_nullsafety() { + // Handling of Object may be a bit different, so test it separately + // let f = ... until inference in form ((p)=>expr)(a) is broken + assert_ccexc(() => { let f = ((x: Object | null | undefined) => x as Object); f(null); }); + assert_ccexc(() => { let f = ((x: Object | null | undefined) => x as Object); f(undefined); }); + assert_ccexc(() => { let f = ((x: Object | null) => x as Object); f(null); }); + assert_ccexc(() => { let f = ((x: Object | undefined) => x as Object); f(undefined); }); + + assert_ccexc(() => { let f = ((x: Object | null | undefined) => x as Object | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: Object | null | undefined) => x as Object | null); f(undefined); }); + assert_ccexc(() => { let f = ((x: Object | null) => x as Object | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: Object | undefined) => x as Object | null); f(undefined); }); + + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A); f(null); }); + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A); f(undefined); }); + assert_ccexc(() => { let f = ((x: A | null) => x as A); f(null); }); + assert_ccexc(() => { let f = ((x: A | undefined) => x as A); f(undefined); }); + + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A | null); f(undefined); }); + assert_ccexc(() => { let f = ((x: A | null) => x as A | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: A | undefined) => x as A | null); f(undefined); }); + + + assert_nothrow(() => { let f = ((x: Object | null | undefined) => x as Object); f(new Object()); }); + assert_nothrow(() => { let f = ((x: Object | null | undefined) => x as Object); f(new Object); }); + assert_nothrow(() => { let f = ((x: Object | null) => x as Object); f(new Object()); }); + assert_nothrow(() => { let f = ((x: Object | undefined) => x as Object); f(new Object()); }); + + assert_nothrow(() => { let f = ((x: Object | null | undefined) => x as Object | undefined); f(new Object()); }); + assert_nothrow(() => { let f = ((x: Object | null | undefined) => x as Object | null); f(new Object()); }); + assert_nothrow(() => { let f = ((x: Object | null) => x as Object | undefined); f(new Object()); }); + assert_nothrow(() => { let f = ((x: Object | undefined) => x as Object | null); f(new Object()); }); + + assert_nothrow(() => { let f = ((x: A | null | undefined) => x as A); f(new A()); }); + assert_nothrow(() => { let f = ((x: A | null | undefined) => x as A); f(new A()); }); + assert_nothrow(() => { let f = ((x: A | null) => x as A); f(new A()); }); + assert_nothrow(() => { let f = ((x: A | undefined) => x as A); f(new A()); }); + + assert_nothrow(() => { let f = ((x: A | null | undefined) => x as A | undefined); f(new A()); }); + assert_nothrow(() => { let f = ((x: A | null | undefined) => x as A | null); f(new A()); }); + assert_nothrow(() => { let f = ((x: A | null) => x as A | undefined); f(new A()); }); + assert_nothrow(() => { let f = ((x: A | undefined) => x as A | null); f(new A()); }); +} + +function test_unions() { + assert_ccexc(() => { let f = ((x: A | B | C) => x as A); f(new C()); }); + assert_ccexc(() => { let f = ((x: A | B | C) => x as A | B); f(new C()); }); + assert_ccexc(() => { let f = ((x: A | B | C | null) => x as A | B); f(null); }); + assert_ccexc(() => { let f = ((x: A | B | C | undefined) => x as A | B); f(undefined); }); + + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A | null); f(undefined); }); + assert_ccexc(() => { let f = ((x: A | null) => x as A | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: A | undefined) => x as A | null); f(undefined); }); + + assert_ccexc(() => { let f = ((x: A | B | C) => x as A); f(new C()); }); + assert_ccexc(() => { let f = ((x: A | B | C) => x as A | B); f(new C()); }); + assert_ccexc(() => { let f = ((x: A | B | C | null) => x as A | B); f(null); }); + assert_ccexc(() => { let f = ((x: A | B | C | undefined) => x as A | B); f(undefined); }); + + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: A | null | undefined) => x as A | null); f(undefined); }); + assert_ccexc(() => { let f = ((x: A | null) => x as A | undefined); f(null); }); + assert_ccexc(() => { let f = ((x: A | undefined) => x as A | null); f(undefined); }); +} + +function main() { + test_nullsafety(); + test_unions(); +} diff --git a/ets2panda/test/runtime/ets/conditionalExpressionLUB.ets b/ets2panda/test/runtime/ets/conditionalExpressionLUB.ets index 9301543e52a5e0a580a8707f47c5c4bf68d2f83e..d324325b9219e5c3dd63ab64e30c24dbdc982b51 100644 --- a/ets2panda/test/runtime/ets/conditionalExpressionLUB.ets +++ b/ets2panda/test/runtime/ets/conditionalExpressionLUB.ets @@ -45,6 +45,11 @@ function foo(p: F): int { return 6; } +// #15276 foo(Object|null) and foo(Object) overloads +function foo7(p: Object | null): int { + return 7; +} + function main(): void { sameTypeLUB(); objectLUB(); @@ -54,30 +59,30 @@ function main(): void { function sameTypeLUB(): void { let a : A = new A(); let b : A = new A(); - let c = true ? a : b; // A + let c = true ? a : b; assert(foo(c) == 2); } function objectLUB(): void { let a : A = new A(); let b : Int = 2; - let c = true ? a : b; // A | Int + let c = true ? a : b; assert(foo(c) == 1); let arr : Int[] | null = null; - let d = true ? a : arr; // A | Int[] | null - assert(foo(d) == 1); + let d = true ? a : arr; + assert(foo7(d) == 7); } function forkSubtypeLUB(): void { let a : F = new F(); let b : D = new D(); - let c = true ? a : b; // F | D => call most specific foo(A) + let c = true ? a : b; assert(foo(c) == 2); let d : A = new A(); - let e = true ? a : d; // F | A => normalize to A + let e = true ? a : b; assert(foo(e) == 2); let f : B = new B(); - let g = true ? a : f; // F | B => normalize to B + let g = true ? a : f; assert(foo(g) == 3); } diff --git a/ets2panda/test/runtime/ets/conversion-char-boolean.ets b/ets2panda/test/runtime/ets/conversion-char-boolean.ets index 76f9ea8e29cc817dac783009e3bda81123d9b699..2b8d23bc6885254a8d991ef612f7438ed9668492 100644 --- a/ets2panda/test/runtime/ets/conversion-char-boolean.ets +++ b/ets2panda/test/runtime/ets/conversion-char-boolean.ets @@ -20,7 +20,7 @@ function check(): Boolean { function main(): void { let x: Boolean = false; - assert (x || check()); + assert (!x || check()); let y: Char = c'a'; assert (y != c'b'); diff --git a/ets2panda/test/runtime/ets/lambda-class-field.ets b/ets2panda/test/runtime/ets/lambda-class-field.ets index 2bca2ab41562fb323d843d96c7a5cb0300f0f473..70fb63ce89417c4f3c892ddc5d24928bd9f7c641 100644 --- a/ets2panda/test/runtime/ets/lambda-class-field.ets +++ b/ets2panda/test/runtime/ets/lambda-class-field.ets @@ -20,7 +20,7 @@ class cls { function main(): void { let c = new cls(); - c.lambda_field = () => 42; - assert c.lambda_field() == 42; + c.lambda_field = (() => new Int(42)) as () => Int; // #15577 + assert c.lambda_field!() == 42; assert c.num == 0; } diff --git a/ets2panda/test/runtime/ets/member-expression-nullptr.ets b/ets2panda/test/runtime/ets/member-expression-nullptr.ets deleted file mode 100644 index 890c7c2290e513a1b0c78c1a879de295ea5156b7..0000000000000000000000000000000000000000 --- a/ets2panda/test/runtime/ets/member-expression-nullptr.ets +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -let a = 0; - -function foo(): int { - a++; - return 1; -} - -function bar(): int { - a++; - return 2; -} - -class Residence { - numberOfRooms: int = 1; -} - -class Person { - residence: Residence = new Residence(); -} - -function main(): void { - a = 0; - let test = false; - let john: Person | null = null; - - try { - let residence = john.residence; - } catch (e: NullPointerException) { - test = true; - } - assert(test == true); - - test = false; - assert(test == false); - - try { - let numbers: int = john.residence.numberOfRooms; - } catch (e: NullPointerException) { - test = true; - } - assert(test == true); - - test = false; - assert(test == false); - try { - let numbers: int = foo() + bar() + john.residence.numberOfRooms; - } catch (e: NullPointerException) { - test = true; - } - assert(test == true); - assert(a == 2); // foo and bar were evaluated - - john = new Person(); - - let numbers: int = john.residence.numberOfRooms; - assert(numbers == 1); - - numbers = foo() + bar() + john.residence.numberOfRooms; - assert(numbers == 4); -} diff --git a/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets b/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a129195b9b2ca0af8ac45ccc00613d2d85ecf7d --- /dev/null +++ b/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main(): void { + let A: Array = new Array(); + let a: Number[][][]; + + let catched = false; + try { + a = new Number[A.length + 2.][4][A.length + 3.00001]; + } catch (e: TypeError) { + catched = true; + } + + assert catched +} diff --git a/ets2panda/test/runtime/ets/multi-array-new-catched-2.ets b/ets2panda/test/runtime/ets/multi-array-new-catched-2.ets new file mode 100644 index 0000000000000000000000000000000000000000..eefeb31395e1ff1ffbb1d8ca173bf534041033cb --- /dev/null +++ b/ets2panda/test/runtime/ets/multi-array-new-catched-2.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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 baz(): number { + return 5.1 +} + +function main(): void { + let A: Array = new Array(); + let a: Number[][][]; + + let catched = false; + try { + a = new Number[baz()][4][A.length + 3.0000]; + } catch (e: TypeError) { + catched = true; + } + + assert catched +} diff --git a/ets2panda/test/runtime/ets/multi-array-new.ets b/ets2panda/test/runtime/ets/multi-array-new.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe46e6e25da602585af97b405ebc53b36095104e --- /dev/null +++ b/ets2panda/test/runtime/ets/multi-array-new.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function main(): void { + let A: Array = new Array(); + let a: Number[][][]; + + a = new Number[A.length + 2.][4.00][A.length + 3.0000]; + + assert a.length == 2 + assert a[1].length == 4 + assert a[0][3].length == 3 +} diff --git a/ets2panda/test/runtime/ets/nullishTypeCodesamples.ets b/ets2panda/test/runtime/ets/nullishTypeCodesamples.ets new file mode 100644 index 0000000000000000000000000000000000000000..f056ee2e984ba7d1b5fd00f151925e0bdc77b15e --- /dev/null +++ b/ets2panda/test/runtime/ets/nullishTypeCodesamples.ets @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A { + readonly indices: number[][] | null; + constructor() { + this.indices = new number[2][2]; + } + + public override equals(other: Object | null | undefined): boolean { + for (let i = 0; i < this.indices!.length; ++i) { + let num: number[] = this.indices![i]; + num[0]; + } + return false; + } +} + +function foo1(value: number, opt?: string) { + return "" + value + opt; +} +function foo2(value: number, opt: string | undefined = undefined) { + return "" + value + opt; +} +function testfoo() { + assert(foo1(12 as number) == "12undefined"); // inference blocked + assert(foo1(12, "s") == "12s"); + assert(foo1(12, undefined) == "12undefined"); + + assert(foo2(12 as number) == "12undefined"); // inference blocked + assert(foo2(12, "s") == "12s"); + assert(foo2(12, undefined) == "12undefined"); +} + +class DNode { + readonly parent: DNode | undefined = undefined; +} + +class DTree { + private current: DNode = new DNode(); + up() { + let parent = this.current.parent + this.current = parent! + } +} + +class B { + public b: boolean = true; +}; +function testb(): void { + let b: B | undefined = new B(); + if (b?.b == false) { + b!.b = true; + } +} + +class Test { + n: number | undefined = undefined; +} + +type int32 = int; +function testf(a: int32 | undefined): int32 { + let x: int32 | null = null; + return a! + x!; +} + +function testcond() { + let _a: null | undefined = null, options_x: null | undefined = null; + return (_a = options_x) !== null && _a !== undefined ? _a : 1; +} + +type float32 = float; +function foo(param?: float32) { } + +export class Matrix33 { + constructor() { this.arr = new Float32Array(8) } + constructor(arr: Float32Array) { this.arr = arr } + private arr: Float32Array | null = null; + + static rotate(degrees: float32, pivotX?: float32, pivotY?: float32): Matrix33 { + let rads = degrees * Math.PI / 180 + let cos = Math.cos(rads) + let sin = Math.sin(rads) + let newarr = new Float32Array(8) + newarr.set([cos, -sin, 0, cos, 0, 0, 0, 1]); + return new Matrix33(newarr); + } +} + +function main() { + new A().equals(null); + testfoo(); + try { + new DTree().up(); + assert(false); + } catch (e: NullPointerException) { } + testb(); + try { + testf(123); + assert(false); + } catch (e: NullPointerException) { } + assert((testcond() instanceof Int) && (testcond() == 1)); + + foo(123); + foo(undefined); + new Matrix33().rotate(1, 2, 3) +} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/opt-chaining.ets b/ets2panda/test/runtime/ets/opt-chaining.ets index 5b4160d21a1fa7d87b62614d86b427f5f03768ed..659e2966cd362ff590b5f4dc538518c5946c10a2 100644 --- a/ets2panda/test/runtime/ets/opt-chaining.ets +++ b/ets2panda/test/runtime/ets/opt-chaining.ets @@ -27,14 +27,4 @@ function main(): void { assert (test == null); let nullsafety_test = john?.residence?.numberOfRooms ?? "unknown"; assert (nullsafety_test == "unknown"); - - let isNull: boolean = false; - - try { - let numbers : int = john.residence.numberOfRooms; - } catch (e: NullPointerException) { - isNull = true; - } - - assert (isNull == true); } diff --git a/ets2panda/test/runtime/ets/optional-chaining-function-call.ets b/ets2panda/test/runtime/ets/optional-chaining-function-call.ets index cd71c78f767067c207079779fbaa7660beb63977..401bcafd016c116d62940c643fab650f8eda61da 100644 --- a/ets2panda/test/runtime/ets/optional-chaining-function-call.ets +++ b/ets2panda/test/runtime/ets/optional-chaining-function-call.ets @@ -15,12 +15,12 @@ type funcType = () => String; -function getPeach(): String { return "peach" } function getMelon(): String { return "melon" } function foo(a: funcType | null) { let fruit: String = a?.() ?? "apple"; + let getPeach: funcType | null = (() => { return "peach"; }) as funcType // #15577; fruit = getPeach?.() ?? "banana"; assert(fruit == "peach"); @@ -29,7 +29,7 @@ function foo(a: funcType | null) { let test = false; try { - fruit = a(); + fruit = a!(); } catch (e: NullPointerException) { test = true; } @@ -38,13 +38,10 @@ function foo(a: funcType | null) { } function main(): void { - let getFruit: funcType | null = null; - foo(getFruit); + let getFruit: funcType | null = null; + foo(getFruit); - let a : funcType = getPeach; - let b = getPeach?.(); - assert(b == "peach"); - - b = getMelon(); - assert(b == "melon"); + let getPeach: funcType | null = (() => { return "peach" }) as funcType // #15577; + let b = getPeach?.(); + assert(b == "peach"); } diff --git a/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets b/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets index e3d5ceed7569609b402da1daa61cb4b61e7990b8..a50679c9f3b63d086da55af2e22341ad132b516a 100644 --- a/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets +++ b/ets2panda/test/runtime/ets/optional-chaining-lazy-evaluation.ets @@ -21,7 +21,8 @@ function main(): void { assert(number == 2); assert(x == 0); // 0 as x was not incremented - let obj: Int[] | null = [11, 21, 31]; + let obj_tmp: Int[] = [11, 21, 31]; + let obj: Int[] | null = obj_tmp; number = obj?.[x++]; let a : Int = 11; diff --git a/ets2panda/test/runtime/ets/optional-chaining-string-check.ets b/ets2panda/test/runtime/ets/optional-chaining-string-check.ets index 3f5de24870316cbe4e752aadb22e709b174fed34..4ab1349c1ee513f6cd3d583f7f5f21c09a35d5e8 100644 --- a/ets2panda/test/runtime/ets/optional-chaining-string-check.ets +++ b/ets2panda/test/runtime/ets/optional-chaining-string-check.ets @@ -19,7 +19,7 @@ class Person { function main(): void { let bill : Person = new Person(); - let name = bill?.name; + let name = bill.name; assert(name == "Bill"); assert(name.length == 4); @@ -33,10 +33,5 @@ function main(): void { let test = false; - try { - name = juan.name; - } catch (e: NullPointerException) { - test = true; - } - assert(test = true); + assert(juan?.name === undefined); } diff --git a/ets2panda/test/runtime/ets/tuple_types_runtime.ets b/ets2panda/test/runtime/ets/tuple_types_runtime.ets index 046ad690bbe8e15bb533655b49d1bc3a03c012b1..259109807de8062ae0c0d8cf2984827019e2a5bc 100644 --- a/ets2panda/test/runtime/ets/tuple_types_runtime.ets +++ b/ets2panda/test/runtime/ets/tuple_types_runtime.ets @@ -98,16 +98,16 @@ function main(): void { assert(tup_8[1][0] == 2 && tup_8[1][1] == "F"); assert(tup_8[2][0] == 3 && tup_8[2][1] == "G"); - let tup_10: [number, int, string, boolean, Object] = [1, 2, "I", false, new Object()]; - let var_float: float = tup_10[1]; - let var_float_2: float = 2.0; - assert(var_float == var_float_2); - - let tup_11: [int, number, string, boolean, Object] = [6, 7, "J", true, 789]; + // #15570 - test ArrayExpr assignability with individual element types + // let tup_10: [number, int, string, boolean, Object] = [1, 2, "I", false, new Object()]; + // let var_float: float = tup_10[1]; + // let var_float_2: float = 2.0; + // assert(var_float == var_float_2); + // let tup_11: [int, number, string, boolean, Object] = [6, 7, "J", true, 789]; // NOTE: Bug in op_assignment lowering (removes const from property) // tup_11[0] += new Short(2 as short); // assert(tup_11[0] == 8); - assert(tup_11[4] == (789 as Object)); + // assert(tup_11[4] == (789 as Object)); let tup_12: [number, ...number[]] = [1, 2, 3, 4]; try { diff --git a/ets2panda/test/runtime/ets/type_param_in_union.ets b/ets2panda/test/runtime/ets/type_param_in_union.ets new file mode 100644 index 0000000000000000000000000000000000000000..532d12e5dd7d05a0ec9043873b4b579e1c6ebe87 --- /dev/null +++ b/ets2panda/test/runtime/ets/type_param_in_union.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 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. + */ + +// #15380 + +// interface PromiseLike { +// then(onFulfilled: (value: T) => U, onRejected: (error: Object | null) => V): PromiseLike; +// } + +// class TestP implements PromiseLike { +// then(onFulfilled: (value: T) => U, onRejected: (error: Object | null) => V): TestP { +// return new TestP(); +// } +// } + +// function testp() { +// let cb1: (v: number | Array) => Number = (v) => 1; +// let cb2: (v: Object | null) => Error = (v) => new Error(); +// let p: PromiseLike> = new TestP>(); +// p.then(cb1, cb2); +// } + +function foo(val: T | (() => T)) { + return true +} + +class X { + method(...items: (T | X)[]): X { + return new X(); + } +} + +export class PromiseFulfilledResult { + status: string; + value: T; +} + +export class PromiseRejectedResult { + status: string; + reason: Object; +} + +type PromiseSettledResult = PromiseFulfilledResult | PromiseRejectedResult; + +function functionOverValue(value: Value | (() => Value)): boolean { + return Type.of(value) instanceof FunctionType +} + +function main() { + foo(123); + // foo(()=>123); // union inference #15577 + + let x = new X(); + x.method(x, 123, x.method(321)); + + let res: PromiseSettledResult = new PromiseFulfilledResult(); + + assert(!functionOverValue(123)); + assert(functionOverValue((() => 123) as () => number)); +} diff --git a/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets b/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets index 7fb437eeda604faf3dfea8614bab86f2a935cf2c..8a865706f58f9213c2b361f4d287947563dee922 100644 --- a/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets +++ b/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets @@ -23,8 +23,9 @@ function returnRefBool(a: boolean): Boolean { function main(): void { let a: Boolean = false; + let a2: Boolean = true - let b: Boolean = a && returnTrue(); + let b: Boolean = a || a2; assert b == true let c: Boolean = returnRefBool(a || returnRefBool(returnRefBool(a))); diff --git a/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt b/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt index e8521c7c0b4ab6db263b0c1cd4a4363e32f60403..c12cc9299c3a9aabffb9ddaff8c9db202086395b 100644 --- a/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt +++ b/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt @@ -47,3 +47,12 @@ struct-init.ets struct-init2.ets struct_implements.ets top_level_03.ets + +# Union with undefined +OptionalCall.ets + +# Functional type with rest parameter +lambdaExpressionWithRestParameter.ets + +# Non-trivial cast sequence +castSequence.ets diff --git a/ets2panda/test/test-lists/parser/parser-ets-ignored.txt b/ets2panda/test/test-lists/parser/parser-ets-ignored.txt index de27323be467022892a7ff1d56c6205e070690fa..803f9a2c5e09b17577ef15e31ae739395148efe6 100644 --- a/ets2panda/test/test-lists/parser/parser-ets-ignored.txt +++ b/ets2panda/test/test-lists/parser/parser-ets-ignored.txt @@ -11,3 +11,17 @@ parser/ets/import_tests/modules/struct_module.ets parser/ets/import_tests/check_exported_default_struct.ets parser/ets/import_tests/modules/struct_default_module.ets parser/ets/import_tests/check_exported_struct.ets + +# Throwing function types are not yet supported +parser/ets/lambdaThrowsRethrows.ets +parser/ets/variable_throw_function_1.ets +compiler/ets/rethrowingCheck5.ets +compiler/ets/rethrowingConstructorCheck1.ets +compiler/ets/rethrowingConstructorCheck2.ets +compiler/ets/rethrowingConstructorCheck3.ets +compiler/ets/rethrowingFunctionCheck1.ets +compiler/ets/rethrowingFunctionCheck2.ets +compiler/ets/rethrowingFunctionCheck3.ets +compiler/ets/rethrowingMethodCheck1.ets +compiler/ets/rethrowingMethodCheck2.ets +compiler/ets/rethrowingMethodCheck3.ets diff --git a/ets2panda/test/test-lists/parser/parser-js-ignored.txt b/ets2panda/test/test-lists/parser/parser-js-ignored.txt index a0cac35d0e8d349ebf833c8793d6cfe4aae7a44a..f43d7fb014d6546bbc9be8a128abdf6850ea5bba 100644 --- a/ets2panda/test/test-lists/parser/parser-js-ignored.txt +++ b/ets2panda/test/test-lists/parser/parser-js-ignored.txt @@ -71,10 +71,31 @@ parser/ets/trailing_lambda_tests/trailing_lambda_define_lambda_in_body_capture_v compiler/ets/override13.ets # 15095 -compiler/ets/methodOverrideCovariantReturnType.ets -compiler/ets/override16.ets compiler/ets/override17.ets parser/ets/static_function_hide_2.ets -# 14595 -compiler/ets/n_assignGenericWithNullableTypeParamToNonNullable.ets +# Throwing function types +compiler/ets/throwingFunctionType2.ets +compiler/ets/throwingFunctionAsParameter2.ets + +# 15276 +parser/ets/n_overrideWithNullable.ets +parser/ets/nullableType.ets + +# 15577 inference for union-typed targets +compiler/ets/optionalLambdaParameter.ets +compiler/ets/tuple_types_12.ets +compiler/ets/tuple_types_7.ets +compiler/ets/tuple_types_9_neg.ets +parser/ets/tuple_type_1.ets + +# 15642 broken ast varbinder scopes in etsglobal +parser/ets/optional-chaining-array.ets +parser/ets/optional_chaining_invalid_property.ets +parser/ets/optional_chaining_nested_property.ets +parser/ets/optional_chaining_object_property.ets + +# 15642 +compiler/ets/etsObjectToString4.ets +compiler/ets/etsObjectToString5.ets +compiler/ets/generic_variance_1.ets diff --git a/ets2panda/test/unit/node_creator.h b/ets2panda/test/unit/node_creator.h index f345b56f2873b08a099d0d26400339232fab104b..4a054bcb10917116f0c357fdf07288e220b9962c 100644 --- a/ets2panda/test/unit/node_creator.h +++ b/ets2panda/test/unit/node_creator.h @@ -65,7 +65,9 @@ public: auto varDecl = CreateVarDecl(true, name); ArenaVector tmp {alloc_->Adapter()}; tmp.emplace_back(varDecl); - return alloc_->New(alloc_, std::move(tmp)); + auto *newBlock = alloc_->New(alloc_, std::move(tmp)); + varDecl->SetParent(newBlock); + return newBlock; } ir::ForUpdateStatement *CreateForUpdate() @@ -82,4 +84,4 @@ public: private: ArenaAllocator *const alloc_; }; -} // namespace panda::es2panda::gtests \ No newline at end of file +} // namespace panda::es2panda::gtests diff --git a/ets2panda/test/unit/union_normalization_test.cpp b/ets2panda/test/unit/union_normalization_test.cpp index 0c680764b0ac1f60f2f4b86e11747bb81e8fea9b..465b5823e8daac58ecc652c76390553d875a751c 100644 --- a/ets2panda/test/unit/union_normalization_test.cpp +++ b/ets2panda/test/unit/union_normalization_test.cpp @@ -220,7 +220,7 @@ TEST_F(UnionNormalizationTest, UnionWithIdenticalTypes1) ASSERT_EQ(unionType->ConstituentTypes().at(IDX2), checker.GlobalBuiltinETSStringType()); } -TEST_F(UnionNormalizationTest, UnionWithIdenticalTypes2) +TEST_F(UnionNormalizationTest, DISABLED_UnionWithIdenticalTypes2) { // Test normalization: Base | int | Base | double | short | number ==> Base | number // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -250,7 +250,7 @@ TEST_F(UnionNormalizationTest, UnionWithIdenticalTypes2) ASSERT_EQ(unionType->ConstituentTypes().at(IDX1), checker.GetGlobalTypesHolder()->GlobalDoubleBuiltinType()); } -TEST_F(UnionNormalizationTest, UnionWithNumeric1) +TEST_F(UnionNormalizationTest, DISABLED_UnionWithNumeric1) { // Test normalization: boolean | int | double | short ==> boolean | double // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -275,7 +275,7 @@ TEST_F(UnionNormalizationTest, UnionWithNumeric1) ASSERT_EQ(unionType->ConstituentTypes().at(IDX1), checker.GetGlobalTypesHolder()->GlobalDoubleBuiltinType()); } -TEST_F(UnionNormalizationTest, UnionWithNumeric2) +TEST_F(UnionNormalizationTest, DISABLED_UnionWithNumeric2) { // Test normalization: string | int | Base | double | short ==> string | Base | double // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -375,7 +375,7 @@ TEST_F(UnionNormalizationTest, UnionWithSubTypes) ASSERT_EQ(normalizedType4, baseType); } -TEST_F(UnionNormalizationTest, UnionLinearization) +TEST_F(UnionNormalizationTest, DISABLED_UnionLinearization) { // Test 3 cases of normalization // NOLINTNEXTLINE(modernize-avoid-c-arrays) @@ -481,7 +481,7 @@ TEST_F(UnionNormalizationTest, UnionStringLiterals) ASSERT_EQ(unionType->ConstituentTypes().at(IDX1), checker.GlobalBuiltinETSStringType()); } -TEST_F(UnionNormalizationTest, UnionWithNever) +TEST_F(UnionNormalizationTest, DISABLED_UnionWithNever) { // Test normalization: int | never | number ==> number // NOLINTNEXTLINE(modernize-avoid-c-arrays) diff --git a/ets2panda/util/declgenEts2Ts.cpp b/ets2panda/util/declgenEts2Ts.cpp index 89cb7e1e34359a11593b62fd4faaffeec4f988e0..f16a5a70c77bc63524886753cb5da81754448776 100644 --- a/ets2panda/util/declgenEts2Ts.cpp +++ b/ets2panda/util/declgenEts2Ts.cpp @@ -116,69 +116,59 @@ std::string TSDeclGen::GetKeyName(const ir::Expression *key) return key->AsIdentifier()->Name().Mutf8(); } -void TSDeclGen::GenType(const checker::Type *checkerType) +static char const *GetDebugTypeName(const checker::Type *checkerType) { - // NOTE: vpukhov. rewrite when nullish type is implemented with union - GenTypeNonNullish(checkerType); - if (checkerType->IsNullish()) { - if (checkerType->ContainsNull()) { - Out(" | null"); - } - if (checkerType->ContainsUndefined()) { - Out(" | undefined"); - } +#define TYPE_CHECKS(type_flag, typeName) \ + if (checkerType->Is##typeName()) { \ + return #typeName; \ } + TYPE_MAPPING(TYPE_CHECKS) +#undef TYPE_CHECKS + return "unknown type"; } -void TSDeclGen::GenTypeNonNullish(const checker::Type *checkerType) +void TSDeclGen::GenType(const checker::Type *checkerType) { - ASSERT(checkerType != nullptr); DebugPrint(" GenType: "); #if DEBUG_PRINT -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define TYPE_CHECKS(type_flag, typeName) \ - if (checkerType->Is##typeName()) { \ - const auto var_name = checkerType->Variable() == nullptr ? "" : checkerType->Variable()->Name().Mutf8(); \ - DebugPrint(" Converting type: " #typeName " (" + var_name + ")"); \ - } - TYPE_MAPPING(TYPE_CHECKS) -#undef TYPE_CHECKS + const auto var_name = checkerType->Variable() == nullptr ? "" : checkerType->Variable()->Name().Mutf8(); + DebugPrint(std::string(" Converting type: ") + GetDebugTypeName(checkerType) + " (" + var_name + ")"); #endif - if (checkerType->IsCharType() || checkerType->IsByteType() || checkerType->IsIntType() || - checkerType->IsShortType() || checkerType->IsNumberType() || checkerType->IsLongType() || - checkerType->IsFloatType() || checkerType->IsDoubleType()) { + if (checkerType->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { Out("number"); - } else if (checkerType->IsETSBooleanType()) { - Out("boolean"); - } else if (checkerType->IsETSVoidType()) { - Out("void"); - } else if (checkerType->IsETSStringType()) { - Out("string"); - } else if (checkerType->IsETSArrayType()) { - GenType(checkerType->AsETSArrayType()->ElementType()); - Out("[]"); - } else if (checkerType->IsETSEnumType()) { - GenEnumType(checkerType->AsETSEnumType()); - } else if (checkerType->IsETSFunctionType()) { + return; + } + if (checkerType->HasTypeFlag(checker::TypeFlag::FUNCTION)) { GenFunctionType(checkerType->AsETSFunctionType()); - } else if (checkerType->IsETSObjectType()) { - if (checker_->IsTypeBuiltinType(checkerType)) { - Out("number"); - return; - } - GenObjectType(checkerType->AsETSObjectType()); - } else if (checkerType->IsETSTypeParameter()) { - GenTypeParameterType(checkerType->AsETSTypeParameter()); - } else { -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define TYPE_CHECKS(typeFlag, typeName) \ - if (checkerType->Is##typeName()) { \ - ThrowError("Unsupported type: '" #typeName); \ + return; } - TYPE_MAPPING(TYPE_CHECKS) -#undef TYPE_CHECKS - UNREACHABLE(); + + switch (checker::ETSChecker::ETSType(checkerType)) { + case checker::TypeFlag::ETS_VOID: + case checker::TypeFlag::ETS_NULL: + case checker::TypeFlag::ETS_UNDEFINED: + case checker::TypeFlag::ETS_BOOLEAN: + case checker::TypeFlag::ETS_TYPE_PARAMETER: + case checker::TypeFlag::ETS_NONNULLISH: + Out(checkerType->ToString()); + return; + case checker::TypeFlag::ETS_ENUM: + GenEnumType(checkerType->AsETSEnumType()); + return; + case checker::TypeFlag::ETS_OBJECT: + case checker::TypeFlag::ETS_DYNAMIC_TYPE: + GenObjectType(checkerType->AsETSObjectType()); + return; + case checker::TypeFlag::ETS_ARRAY: + GenType(checkerType->AsETSArrayType()->ElementType()); + Out("[]"); + return; + case checker::TypeFlag::ETS_UNION: + GenUnionType(checkerType->AsETSUnionType()); + return; + default: + ThrowError(std::string("Unsupported type: '") + GetDebugTypeName(checkerType)); } } @@ -229,7 +219,7 @@ void TSDeclGen::GenFunctionType(const checker::ETSFunctionType *etsFunctionType, Out(param->Name()); const auto *paramType = param->TsType(); - if (param->HasFlag(varbinder::VariableFlags::OPTIONAL) || paramType->IsNullish()) { + if (param->HasFlag(varbinder::VariableFlags::OPTIONAL)) { Out("?"); } @@ -292,15 +282,33 @@ void TSDeclGen::GenEnumType(const checker::ETSEnumType *enumType) } } +void TSDeclGen::GenUnionType(const checker::ETSUnionType *unionType) +{ + for (auto *ctype : unionType->ConstituentTypes()) { + GenType(ctype); + if (ctype != unionType->ConstituentTypes().back()) { + Out(" | "); + } + } +} + void TSDeclGen::GenObjectType(const checker::ETSObjectType *objectType) { + if (objectType->IsETSStringType()) { + Out("string"); + return; + } + if (objectType->HasObjectFlag(checker::ETSObjectFlags::UNBOXABLE_TYPE)) { + Out("number"); // NOTE(ivagin): create precise builtin type + return; + } if (objectType->HasObjectFlag(checker::ETSObjectFlags::FUNCTIONAL)) { - const auto *invoke = objectType->GetOwnProperty("invoke"); + const auto *invoke = objectType->GetOwnProperty( + checker::FUNCTIONAL_INTERFACE_INVOKE_METHOD_NAME); ASSERT(invoke && invoke->TsType() && invoke->TsType()->IsETSFunctionType()); GenType(invoke->TsType()); return; } - if (objectType->HasObjectFlag(checker::ETSObjectFlags::DYNAMIC)) { Out("any"); return; @@ -322,11 +330,6 @@ void TSDeclGen::GenObjectType(const checker::ETSObjectType *objectType) } } -void TSDeclGen::GenTypeParameterType(const checker::ETSTypeParameter *typeParam) -{ - Out(typeParam->GetDeclNode()->Name()->Name()); -} - void TSDeclGen::GenTypeParameters(const ir::TSTypeParameterDeclaration *typeParams) { if (typeParams != nullptr) { diff --git a/ets2panda/util/declgenEts2Ts.h b/ets2panda/util/declgenEts2Ts.h index f6b1fdee767100b4c97eb34ffb6a10a0e90ae82a..21d3b354a23a7978863cb8994933db1d1b4af8f7 100644 --- a/ets2panda/util/declgenEts2Ts.h +++ b/ets2panda/util/declgenEts2Ts.h @@ -47,11 +47,10 @@ private: std::string GetKeyName(const ir::Expression *key); void GenType(const checker::Type *checkerType); - void GenTypeNonNullish(const checker::Type *checkerType); void GenFunctionType(const checker::ETSFunctionType *functionType, const ir::MethodDefinition *methodDef = nullptr); - void GenTypeParameterType(const checker::ETSTypeParameter *typeParam); void GenObjectType(const checker::ETSObjectType *objectType); void GenEnumType(const checker::ETSEnumType *enumType); + void GenUnionType(const checker::ETSUnionType *unionType); void GenImportDeclaration(const ir::ETSImportDeclaration *importDeclaration); void GenTypeAliasDeclaration(const ir::TSTypeAliasDeclaration *typeAlias); diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index 7961ee7c144c5dae77f599155b7ad563d25b8c36..4f5e5c1db2e0b62c446d27b21a7067b22227f3f4 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -190,7 +190,7 @@ bool Options::Parse(int argc, const char **argv) "ForLoopCorrectlyInitializedForAll,VariableHasEnclosingScopeForAll,ModifierAccessValidForAll," "ImportExportAccessValid"); panda::PandArg verifierErrors( - "verifier-errors", "ForLoopCorrectlyInitializedForAll", + "verifier-errors", "ForLoopCorrectlyInitializedForAll,NodeHasParentForAll,EveryChildHasValidParentForAll", "Print errors and stop compilation if AST tree is incorrect. " "Possible values: " "NodeHasParentForAll,EveryChildHasValidParentForAll,VariableHasScopeForAll,NodeHasTypeForAll," diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index 06d08f355360f8048f07c6523e8c017e54484f05..cb13eb13ff3d65926abef450ce4e13f9ae9e0070 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -275,9 +275,9 @@ void ETSBinder::BuildMethodDefinition(ir::MethodDefinition *methodDef) void ETSBinder::ResolveMethodDefinition(ir::MethodDefinition *methodDef) { - auto *func = methodDef->Function(); - ResolveReferences(methodDef); + methodDef->ResolveReferences([this](auto *childNode) { ResolveReference(childNode); }); + auto *func = methodDef->Function(); if (methodDef->IsStatic() || func->IsStaticBlock()) { return; } @@ -400,8 +400,9 @@ void ETSBinder::BuildLambdaObject(ir::AstNode *refNode, ir::ClassDefinition *lam auto boundCtx = BoundContext(GetGlobalRecordTable(), lambdaObject); const auto &lambdaBody = lambdaObject->Body(); + AddLambdaFunctionThisParam(lambdaBody[lambdaBody.size() - 3U]->AsMethodDefinition()->Function()); AddLambdaFunctionThisParam(lambdaBody[lambdaBody.size() - 2U]->AsMethodDefinition()->Function()); - AddLambdaFunctionThisParam(lambdaBody[lambdaBody.size() - 1]->AsMethodDefinition()->Function()); + AddLambdaFunctionThisParam(lambdaBody[lambdaBody.size() - 1U]->AsMethodDefinition()->Function()); LambdaObjects().insert({refNode, {lambdaObject, signature}}); } @@ -876,16 +877,6 @@ void ETSBinder::FormLambdaName(util::UString &name, const util::StringView &sign name.Append(replaced); } -void ETSBinder::FormFunctionalInterfaceName(util::UString &name, const util::StringView &signature) -{ - auto replaced = std::string(signature.Utf8()); - std::replace(replaced.begin(), replaced.end(), '.', '-'); - std::replace(replaced.begin(), replaced.end(), ':', '-'); - std::replace(replaced.begin(), replaced.end(), ';', '-'); - replaced.append(std::to_string(0)); - name.Append(replaced); -} - void ETSBinder::BuildLambdaObjectName(const ir::AstNode *refNode) { auto found = lambdaObjects_.find(refNode); @@ -913,51 +904,17 @@ void ETSBinder::BuildLambdaObjectName(const ir::AstNode *refNode) lambdaObject->SetAssemblerName(lambdaClass->Ident()->Name()); const auto &lambdaBody = lambdaClass->Body(); - auto *ctorFunc = lambdaBody[lambdaBody.size() - 2]->AsMethodDefinition()->Function(); + auto *ctorFunc = lambdaBody[lambdaBody.size() - 3U]->AsMethodDefinition()->Function(); auto *ctorFuncScope = ctorFunc->Scope(); ctorFuncScope->BindName(lambdaClass->Ident()->Name()); - auto *invokeFunc = lambdaBody[lambdaBody.size() - 1]->AsMethodDefinition()->Function(); - auto *invokeFuncScope = invokeFunc->Scope(); - invokeFuncScope->BindName(lambdaClass->Ident()->Name()); -} - -void ETSBinder::BuildFunctionalInterfaceName(ir::ETSFunctionType *funcType) -{ - auto *functionalInterface = funcType->FunctionalInterface(); - auto *invokeFunc = functionalInterface->Body()->Body()[0]->AsMethodDefinition()->Function(); - util::UString functionalInterfaceName(functionalInterface->Id()->Name(), Allocator()); - std::stringstream ss; - invokeFunc->Signature()->ToAssemblerType(GetCompilerContext(), ss); - std::string signatureString = ss.str(); - util::StringView signatureName(signatureString); - FormFunctionalInterfaceName(functionalInterfaceName, signatureName); - functionalInterface->Id()->SetName(functionalInterfaceName.View()); - util::UString internalName(Program()->GetPackageName(), Allocator()); - if (!(internalName.View().Empty())) { - internalName.Append(compiler::Signatures::METHOD_SEPARATOR); - } - internalName.Append(functionalInterface->Id()->Name()); - functionalInterface->SetInternalName(internalName.View()); - - checker::ETSObjectType *functionalInterfaceType = functionalInterface->TsType()->AsETSObjectType(); - functionalInterfaceType->SetName(functionalInterface->Id()->Name()); - functionalInterfaceType->SetAssemblerName(internalName.View()); + auto *invoke0Func = lambdaBody[lambdaBody.size() - 2U]->AsMethodDefinition()->Function(); + auto *invoke0FuncScope = invoke0Func->Scope(); + invoke0FuncScope->BindName(lambdaClass->Ident()->Name()); + auto *invokeFunc = lambdaBody[lambdaBody.size() - 1U]->AsMethodDefinition()->Function(); auto *invokeFuncScope = invokeFunc->Scope(); - invokeFuncScope->BindName(functionalInterface->Id()->Name()); - - util::UString invokeInternalName(Program()->GetPackageName(), Allocator()); - if (!(invokeInternalName.View().Empty())) { - invokeInternalName.Append(compiler::Signatures::METHOD_SEPARATOR); - } - invokeInternalName.Append(invokeFuncScope->Name()); - invokeInternalName.Append(compiler::Signatures::METHOD_SEPARATOR); - invokeInternalName.Append(invokeFunc->Id()->Name()); - std::stringstream invokeSignatureSs; - invokeFunc->Signature()->ToAssemblerType(GetCompilerContext(), invokeSignatureSs); - invokeInternalName.Append(invokeSignatureSs.str()); - invokeFuncScope->BindInternalName(invokeInternalName.View()); + invokeFuncScope->BindName(lambdaClass->Ident()->Name()); } void ETSBinder::InitImplicitThisParam() diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index edd27f9a43a6b9cd3905d994d94ac3fbaf527937..0f7057727922ed23bafc385918c95c2e7a5d43a2 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -158,8 +158,6 @@ public: void AddInvokeFunctionThisParam(ir::ScriptFunction *func); void BuildLambdaObjectName(const ir::AstNode *refNode); void FormLambdaName(util::UString &name, const util::StringView &signature); - void FormFunctionalInterfaceName(util::UString &name, const util::StringView &signature); - void BuildFunctionalInterfaceName(ir::ETSFunctionType *funcType); void SetDefaultImports(ArenaVector defaultImports) {