diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 3a2c876796b279d11c1623da93556dec47c02a82..ecf9fc659acc88c143de5d33da7c2bcb1b2f1619 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1941,8 +1941,7 @@ ETSObjectType *ETSChecker::CheckExceptionOrErrorType(checker::Type *type, const ES2PANDA_ASSERT(type != nullptr); if (!type->IsETSObjectType() || (!Relation()->IsAssignableTo(type, GlobalBuiltinExceptionType()) && !Relation()->IsAssignableTo(type, GlobalBuiltinErrorType()))) { - LogError(diagnostic::CATCH_OR_THROW_OF_INVALID_TYPE, - {compiler::Signatures::BUILTIN_EXCEPTION_CLASS, compiler::Signatures::BUILTIN_ERROR_CLASS}, pos); + LogError(diagnostic::CATCH_OR_THROW_OF_INVALID_TYPE, {compiler::Signatures::BUILTIN_ERROR_CLASS}, pos); return GlobalETSObjectType(); } diff --git a/ets2panda/test/ast/compiler/ets/try_catch_argument.ets b/ets2panda/test/ast/compiler/ets/try_catch_argument.ets new file mode 100644 index 0000000000000000000000000000000000000000..0890bc45e55f71b5fe3a3376d8587bdf3c32da41 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/try_catch_argument.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ + +try { + let a = new Array(4); + a[11] = "8" +} catch (e: A) { + console.log("11") +} + +/* @@? 19:10 Error TypeError: Argument must be an instance of 'Error' */ +/* @@? 19:13 Error TypeError: Cannot find type 'A'. */ +/* @@? 19:13 Warning Warning: The catch statement with type annotation is deprecated, use catch(e). */ diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index 5b7a9bdbff9630242492a0859864346d39f0e79b..ccd99c363187c206df196bd99b50299fbd408f5d 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -250,7 +250,7 @@ semantic: - name: CATCH_OR_THROW_OF_INVALID_TYPE id: 205 - message: "Argument must be an instance of '{}' or '{}'" + message: "Argument must be an instance of '{}'" - name: CHAR_TO_STR_CONVERSION id: 4201