From 0adbc8cb7c0f66acb25fecf6eb8f197c697d9fc4 Mon Sep 17 00:00:00 2001 From: yanpeng51 Date: Sat, 21 Jun 2025 08:53:19 +0800 Subject: [PATCH] "Fix object creation error" Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICGRU2 Signed-off-by: yanpeng51 --- .../lowering/ets/objectLiteralLowering.cpp | 2 +- .../ets/readonly_test/readonly_test.ets | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/runtime/ets/readonly_test/readonly_test.ets diff --git a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp index d0f415917d..031e672607 100644 --- a/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp +++ b/ets2panda/compiler/lowering/ets/objectLiteralLowering.cpp @@ -186,7 +186,7 @@ static void GenerateNewStatements(public_lib::Context *ctx, ir::ObjectExpression checker::Signature *sig = classType->ConstructSignatures().front(); for (auto param : sig->Params()) { ES2PANDA_ASSERT(param->Declaration() != nullptr); - ctorArgumentsMap.emplace(param->Declaration()->Name(), nullptr); + ctorArgumentsMap.emplace(param->Declaration()->Name(), allocator->New()); } } diff --git a/ets2panda/test/runtime/ets/readonly_test/readonly_test.ets b/ets2panda/test/runtime/ets/readonly_test/readonly_test.ets new file mode 100644 index 0000000000..e7703836e1 --- /dev/null +++ b/ets2panda/test/runtime/ets/readonly_test/readonly_test.ets @@ -0,0 +1,32 @@ +/* + * 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 MetaDate { + name:string; + age?:number; + readonly valueId?:number; +} + +const meta:MetaDate = {name:"Bob", age: 25, valueId:2} + +console.log(meta.name); +console.log(meta.age); +console.log(meta.valueId); + +const date:MetaDate = {name:"Kelly"}; +console.log(date.name); +console.log(date.age); +console.log(date.valueId); + -- Gitee