diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index c872c526794a9658968f2ae41148955daca5dc18..cf5245394f48cc394e81c7eec00520fb03c8ed84 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -2009,6 +2009,13 @@ void ETSChecker::CheckForSameSwitchCases(ArenaVector } }; + auto const checkStringEnumType = [this](ir::Expression const *const caseTest, + ETSStringEnumType const *const type) -> void { + if (caseTest->TsType()->AsETSStringEnumType()->IsSameEnumLiteralType(type)) { + ThrowTypeError("Case duplicate", caseTest->Start()); + } + }; + for (size_t caseNum = 0; caseNum < cases->size(); caseNum++) { for (size_t compareCase = caseNum + 1; compareCase < cases->size(); compareCase++) { auto *caseTest = cases->at(caseNum)->Test(); @@ -2023,6 +2030,11 @@ void ETSChecker::CheckForSameSwitchCases(ArenaVector continue; } + if (caseTest->TsType()->IsETSStringEnumType()) { + checkStringEnumType(caseTest, compareCaseTest->TsType()->AsETSStringEnumType()); + continue; + } + if (caseTest->IsIdentifier() || caseTest->IsMemberExpression()) { CheckIdentifierSwitchCase(caseTest, compareCaseTest, cases->at(caseNum)->Start()); continue; diff --git a/ets2panda/test/parser/ets/switch_enum_string_case-expected.txt b/ets2panda/test/parser/ets/switch_enum_string_case-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b99102dc53f0ac5f96a76380886106f13b185b2 --- /dev/null +++ b/ets2panda/test/parser/ets/switch_enum_string_case-expected.txt @@ -0,0 +1,802 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "e1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 20 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "e2", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "e3", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 16, + "column": 40 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "v", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "property": { + "type": "Identifier", + "name": "e3", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "SwitchStatement", + "discriminant": { + "type": "Identifier", + "name": "v", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "cases": [ + { + "type": "SwitchCase", + "test": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "e2", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "consequent": [ + { + "type": "AssertStatement", + "test": { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 21, + "column": 26 + }, + "end": { + "line": 21, + "column": 31 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 21, + "column": 33 + }, + "end": { + "line": 21, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 39 + } + } + }, + { + "type": "SwitchCase", + "test": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "e1", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "consequent": [ + { + "type": "AssertStatement", + "test": { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 31 + } + } + }, + "second": null, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 32 + } + } + }, + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 22, + "column": 33 + }, + "end": { + "line": 22, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 39 + } + } + }, + { + "type": "SwitchCase", + "test": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "e3", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "consequent": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 23, + "column": 20 + }, + "end": { + "line": 23, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 26 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 24, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 26, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/switch_enum_string_case.ets b/ets2panda/test/parser/ets/switch_enum_string_case.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa796ac94d989cc7a64297edf4f32f51ff41f702 --- /dev/null +++ b/ets2panda/test/parser/ets/switch_enum_string_case.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023-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. + */ + +enum Enum {e1 = "A", e2 = "B", e3 = "C"} + +function main() { + let v = Enum.e3 + switch (v) { + case Enum.e2: assert false; break; + case Enum.e1: assert false; break; + case Enum.e3: break; + } +} diff --git a/ets2panda/test/parser/ets/switch_enum_string_case_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_enum_string_case_duplicate-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..01c1ce316b097cc70396b31400eb920539eafd7f --- /dev/null +++ b/ets2panda/test/parser/ets/switch_enum_string_case_duplicate-expected.txt @@ -0,0 +1,747 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 10 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "e1", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 20 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "e2", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "e3", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 16, + "column": 34 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "C", + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 16, + "column": 40 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 41 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "v", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 15 + } + } + }, + "property": { + "type": "Identifier", + "name": "e3", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 16 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 18 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + { + "type": "SwitchStatement", + "discriminant": { + "type": "Identifier", + "name": "v", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "cases": [ + { + "type": "SwitchCase", + "test": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "e1", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 15 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 17 + } + } + }, + "consequent": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 25 + } + } + }, + { + "type": "SwitchCase", + "test": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "e1", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 10 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "consequent": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 25 + } + } + }, + { + "type": "SwitchCase", + "test": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Enum", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 14 + } + } + }, + "property": { + "type": "Identifier", + "name": "e3", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 17 + } + } + }, + "consequent": [ + { + "type": "BreakStatement", + "label": null, + "loc": { + "start": { + "line": 23, + "column": 19 + }, + "end": { + "line": 23, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 25 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 24, + "column": 4 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 26, + "column": 1 + } + } +} +TypeError: Case duplicate [switch_enum_string_case_duplicate.ets:21:10] diff --git a/ets2panda/test/parser/ets/switch_enum_string_case_duplicate.ets b/ets2panda/test/parser/ets/switch_enum_string_case_duplicate.ets new file mode 100644 index 0000000000000000000000000000000000000000..51b6c5a4a9137514d168ab708a03129b72615d40 --- /dev/null +++ b/ets2panda/test/parser/ets/switch_enum_string_case_duplicate.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023-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. + */ + +enum Enum {e1 = "A", e2 = "B", e3 = "C"} + +function main() { + let v = Enum.e3 + switch (v) { + case Enum.e1: break; + case Enum.e1: break; + case Enum.e3: break; + } +}