diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index fc1e4e72841c8ae88eadd16cde3197184d10802b..3bcd63daba619b99383acc11529724c8609450be 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -47,7 +47,7 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType { if (checker_->HasStatus(CheckerStatus::IN_INSTANCEOF_CONTEXT)) { if (typeArgs != nullptr) { - checker_->LogDiagnostic(diagnostic::INSTANCEOF_ERASED, {type->Name()}, pos); + checker_->LogError(diagnostic::INSTANCEOF_ERASED, {type->Name()}, pos); } result_ = type; return true; diff --git a/ets2panda/test/ast/compiler/ets/array_instance_cte.ets b/ets2panda/test/ast/compiler/ets/array_instance_cte.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2518c2ff91c6baba9054737f24b75b7a3b6b0be --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/array_instance_cte.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/*--- +desc: A compile-time error occurs if type T is not preserved by Type Erasure +name: array_instance_cte +tags: +- compile-only +---*/ + +class A { + test(p: Object) { + return p instanceof Array //CTE, Array is erased + } +} + +/* @@? TypeError: Type parameter is erased from type 'Array' when used in instanceof expression. [array_instance_cte.ets:25:29] */ \ No newline at end of file diff --git a/ets2panda/util/diagnostic/semantic.yaml b/ets2panda/util/diagnostic/semantic.yaml index bb8e6f39eca5bff4e51557d8cd44aa3786da5065..54fa0ab00f6620034f68229285021c4b503df525 100644 --- a/ets2panda/util/diagnostic/semantic.yaml +++ b/ets2panda/util/diagnostic/semantic.yaml @@ -632,6 +632,10 @@ semantic: id: 195 message: "Inner class cannot have static methods" +- name: INSTANCEOF_ERASED + id: 80543 + message: "Type parameter is erased from type '{}' when used in instanceof expression." + - name: INSTANCEOF_NONOBJECT id: 296 message: "Using the 'instance of' operator with non-object type '{}'" diff --git a/ets2panda/util/diagnostic/warning.yaml b/ets2panda/util/diagnostic/warning.yaml index dcb80bf69a9a2f91e03f26c0b9a0f0b9c6212f5b..ee905259d1c2c6f13306b276ff31f7d113d4fb7c 100644 --- a/ets2panda/util/diagnostic/warning.yaml +++ b/ets2panda/util/diagnostic/warning.yaml @@ -69,10 +69,6 @@ warning: id: 29 message: "'As' expression for cast is deprecated for numeric types. Use explicit conversion function {}.to{}(...) instead." -- name: INSTANCEOF_ERASED - id: 15 - message: "Type parameter is erased from type '{}' when used in instanceof expression." - - name: MAYBE_FALLTHROUGH id: 20 message: "Possible fall-through into case" @@ -127,6 +123,7 @@ warning: code_fix_ids: [FixUnreachableCode] graveyard: +- 15 - 18 - 19 - 27