From 1f8417fda4cb41465895b570bd0dc0d637dc88ab Mon Sep 17 00:00:00 2001 From: xuxinjie4 Date: Thu, 10 Jul 2025 15:49:19 +0800 Subject: [PATCH] Fix bug of interop objectliteral Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMYRA?from=project-issue Signed-off-by: xuxinjie4 --- ets2panda/checker/ETSAnalyzer.cpp | 7 ++++++- .../lowering/ets/interfacePropertyDeclarations.cpp | 3 ++- ets2panda/compiler/lowering/ets/unboxLowering.cpp | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 3fe590ae19..6c13296f64 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -2004,7 +2004,12 @@ checker::Type *ETSAnalyzer::CheckDynamic(ir::ObjectExpression *expr) const static bool ValidatePreferredType(ETSChecker *checker, ir::ObjectExpression *expr) { - auto preferredType = expr->PreferredType(); + auto preferredType = expr->PreferredType()->MaybeBaseTypeOfGradualType(); + if (preferredType == nullptr) { + checker->LogError(diagnostic::CLASS_COMPOSITE_UNKNOWN_TYPE, {}, expr->Start()); + return false; + } + if (preferredType->IsTypeError()) { // Don't need to duplicate error message for a single error. return false; diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index 9ffb2732ec..66fb67ba66 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -125,7 +125,8 @@ ir::MethodDefinition *InterfacePropertyDeclarationsPhase::GenerateGetterOrSetter ctx->Allocator(), ir::ScriptFunction::ScriptFunctionData { nullptr, std::move(signature), // CC-OFF(G.FMT.02) project code style // CC-OFFNXT(G.FMT.02) project code style - isSetter ? ir::ScriptFunctionFlags::SETTER : ir::ScriptFunctionFlags::GETTER, flags}); + isSetter ? ir::ScriptFunctionFlags::SETTER : ir::ScriptFunctionFlags::GETTER, flags, + classScope->Node()->AsTSInterfaceDeclaration()->Language()}); func->SetRange(field->Range()); func->SetScope(functionScope); diff --git a/ets2panda/compiler/lowering/ets/unboxLowering.cpp b/ets2panda/compiler/lowering/ets/unboxLowering.cpp index 0e5299b822..ef0704c10e 100644 --- a/ets2panda/compiler/lowering/ets/unboxLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unboxLowering.cpp @@ -268,6 +268,11 @@ static void NormalizeAllTypes(UnboxContext *uctx, ir::AstNode *ast) static void HandleScriptFunctionHeader(UnboxContext *uctx, ir::ScriptFunction *func) { + // dynamic function does not need to unbox + if (func->Language() == Language::Id::JS) { + return; + } + auto *sig = func->Signature(); if (sig == nullptr) { return; -- Gitee