diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index eb1fabd6b92dc1057c1502344c0b782f65628657..2cba5e27931f409090f56853b4dda5312395bded 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -2299,7 +2299,7 @@ ir::OverloadDeclaration *ETSParser::ParseOverloadDeclaration(ir::ModifierFlags m { ValidateOverloadDeclarationModifiers(modifiers); Lexer()->TryEatTokenKeyword(lexer::TokenType::KEYW_OVERLOAD); - auto *overloadName = ExpectIdentifier(false, true, TypeAnnotationParsingOptions::REPORT_ERROR); + auto *overloadName = ExpectIdentifier(false, false, TypeAnnotationParsingOptions::REPORT_ERROR); auto *overloadDef = AllocNode(overloadName->Clone(Allocator(), nullptr)->AsExpression(), modifiers, Allocator()); overloadDef->AddOverloadDeclFlag(ir::OverloadDeclFlags::FUNCTION); diff --git a/ets2panda/parser/ETSparserClasses.cpp b/ets2panda/parser/ETSparserClasses.cpp index 3900e089705afb7adce84692c4f4359900479f21..7a1dfe9f0e4a9c869a8b300d299aa80ee3d20736 100644 --- a/ets2panda/parser/ETSparserClasses.cpp +++ b/ets2panda/parser/ETSparserClasses.cpp @@ -549,7 +549,7 @@ ir::OverloadDeclaration *ETSParser::ParseClassOverloadDeclaration(ir::ModifierFl modifiers |= ir::ModifierFlags::CONSTRUCTOR; Lexer()->NextToken(); } else { - overloadName = ExpectIdentifier(false, true, TypeAnnotationParsingOptions::REPORT_ERROR); + overloadName = ExpectIdentifier(false, false, TypeAnnotationParsingOptions::REPORT_ERROR); } auto *overloadDef = AllocNode(overloadName->Clone(Allocator(), nullptr)->AsExpression(), @@ -1108,7 +1108,7 @@ static lexer::SourcePosition GetEndLoc(ir::BlockStatement *body, ir::ScriptFunct ir::OverloadDeclaration *ETSParser::ParseInterfaceOverload(ir::ModifierFlags modifiers) { ValidateOverloadDeclarationModifiers(modifiers); - auto *overloadName = ExpectIdentifier(false, true, TypeAnnotationParsingOptions::REPORT_ERROR); + auto *overloadName = ExpectIdentifier(false, false, TypeAnnotationParsingOptions::REPORT_ERROR); auto *overloadDef = AllocNode(overloadName->Clone(Allocator(), nullptr)->AsExpression(), modifiers, Allocator()); overloadDef->AddOverloadDeclFlag(ir::OverloadDeclFlags::INTERFACE_METHOD); diff --git a/ets2panda/test/runtime/ets/first_match/soft_keyword.ets b/ets2panda/test/runtime/ets/first_match/soft_keyword.ets new file mode 100644 index 0000000000000000000000000000000000000000..933459d3d8f39a038ccc4c90d3d0a372d0fa8743 --- /dev/null +++ b/ets2panda/test/runtime/ets/first_match/soft_keyword.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ + + +function type1(a: number) { return "invoke1" } +function type2(a: string) { return "invoke2" } +overload type{ type1, type2 } + +class A { + type1(a: number) { return "invoke1" } + type2(a: string) { return "invoke2" } + overload type{ type1, type2 } +} + +interface I { + type1(a: number): string + type2(a: string): string + overload type{ type1, type2 } +} + +function main(): void { + arktest.assertEQ(type(123), "invoke1") + arktest.assertEQ(type("abc"), "invoke2") + + let a = new A(); + arktest.assertEQ(a.type(123), "invoke1") + arktest.assertEQ(a.type("abc"), "invoke2") +}