From dcb5ee8708980c4c54ec1500e5cc61eacf424ee2 Mon Sep 17 00:00:00 2001 From: ertugrulfarukpiskin Date: Fri, 20 Jun 2025 11:29:57 +0300 Subject: [PATCH] Crash with readonly Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICGEEY Description: Crash with readonly when class or interface has nullable properties Signed-off-by: ertugrulfarukpiskin --- .../lowering/ets/objectLiteralLowering.cpp | 6 ++- .../ets/nullable_readonly_property.ets | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/runtime/ets/nullable_readonly_property.ets diff --git a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp index d0f415917d..a01f89264f 100644 --- a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp +++ b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp @@ -14,7 +14,6 @@ */ #include "objectLiteralLowering.h" - #include "checker/ETSchecker.h" #include "compiler/lowering/scopesInit/scopesInitPhase.h" #include "compiler/lowering/util.h" @@ -130,6 +129,11 @@ static void PopulateCtorArgumentsFromMap(public_lib::Context *ctx, ir::ObjectExp ctorArguments.push_back(allocator->New()); continue; } + if (ctorArgument == nullptr && param->TsType()->PossiblyETSUndefined()) { + ctorArguments.push_back(allocator->New()); + continue; + } + ES2PANDA_ASSERT(ctorArgument != nullptr); ctorArguments.push_back(ctorArgument); } } diff --git a/ets2panda/test/runtime/ets/nullable_readonly_property.ets b/ets2panda/test/runtime/ets/nullable_readonly_property.ets new file mode 100644 index 0000000000..ab468df7ed --- /dev/null +++ b/ets2panda/test/runtime/ets/nullable_readonly_property.ets @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 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. + */ + +interface Actions { + readonly type: string; + readonly id: string; +} + +export interface VerifyCodeFixAvailableOptions { + readonly description: string; + readonly actions?: ReadonlyArray; + readonly commands?: ReadonlyArray; +} + +class verify { + static codeFixAvailable(options?: ReadonlyArray): void { + arktest.assertEQ(options![0].description, "Implement interface 'I1'"); + arktest.assertEQ(options![0].actions, undefined); + arktest.assertEQ(options![0].commands, undefined); + arktest.assertEQ(options![1].description, "Implement interface 'I2'"); + arktest.assertEQ(options![1].actions, undefined); + arktest.assertEQ(options![1].commands, undefined); + arktest.assertEQ(options![2].description, "Implement interface 'I3'"); + arktest.assertEQ(options![2].actions![0].type, "IA"); + arktest.assertEQ(options![2].actions![0].id, "IA1"); + arktest.assertEQ(options![2].commands, undefined); + arktest.assertEQ(options![3].description, "Implement interface 'I4'"); + arktest.assertEQ(options![3].actions![0].type, "IB"); + arktest.assertEQ(options![3].actions![0].id, "IB1"); + arktest.assertEQ(options![3].commands![0], "CMD1"); + }; +} + +function main() { + verify.codeFixAvailable([ + { description: "Implement interface 'I1'" }, + { description: "Implement interface 'I2'" }, + { description: "Implement interface 'I3'", actions: [ { type: "IA", id: "IA1" } ] as Actions[] }, + { description: "Implement interface 'I4'", actions: [ { type: "IB", id: "IB1" } ] as Actions[], commands: [ "CMD1" ] } + ] as VerifyCodeFixAvailableOptions[]) +} \ No newline at end of file -- Gitee