From b2fd9adf2ad3aedbab18b9b8ee953c4f8fb242ee Mon Sep 17 00:00:00 2001 From: XuMoheng Date: Tue, 2 Sep 2025 20:04:21 +0800 Subject: [PATCH] add test case Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICW1TT?from=project-issue Description: pr7878 has fixed this bug, and this commit will add a test case to cover the scenario described in the issue. Tests: tests/tests-u-runner/runner.sh --astchecker --no-js --show-progress --build-dir out --processes=all Signed-off-by: xumoheng --- .../compiler/ets/nonNullish_expr_is_null.ets | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/nonNullish_expr_is_null.ets diff --git a/ets2panda/test/ast/compiler/ets/nonNullish_expr_is_null.ets b/ets2panda/test/ast/compiler/ets/nonNullish_expr_is_null.ets new file mode 100644 index 0000000000..e11875089d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/nonNullish_expr_is_null.ets @@ -0,0 +1,45 @@ +/* + * 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 arkts_p { + field: int; + + static run(out: Console): int { + let x: arkts_p | null = null; + let a:int = 0; + let res: int; + try { + res = (x!.field += ++a); + } catch (e) { + if (e instanceof NullPointerError) { + if (a === 0) { + return 0; + } + return 1; + } + return 2; + } + return 3; + } +} + +function test() { + const result = arkts_p.run(console); + arktest.assertEQ(result,0); +} + +test() + +/* @@? 23:19 Warning Warning: Bad operand type, the operand of the non-nullish expression is 'null' or 'undefined'. */ +/* @@? 23:20 Warning Warning: Bad operand type, the operand of the non-nullish expression is 'null' or 'undefined'. */ \ No newline at end of file -- Gitee