From 13b624f7c9a20d434dbf098a9cf220ac40a0a7f2 Mon Sep 17 00:00:00 2001 From: ozerovnikita Date: Thu, 4 Apr 2024 16:46:08 +0300 Subject: [PATCH] add error message for interface member initialization Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I96ROK Testing: runner.sh --parser Signed-off-by: ozerovnikita --- ets2panda/parser/TypedParser.cpp | 3 +++ ...terface_member_initialization-expected.txt | 1 + .../ets/interface_member_initialization.ets | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 ets2panda/test/parser/ets/interface_member_initialization-expected.txt create mode 100644 ets2panda/test/parser/ets/interface_member_initialization.ets diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index cdd34f4385..ea49b43578 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -563,6 +563,9 @@ ArenaVector TypedParser::ParseTypeLiteralOrInterface() if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_COMMA && Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { + ThrowSyntaxError("Interface member initialization is prohibited"); + } if (!Lexer()->GetToken().NewLine()) { ThrowSyntaxError("',' expected"); } diff --git a/ets2panda/test/parser/ets/interface_member_initialization-expected.txt b/ets2panda/test/parser/ets/interface_member_initialization-expected.txt new file mode 100644 index 0000000000..bbc8b1c2e4 --- /dev/null +++ b/ets2panda/test/parser/ets/interface_member_initialization-expected.txt @@ -0,0 +1 @@ +SyntaxError: Interface member initialization is prohibited [interface_member_initialization.ets:17:14] diff --git a/ets2panda/test/parser/ets/interface_member_initialization.ets b/ets2panda/test/parser/ets/interface_member_initialization.ets new file mode 100644 index 0000000000..3aae74b02f --- /dev/null +++ b/ets2panda/test/parser/ets/interface_member_initialization.ets @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2024 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 Colors { + Red: int = 1; +} + +function main() +{ + +} -- Gitee