From 7ebbd6f8b6d4853ab3c14a3b5e9da92b6c7ec1b2 Mon Sep 17 00:00:00 2001 From: Enes Aygun Date: Wed, 10 Sep 2025 14:55:36 +0300 Subject: [PATCH] Title: Array instance CTE Issue: ICXEHI Testing: Build Signed-off-by: Enes Aygun --- ets2panda/checker/ets/typeRelationContext.cpp | 2 +- .../ast/compiler/ets/array_instance_cte.ets | 29 +++++++++++++++++++ ets2panda/util/diagnostic/semantic.yaml | 4 +++ ets2panda/util/diagnostic/warning.yaml | 5 +--- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 ets2panda/test/ast/compiler/ets/array_instance_cte.ets diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index fc1e4e7284..3bcd63daba 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 0000000000..e2518c2ff9 --- /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 bb8e6f39ec..54fa0ab00f 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 dcb80bf69a..ee905259d1 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 -- Gitee