From 0ad8c80eb378a37e568e01a8d075a44c823ee1da Mon Sep 17 00:00:00 2001 From: yp9522 Date: Thu, 17 Jul 2025 09:09:22 +0800 Subject: [PATCH] fix crash for rest tuple Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMUDY Signed-off-by: yp9522 --- .../checker/types/ets/etsTypeParameter.cpp | 6 +++- .../compiler/ets/rest_tuple_for_static.ets | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 ets2panda/test/ast/compiler/ets/rest_tuple_for_static.ets diff --git a/ets2panda/checker/types/ets/etsTypeParameter.cpp b/ets2panda/checker/types/ets/etsTypeParameter.cpp index ebb370321d..7e213838b7 100644 --- a/ets2panda/checker/types/ets/etsTypeParameter.cpp +++ b/ets2panda/checker/types/ets/etsTypeParameter.cpp @@ -160,7 +160,11 @@ void ETSTypeParameter::ToDebugInfoType(std::stringstream &ss) const ETSTypeParameter *ETSTypeParameter::GetOriginal() const noexcept { - return GetDeclNode()->Name()->Variable()->TsType()->AsETSTypeParameter(); + auto type = GetDeclNode()->Name()->Variable()->TsType(); + if (type == nullptr || type->HasTypeFlag(TypeFlag::TYPE_ERROR)) { + return nullptr; + } + return type->AsETSTypeParameter(); } util::StringView const &ETSTypeParameter::Name() const noexcept diff --git a/ets2panda/test/ast/compiler/ets/rest_tuple_for_static.ets b/ets2panda/test/ast/compiler/ets/rest_tuple_for_static.ets new file mode 100755 index 0000000000..53554d48e2 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/rest_tuple_for_static.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ + +class TH { + static restMethod(...v: [A, B, C]) { + } +} + +function main() { + let mc = new TH +} + +/* @@@ label Error TypeError: Type '[*ERROR_TYPE*, *ERROR_TYPE*, *ERROR_TYPE*]' is not compatible with rest parameter type '[A, B, C]' at index 1 */ +/* @@@ label Error TypeError: Expected 3 arguments, got 1. */ +/* @@@ label Error TypeError: No matching call signature for restMethod([*ERROR_TYPE*, *ERROR_TYPE*, *ERROR_TYPE*]) */ +/* @@@ label Error TypeError: Cannot make a static reference to the non-static type A */ +/* @@@ label Error TypeError: Cannot make a static reference to the non-static type B */ +/* @@@ label Error TypeError: Cannot make a static reference to the non-static type C */ -- Gitee