From 1e286a2f05b8486a72ea2414c8936bfdcec61542 Mon Sep 17 00:00:00 2001 From: zengzengran Date: Fri, 11 Jul 2025 15:51:49 +0800 Subject: [PATCH] Fixing Invalid override Crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLPA9 Description: IsVariableStatic method directly calls AsETSFunctionType for a variable with Tstype is typeerror, leading to assertion failure and causing compilation crash. Tested-by: ninja tests (passed) ets_testrunner (passed) Signed-off-by: zengzengran # --- ets2panda/checker/ets/helpers.cpp | 3 +- .../compiler/ets/fuzzing_invalid_override.ets | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 ets2panda/test/ast/compiler/ets/fuzzing_invalid_override.ets diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index 35eb70cc91..f970840255 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -61,7 +61,8 @@ bool ETSChecker::IsVariableStatic(const varbinder::Variable *var) { CHECK_NOT_NULL(var); if (var->HasFlag(varbinder::VariableFlags::METHOD)) { - return var->TsType()->AsETSFunctionType()->CallSignatures()[0]->HasSignatureFlag(SignatureFlags::STATIC); + return var->TsType()->IsETSFunctionType() && + var->TsType()->AsETSFunctionType()->CallSignatures()[0]->HasSignatureFlag(SignatureFlags::STATIC); } return var->HasFlag(varbinder::VariableFlags::STATIC); } diff --git a/ets2panda/test/ast/compiler/ets/fuzzing_invalid_override.ets b/ets2panda/test/ast/compiler/ets/fuzzing_invalid_override.ets new file mode 100644 index 0000000000..960aae81e8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/fuzzing_invalid_override.ets @@ -0,0 +1,62 @@ +/* + * 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. + */ + +interface ReadonlyHashMap extends Iterable<[K, V]> { + forEach(callbackFn: (value: V, key: K, map: ReadonlyHashMap) => void): void; +} + +export default class HashMap implements ReadonlyHashMap { + forEach(this.type === XmlDynamicType.START_AND_ATTRIBUTES): void { + this.buckets.forEach((value: V, key: K) => { + callbackFn(value, key, this); + }); + } +} + +/* @@? 20:69 Error TypeError: HashMap is not abstract and does not override abstract method forEach(callbackFn: (value: V, key: K, map: ReadonlyHashMap) => void): void in ReadonlyHashMap */ +/* @@? 21:12 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 21:17 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 21:17 Error SyntaxError: The function parameter 'this' must explicitly specify the typeAnnotation. */ +/* @@? 21:17 Error SyntaxError: Unexpected token '.'. */ +/* @@? 21:23 Error SyntaxError: Unexpected token '==='. */ +/* @@? 21:23 Error SyntaxError: Field type annotation expected. */ +/* @@? 21:41 Error SyntaxError: Field type annotation expected. */ +/* @@? 21:41 Error SyntaxError: Unexpected token '.'. */ +/* @@? 21:62 Error SyntaxError: Field type annotation expected. */ +/* @@? 21:62 Error SyntaxError: Unexpected token ')'. */ +/* @@? 21:63 Error SyntaxError: Unexpected token ':'. */ +/* @@? 21:65 Error SyntaxError: Unexpected token 'void'. */ +/* @@? 21:70 Error SyntaxError: Unexpected token '{'. */ +/* @@? 22:9 Error SyntaxError: Unexpected token 'this'. */ +/* @@? 22:13 Error SyntaxError: Unexpected token '.'. */ +/* @@? 22:21 Error SyntaxError: Field type annotation expected. */ +/* @@? 22:21 Error SyntaxError: Unexpected token '.'. */ +/* @@? 22:30 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 22:30 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 22:30 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 22:30 Error SyntaxError: Unexpected token '('. */ +/* @@? 22:39 Error SyntaxError: Unexpected token ','. */ +/* @@? 22:47 Error SyntaxError: Unexpected token ')'. */ +/* @@? 22:49 Error SyntaxError: Unexpected token '=>'. */ +/* @@? 22:52 Error SyntaxError: Unexpected token '{'. */ +/* @@? 23:23 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 23:24 Error TypeError: The type of parameter 'value' cannot be inferred */ +/* @@? 23:29 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 23:31 Error TypeError: The type of parameter 'key' cannot be inferred */ +/* @@? 23:34 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@? 23:40 Error SyntaxError: The function parameter 'this' must explicitly specify the typeAnnotation. */ +/* @@? 24:10 Error SyntaxError: Unexpected token ')'. */ +/* @@? 25:5 Error SyntaxError: Unexpected token '}'. */ +/* @@? 26:1 Error SyntaxError: Unexpected token '}'. */ -- Gitee