diff --git a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp index 3b7466ef9f897a990ee8dd8fc993079a97ad7dc7..960cab515ea8f9b64319c5b83c7c3f3e36de9812 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()) { @@ -315,6 +319,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 0000000000000000000000000000000000000000..c24f12ba1649dff7a22b5774705262a5d6537897 --- /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 '}'. */