From 49af93305e13fae37b7415245186c56e6471504f Mon Sep 17 00:00:00 2001 From: yuanxupeng Date: Tue, 21 May 2024 16:17:48 +0800 Subject: [PATCH] Fix bug in verfier Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I9PLW5 Reason: Verifier should not report an error to an Ensure-Not-Nullish Expression Description: Object in verifier dump definetely arise from "checkcast std.core.Object" with "null" as input. Verfier's checkcast handler set acc type to "std.core.Object" in this case, and makes analysis wrong. In fact, it's not necessary to do this. Tests: ninja tests bash ets_testrunner.sh --cts -r -rt Signed-off-by: yuanxupeng --- .../ets/ensure_not_nullish_expression.ets | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ets2panda/test/runtime/ets/ensure_not_nullish_expression.ets diff --git a/ets2panda/test/runtime/ets/ensure_not_nullish_expression.ets b/ets2panda/test/runtime/ets/ensure_not_nullish_expression.ets new file mode 100644 index 0000000000..269440f171 --- /dev/null +++ b/ets2panda/test/runtime/ets/ensure_not_nullish_expression.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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. + */ + +function test(p: boolean, x: number|null): number{ + let v : object|null = null; + return (p ? v : x)! + 1; +} + +function main(): void{ + let a: number|null = 5; + console.log(test(false, a)); +} \ No newline at end of file -- Gitee