From 134bfea91c97de2c521b1e7e37495bd9e3c7322e Mon Sep 17 00:00:00 2001 From: xingshunxiang Date: Fri, 11 Jul 2025 10:30:56 +0800 Subject: [PATCH] Support IndexType can be int type Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICLL1U?from=project-issue Description: Support IndexType can be int type Reason: Support IndexType can be int type Tests: ninja tests passed tests/tests-u-runner/runner.sh --ets-cts --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-func-tests --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --astchecker --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-runtime --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --parser --no-js --show-progress --build-dir x64.release --processes=all passed Signed-off-by: xingshunxiang --- ets2panda/parser/ETSparser.cpp | 3 ++- .../ast/compiler/ets/DeclareIndexerTest.ets | 7 +++++++ .../ets/interface_ambient_indexer_3.ets | 19 ------------------- 3 files changed, 9 insertions(+), 20 deletions(-) delete mode 100644 ets2panda/test/ast/compiler/ets/interface_ambient_indexer_3.ets diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index 5541ac57d5..fe84a350ef 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2047,7 +2047,8 @@ ir::AstNode *ETSParser::ParseAmbientSignature(const lexer::SourcePosition &start } // eat ":" - if (Lexer()->NextToken(); Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_NUMBER) { + if (Lexer()->NextToken(); Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_NUMBER && + Lexer()->GetToken().KeywordType() != lexer::TokenType::KEYW_INT) { // ambient_indexer_3.ets LogError(diagnostic::INDEX_TYPE_NOT_NUMBER); diff --git a/ets2panda/test/ast/compiler/ets/DeclareIndexerTest.ets b/ets2panda/test/ast/compiler/ets/DeclareIndexerTest.ets index 7cf36bcc8b..4bc211702a 100644 --- a/ets2panda/test/ast/compiler/ets/DeclareIndexerTest.ets +++ b/ets2panda/test/ast/compiler/ets/DeclareIndexerTest.ets @@ -17,6 +17,13 @@ declare class A { [index: number]: string // indexer declaration } +declare class B { + [index: int] : number +} + +declare interface C { + [index :int]: string + } function main () { diff --git a/ets2panda/test/ast/compiler/ets/interface_ambient_indexer_3.ets b/ets2panda/test/ast/compiler/ets/interface_ambient_indexer_3.ets deleted file mode 100644 index fdc663f300..0000000000 --- a/ets2panda/test/ast/compiler/ets/interface_ambient_indexer_3.ets +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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. - */ - -declare interface A { - [index :int]: string - } - /* @@? 17:14 Error SyntaxError: Index type must be number in index signature. */ -- Gitee