From 4c42cb5734ba78160e61a38e4bfed741e519ff5c Mon Sep 17 00:00:00 2001 From: yp9522 Date: Mon, 14 Jul 2025 09:54:40 +0800 Subject: [PATCH] modify the judgment when the type is empty issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLU76 Signed-off-by: yp9522 --- ets2panda/checker/checkerContext.cpp | 3 +- .../ets/nullable_type_in_get_tstype.ets | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/nullable_type_in_get_tstype.ets diff --git a/ets2panda/checker/checkerContext.cpp b/ets2panda/checker/checkerContext.cpp index b8da863c9b..9488f39ad8 100644 --- a/ets2panda/checker/checkerContext.cpp +++ b/ets2panda/checker/checkerContext.cpp @@ -308,7 +308,8 @@ void CheckerContext::CheckIdentifierSmartCastCondition(ir::Identifier const *con ES2PANDA_ASSERT(variable != nullptr); // Smart cast for extended conditional check can be applied only to the variables of reference types. - if (auto const *const variableType = variable->TsType(); !variableType->IsETSReferenceType()) { + auto const *const variableType = variable->TsType(); + if (variableType == nullptr || !variableType->IsETSReferenceType()) { return; } diff --git a/ets2panda/test/ast/compiler/ets/nullable_type_in_get_tstype.ets b/ets2panda/test/ast/compiler/ets/nullable_type_in_get_tstype.ets new file mode 100644 index 0000000000..d119fc7099 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/nullable_type_in_get_tstype.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024-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. + */ + +let x: Int = new Int(5); + let x = i + j; + x = (++x, x++); + console.println(x); + +function foo(): void {"GGGG" +} + +class A { + flag: boolean = null == null; greeting(): void { + if (x == null) { console.println("Hello, World!"); + } + } +} + +/* @@? 17:13 Error TypeError: Variable 'x' has already been declared. */ +/* @@? 17:17 Error TypeError: Unresolved reference i */ +/* @@? 17:21 Error TypeError: Unresolved reference j */ +/* @@? 18:17 Error SyntaxError: Unexpected token, expected ')'. */ +/* @@? 18:19 Error SyntaxError: Unexpected token 'x'. */ +/* @@? 18:22 Error SyntaxError: Unexpected token ')'. */ -- Gitee