From e72252ccd688fde59e0d9a69bfd4eb7867ea0598 Mon Sep 17 00:00:00 2001 From: zmw Date: Mon, 14 Jul 2025 21:41:19 +0800 Subject: [PATCH] Fix invalid param in ctr crash Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICM9AM Description: Fix invalid param in ctr crash Signed-off-by: zmw Change-Id: Iec9aea65ba9813af5134acaeffa74f161641d107 --- ...defaultParametersInConstructorLowering.cpp | 7 +++++ .../ets/invalid_param_in_constructor.ets | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/invalid_param_in_constructor.ets diff --git a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp index ed4192d4e8..4bac9aa4dd 100644 --- a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp +++ b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp @@ -27,6 +27,10 @@ static bool HasDefaultParameters(const ir::ScriptFunction *function, util::Diagn bool hasRestParameter = false; for (auto *const it : function->Params()) { + if (it->IsBrokenExpression()) { + continue; + } + auto const *const param = it->AsETSParameterExpression(); if (param->IsRestParameter()) { @@ -307,6 +311,9 @@ bool DefaultParametersInConstructorLowering::PostconditionForModule([[maybe_unus return false; } for (auto *const it : node->AsMethodDefinition()->Function()->Params()) { + if (it->IsBrokenExpression()) { + continue; + } auto const *const param = it->AsETSParameterExpression(); if (param->IsOptional()) { return true; diff --git a/ets2panda/test/ast/compiler/ets/invalid_param_in_constructor.ets b/ets2panda/test/ast/compiler/ets/invalid_param_in_constructor.ets new file mode 100644 index 0000000000..c24f12ba16 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/invalid_param_in_constructor.ets @@ -0,0 +1,28 @@ +/* + * 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 A { + constructor(this.b) { + } +} + +/* @@? 17:16 Error TypeError: Only abstract or native methods can't have body. */ +/* @@? 17:21 Error SyntaxError: The function parameter 'this' must explicitly specify the typeAnnotation. */ +/* @@? 17:21 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@? 17:21 Error SyntaxError: Unexpected token '.'. */ +/* @@? 17:23 Error SyntaxError: Field type annotation expected. */ +/* @@? 17:23 Error SyntaxError: Unexpected token ')'. */ +/* @@? 17:25 Error SyntaxError: Unexpected token '{'. */ +/* @@? 19:1 Error SyntaxError: Unexpected token '}'. */ -- Gitee