From 6763a5dfc8469f9ebaadd5ee009199ecd4954f2e Mon Sep 17 00:00:00 2001 From: Shimenkov Mikhail Date: Tue, 5 Aug 2025 15:42:45 +0300 Subject: [PATCH] Fixed union type assembler string representation * Fixed union type assembler string representation dependence on the order of constituent types Was: object | null => U{std.core.Null, std.core.Object} null | object => std.core.Object Became: object | null or null | object => U{std.core.Null, std.core.Object} Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICT0O9 Tests: ninja all tests Signed-off-by: Shimenkov Mikhail Change-Id: Ibf6e5e38df13df8a6b22845f530ad8868442fbd0 --- .../checker/types/ets/etsNullishTypes.cpp | 4 +-- ets2panda/test/unit/union_emit_test.cpp | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ets2panda/checker/types/ets/etsNullishTypes.cpp b/ets2panda/checker/types/ets/etsNullishTypes.cpp index 6e102e1675..e9abc5839f 100644 --- a/ets2panda/checker/types/ets/etsNullishTypes.cpp +++ b/ets2panda/checker/types/ets/etsNullishTypes.cpp @@ -59,12 +59,12 @@ void ETSNullType::ToString(std::stringstream &ss, [[maybe_unused]] bool precise) void ETSNullType::ToAssemblerType(std::stringstream &ss) const { - ss << compiler::Signatures::BUILTIN_OBJECT; + ss << compiler::Signatures::NULL_ASSEMBLY_TYPE; } void ETSNullType::ToDebugInfoType(std::stringstream &ss) const { - ss << ETSObjectType::NameToDescriptor(compiler::Signatures::BUILTIN_OBJECT); + ss << ETSObjectType::NameToDescriptor(compiler::Signatures::NULL_ASSEMBLY_TYPE); } Type *ETSNullType::Instantiate([[maybe_unused]] ArenaAllocator *allocator, [[maybe_unused]] TypeRelation *relation, diff --git a/ets2panda/test/unit/union_emit_test.cpp b/ets2panda/test/unit/union_emit_test.cpp index 47134d0b4f..13fcd11f6d 100644 --- a/ets2panda/test/unit/union_emit_test.cpp +++ b/ets2panda/test/unit/union_emit_test.cpp @@ -24,6 +24,16 @@ public: ~UnionAsmTest() override = default; + void CheckFunction(std::string_view funcSig, bool found = true) + { + pandasm::Function *func = GetFunction(funcSig, program_->functionStaticTable); + if (found) { + ASSERT_TRUE(func != nullptr) << "Function '" << funcSig << "' not found"; + } else { + ASSERT_TRUE(func == nullptr) << "Function '" << funcSig << "' found"; + } + } + void CheckUnionType(std::string_view recordName, bool found = true) { pandasm::Record *rec = GetRecord(recordName, program_); @@ -234,4 +244,19 @@ TEST_F(UnionAsmTest, union_test_as) CheckInsInFunction("dummy.ETSGLOBAL.test1:std.core.String;void;", "std.core.Runtime.failedTypeCastException", true); } +TEST_F(UnionAsmTest, union_null_object) +{ + SetCurrentProgram(R"( + type T1 = string | null | undefined | object + type T2 = string | object | null | undefined + function foo1(a: T1) {} + function foo2(a: T2) {} + )"); + + CheckFunction("dummy.ETSGLOBAL.foo1:{Ustd.core.Null,std.core.Object};void;"); + CheckFunction("dummy.ETSGLOBAL.foo2:{Ustd.core.Null,std.core.Object};void;"); + CheckFunction("dummy.ETSGLOBAL.foo1:std.core.Object;void;", false); + CheckFunction("dummy.ETSGLOBAL.foo2:std.core.Object;void;", false); +} + } // namespace ark::es2panda::compiler::test -- Gitee