From ca61ec66070df3bfc73d3ff7e7827a5cc29eb0cf Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Tue, 17 Jun 2025 14:41:59 +0300 Subject: [PATCH] Avoid conversion to string via as Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICFVAW Signed-off-by: Georgy Bronnikov --- ets2panda/compiler/core/ETSGen.cpp | 4 ---- ets2panda/test/runtime/ets/no-as-string.ets | 12 ++++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 ets2panda/test/runtime/ets/no-as-string.ets diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 149c12d4d5..dde5c4c560 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -1201,10 +1201,6 @@ void ETSGen::CastToReftype(const ir::AstNode *const node, const checker::Type *c const auto *const sourceType = GetAccumulatorType(); ES2PANDA_ASSERT(sourceType->IsETSReferenceType()); - if (targetType->IsETSStringType() && !sourceType->IsETSStringType()) { - CastToString(node); - } - if (!unchecked) { CheckedReferenceNarrowing(node, targetType); return; diff --git a/ets2panda/test/runtime/ets/no-as-string.ets b/ets2panda/test/runtime/ets/no-as-string.ets new file mode 100644 index 0000000000..9ced428c7e --- /dev/null +++ b/ets2panda/test/runtime/ets/no-as-string.ets @@ -0,0 +1,12 @@ +function ff(o: Object): string { + return o as string +} + +function main(): int { + try { + ff(44) + return 1 + } catch (e) { + return 0 + } +} -- Gitee