From 7f24dd110d31b8c27a40e576df7a5bad0cab345e Mon Sep 17 00:00:00 2001 From: zmw Date: Mon, 8 Sep 2025 16:09:57 +0800 Subject: [PATCH] Fix interface ctor sig error Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICWXAY Description: Fix interface ctor sig error Signed-off-by: zmw --- ets2panda/parser/TypedParser.cpp | 4 +++ .../interface-constructor-signatures_1.ets | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/interface-constructor-signatures_1.ets diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index d7a1834407..86f4690bbb 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -609,6 +609,10 @@ ArenaVector TypedParser::ParseTypeLiteralOrInterfaceBody() LogExpectedToken(lexer::TokenType::PUNCTUATOR_COMMA); } + if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_NEW) { + LogError(diagnostic::ERROR_ARKTS_NO_INTERFACE_CONSTRUCTOR_SIGNATURES); + } + if (Lexer()->GetToken().IsKeyword() && (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_STATIC && Lexer()->GetToken().Type() != lexer::TokenType::KEYW_PRIVATE && Lexer()->GetToken().Type() != lexer::TokenType::KEYW_DEFAULT)) { diff --git a/ets2panda/test/ast/compiler/ets/interface-constructor-signatures_1.ets b/ets2panda/test/ast/compiler/ets/interface-constructor-signatures_1.ets new file mode 100644 index 0000000000..be0a8fb68e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/interface-constructor-signatures_1.ets @@ -0,0 +1,25 @@ +/* + * 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 C { + constructor() { } +} + +interface I { + fn(): boolean; + new(): C; +} + +/* @@? 22:5 Error SyntaxError: Constructor signatures are not supported in interfaces, use methods instead! */ -- Gitee