From 66a4a742e030fe3a72ed9d6e13d014307f83a2e4 Mon Sep 17 00:00:00 2001 From: zmw Date: Tue, 15 Jul 2025 20:46:41 +0800 Subject: [PATCH] Fix stack overflow of default type Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMK58 Description: Fix stack overflow of default type Signed-off-by: zmw Change-Id: I6d4b921ed1593a6fd84a3c997ace3e68cc421d48 --- ets2panda/checker/ets/object.cpp | 7 ++--- .../ets/default_type_circular_dependency.ets | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/default_type_circular_dependency.ets diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 931ba8540c0..d7277a46c0b 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -311,13 +311,14 @@ bool ETSChecker::CheckDefaultTypeParameter(const ir::TSTypeParameter *param, Typ defaultTypePart->Name()->Check(this); } auto *const variable = defaultTypePart->GetIdent()->Variable(); - ES2PANDA_ASSERT(variable != nullptr); - if (variable->TsType() == nullptr && (variable->Flags() & varbinder::VariableFlags::TYPE_PARAMETER) != 0U && + auto defaultType = variable == nullptr ? defaultTypePart->TsType() : variable->TsType(); + if (defaultType == nullptr && variable != nullptr && + (variable->Flags() & varbinder::VariableFlags::TYPE_PARAMETER) != 0U && typeParameterDecls.count(variable) == 0U) { LogError(diagnostic::TYPE_PARAM_USE_BEFORE_DEFINE, {defaultTypePart->Name()->AsIdentifier()->Name().Utf8()}, node->Start()); ok = false; - } else if (variable->TsType() != nullptr && variable->TsType()->IsTypeError()) { + } else if (defaultType != nullptr && defaultType->IsTypeError()) { ok = false; } } diff --git a/ets2panda/test/ast/compiler/ets/default_type_circular_dependency.ets b/ets2panda/test/ast/compiler/ets/default_type_circular_dependency.ets new file mode 100644 index 00000000000..8f4a1420146 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/default_type_circular_dependency.ets @@ -0,0 +1,27 @@ +/* + * 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 Racer { + stat; +} + +/* @@? 17:9 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 17:22 Error TypeError: 'f' type does not exist. */ +/* @@? 17:23 Error SyntaxError: Unexpected token, expected '>'. */ +/* @@? 17:24 Error SyntaxError: Unexpected token, expected '('. */ +/* @@? 17:25 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 17:25 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 17:25 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 17:25 Error SyntaxError: Unexpected token '>'. */ -- Gitee