已合并
Declare interface method has body_2 #10318
Declare interface method has body_2 #10318
已合并
fanglou创建于 3月31日
共 1 个文件变更+27-28
@@ -701,59 +701,58 @@ static ArenaVector<ark::es2panda::checker::Signature *> GetInterfaceGenericSigna
701static void CheckInterface(checker::TypeRelation *relation, ir::TSInterfaceDeclaration *interfaceDecl,701static void CheckInterface(checker::TypeRelation *relation, ir::TSInterfaceDeclaration *interfaceDecl,
702 ir::ObjectExpression *objectExpr, InterfaceMethods &methods)702 ir::ObjectExpression *objectExpr, InterfaceMethods &methods)
703{703{
704- // Lambda checks if any method defined in object literal overrides empty method declared in interface.704+ auto checkOverriding = [&methods, objectExpr, relation](ir::MethodDefinition const *methodDef,
705- auto const checkOverriding = [&methods, objectExpr, relation](ir::ScriptFunction const *const function,705+ checker::Signature *sig) {
706- checker::Signature *sig) -> void {706+ auto *func = methodDef->Function();
707- auto const &name = function->Id()->Name();707+ auto &name = func->Id()->Name();
708- auto *const signature = const_cast<checker::Signature *>(function->Signature());708+ auto *signature = const_cast<checker::Signature *>(func->Signature());
709- auto const hasBody = function->HasBody();709+ bool hasBody = func->HasBody() || (methodDef->Modifiers() & ir::ModifierFlags::DEFAULT);
710- 710+ auto it = std::find_if(methods.begin(), methods.end(), [&name, signature, relation](auto &item) {
711- auto it = std::find_if(711+ return std::get<0>(item) == name && relation->SignatureIsSupertypeOf(std::get<1>(item), signature);
712- methods.begin(), methods.end(), [&name, signature, relation](InterfaceMethod const &item) -> bool {712+ });
713- return std::get<0U>(item) == name && relation->SignatureIsSupertypeOf(std::get<1U>(item), signature);
714- });
715 if (it == methods.end()) {713 if (it == methods.end()) {
716 methods.emplace_back(name, signature, hasBody);714 methods.emplace_back(name, signature, hasBody);
717 it = std::prev(methods.end());715 it = std::prev(methods.end());
718 } else if (hasBody) {716 } else if (hasBody) {
719- std::get<2U>(*it) = true;717+ std::get<2>(*it) = true;
720 }718 }
721 719 
722- if (std::get<2U>(*it)) {720+ if (std::get<2>(*it)) {
723 return;721 return;
724 }722 }
725 723 
726- for (ir::Expression *propExpr : objectExpr->Properties()) {724+ for (auto *propExpr : objectExpr->Properties()) {
727 if (!propExpr->IsProperty()) {725 if (!propExpr->IsProperty()) {
728 continue;726 continue;
729 }727 }
730 728 
731- if (auto const *const key = propExpr->AsProperty()->Key();729+ auto *key = propExpr->AsProperty()->Key();
732- !key->IsIdentifier() || !key->AsIdentifier()->Name().Is(name.Utf8())) {730+ if (!key->IsIdentifier() || key->AsIdentifier()->Name() != name.Utf8()) {
733 continue;731 continue;
734 }732 }
735 733 
736- checker::SavedTypeRelationFlagsContext savedCtx(relation, checker::TypeRelationFlag::OVERRIDING_CONTEXT);734+ checker::SavedTypeRelationFlagsContext ctx(relation, checker::TypeRelationFlag::OVERRIDING_CONTEXT);
737- checker::Type *const valueType = propExpr->AsProperty()->Value()->TsType();735+ auto *valType = propExpr->AsProperty()->Value()->TsType();
738- if (valueType->IsETSArrowType() &&736+ if (valType->IsETSArrowType() &&
739- relation->SignatureIsSupertypeOf(sig, valueType->AsETSFunctionType()->ArrowSignature())) {737+ relation->SignatureIsSupertypeOf(sig, valType->AsETSFunctionType()->ArrowSignature())) {
740- std::get<2U>(*it) = true;738+ std::get<2>(*it) = true;
741 }739 }
742 }740 }
743 };741 };
744 742 
745- ES2PANDA_ASSERT(interfaceDecl->Body() != nullptr);743+ ES2PANDA_ASSERT(interfaceDecl->Body());
746- for (auto const *const node : interfaceDecl->Body()->Body()) {744+ for (auto *node : interfaceDecl->Body()->Body()) {
747 if (node->IsOverloadDeclaration()) {745 if (node->IsOverloadDeclaration()) {
748 continue;746 continue;
749 }747 }
750- auto methodDef = node->AsMethodDefinition();
751- auto targetType = objectExpr->TsType()->AsETSObjectType();
752- auto signatures = GetInterfaceGenericSignature(targetType, methodDef->Key()->AsIdentifier()->Name());
753 748 
754- for (auto sig : signatures) {749+ auto *methodDef = node->AsMethodDefinition();
750+ auto *objType = objectExpr->TsType()->AsETSObjectType();
751+ auto signatures = GetInterfaceGenericSignature(objType, methodDef->Key()->AsIdentifier()->Name());
752+ 
753+ for (auto *sig : signatures) {
755 if (!methodDef->Function()->IsGetterOrSetter()) {754 if (!methodDef->Function()->IsGetterOrSetter()) {
756- checkOverriding(methodDef->Function(), sig);755+ checkOverriding(methodDef, sig);
757 }756 }
758 }757 }
759 }758 }