From 21e7098504dd0c8e012101a1a8c013330d9a14e3 Mon Sep 17 00:00:00 2001 From: oh-rgx Date: Sat, 19 Jul 2025 15:01:56 +0800 Subject: [PATCH] Fix check spreadElement crash Issue: #ICNE4C Signed-off-by: oh-rgx --- ets2panda/checker/ETSAnalyzer.cpp | 2 +- .../ast/compiler/ets/check_spreadElement.ets | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/check_spreadElement.ets diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index f4fc39afe2..5d295543ec 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -380,7 +380,7 @@ checker::Type *ETSAnalyzer::Check(ir::SpreadElement *expr) const if (expr->PreferredType() != nullptr) { expr->Argument()->SetPreferredType(expr->PreferredType()); } - auto type = expr->AsSpreadElement()->Argument()->Check(checker); + auto type = expr->Argument()->Check(checker); Type *exprType = type->MaybeBaseTypeOfGradualType(); if (exprType->IsETSResizableArrayType()) { diff --git a/ets2panda/test/ast/compiler/ets/check_spreadElement.ets b/ets2panda/test/ast/compiler/ets/check_spreadElement.ets new file mode 100644 index 0000000000..69f13c49a7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/check_spreadElement.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +[a, b, ...rest] = [1, 2, 3, 4, 5]; + +/* @@? 16:1 Error TypeError: Invalid left-hand side of assignment expression */ +/* @@? 16:2 Error TypeError: Unresolved reference a */ +/* @@? 16:5 Error TypeError: Unresolved reference b */ +/* @@? 16:11 Error TypeError: Unresolved reference rest */ -- Gitee