From f055031d1a51384d6f46f450ebe47e6e6f9cd6af Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 14 Jul 2025 16:15:15 +0800 Subject: [PATCH] Fixing Compilation Problems Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICM5Y9 Signed-off-by: yp9522 --- ets2panda/checker/ets/helpers.cpp | 6 ++++++ .../ast/compiler/ets/expressions_test.ets | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 ets2panda/test/ast/compiler/ets/expressions_test.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 095b9f0503..b1281f4995 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -717,6 +717,12 @@ bool ETSChecker::CheckInit(ir::Identifier *ident, ir::TypeNode *typeAnnotation, { if (typeAnnotation == nullptr) { if (init->IsArrayExpression()) { + auto arrayExpr = init->AsArrayExpression(); + if (arrayExpr->Elements().empty()) { + LogError(diagnostic::CANNOT_INFER_OBJ_LIT, {ident->Name()}, ident->Start()); + return false; + } + annotationType = CheckArrayElements(init->AsArrayExpression()); } else if (init->IsETSNewArrayInstanceExpression()) { annotationType = init->AsETSNewArrayInstanceExpression()->TypeReference()->GetType(this); diff --git a/ets2panda/test/ast/compiler/ets/expressions_test.ets b/ets2panda/test/ast/compiler/ets/expressions_test.ets new file mode 100755 index 0000000000..1eef3ff0e6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/expressions_test.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +let u : "A" | "B" = "A"; + +let /* @@ label */a = []; + +/* @@@ label Error TypeError: Cannot infer type for a because class composite needs an explicit target type */ \ No newline at end of file -- Gitee