From 3be3a3656f7868b611bb79a2795b64c54eaa22fc Mon Sep 17 00:00:00 2001 From: zmw Date: Sat, 5 Jul 2025 12:03:02 +0800 Subject: [PATCH] Fix get set type crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICKAY7 Description: Fix get set type crash Signed-off-by: zmw Signed-off-by: tengtengh --- ets2panda/checker/ets/typeCheckingHelpers.cpp | 5 +++++ .../compiler/ets/set_init_without_param.ets | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/set_init_without_param.ets diff --git a/ets2panda/checker/ets/typeCheckingHelpers.cpp b/ets2panda/checker/ets/typeCheckingHelpers.cpp index a077b6024f..4820200af0 100644 --- a/ets2panda/checker/ets/typeCheckingHelpers.cpp +++ b/ets2panda/checker/ets/typeCheckingHelpers.cpp @@ -435,6 +435,11 @@ Type *ETSChecker::GetTypeOfSetterGetter(varbinder::Variable *const var) return propType->FindGetter()->ReturnType(); } + if (propType->FindSetter()->Params().empty()) { + var->SetTsType(GlobalTypeError()); + return GlobalTypeError(); + } + return propType->FindSetter()->Params()[0]->TsType(); } diff --git a/ets2panda/test/ast/compiler/ets/set_init_without_param.ets b/ets2panda/test/ast/compiler/ets/set_init_without_param.ets new file mode 100644 index 0000000000..266f904738 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/set_init_without_param.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + +set a '1;' + +/* @@? 16:1 Error SyntaxError: Extension Setter can only have 2 parameters. */ +/* @@? 16:5 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 16:7 Error SyntaxError: Unexpected token, expected '('. */ +/* @@? 23:1 Error SyntaxError: Expected ')', got 'eos'. */ +/* @@? 23:1 Error SyntaxError: Extension Accessor must have a receiver. */ -- Gitee