diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index e88dc37f377a4878c695a4bb06ad6d332d445cbb..62e60a942655c739e9dfba18584e766ed40f063c 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -370,6 +370,12 @@ bool ETSChecker::CheckDefaultTypeParameter(const ir::TSTypeParameter *param, Typ }; if (param->DefaultType() != nullptr) { + TypeStackElement tse(this, param->DefaultType(), {{diagnostic::TYPE_PARAM_CIRCULAR_DEFAULT_TYPE}}, + param->DefaultType()->Start()); + if (tse.HasTypeError()) { + return false; + } + param->DefaultType()->Iterate(checkDefault); } 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 0000000000000000000000000000000000000000..973142e608fa841101956aa3d71627bd596646eb --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/default_type_circular_dependency.ets @@ -0,0 +1,28 @@ +/* + * 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:16 Error TypeError: Default type of type parameter has circular dependency. */ +/* @@? 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 '>'. */ diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index d344218f8655f19491a7f9239928e44322a0f7c3..9d97193cc8056815d5cb6fda45621025cd5a88a1 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -1472,6 +1472,10 @@ semantic: id: 184 message: "Type parameter '{}' has circular constraint dependency." +- name: TYPE_PARAM_CIRCULAR_DEFAULT_TYPE + id: 398 + message: "Default type of type parameter has circular dependency." + - name: TYPE_PARAM_USE_BEFORE_DEFINE id: 183 message: "Type Parameter {} should be defined before use."