diff --git a/ets2panda/ets2panda b/ets2panda/ets2panda new file mode 120000 index 0000000000000000000000000000000000000000..c60d228fd0a04b068361b1f8fab3c7f8268010ef --- /dev/null +++ b/ets2panda/ets2panda @@ -0,0 +1 @@ +../../../ets_frontend/ets2panda \ No newline at end of file diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index e4b25915ea843bfd0b9febf3a5945ebebd39ad08..fc9c9c6541b5d74d6cf12cd5facb3b2d8e5b2d3f 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1935,7 +1935,7 @@ ir::Expression *ETSParser::ParseCatchParam() void ETSParser::ParseCatchParamTypeAnnotation([[maybe_unused]] ir::AnnotatedExpression *param) { if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_COLON)) { - LogError(diagnostic::MULTI_CATCH_DEPRECATED); + LogUnexpectedToken(Lexer()->GetToken()); TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::REPORT_ERROR; if (auto *typeAnnotation = ParseTypeAnnotation(&options); typeAnnotation != nullptr) { ES2PANDA_ASSERT(param != nullptr); diff --git a/ets2panda/test/ast/compiler/ets/try_catch.ets b/ets2panda/test/ast/compiler/ets/try_catch.ets new file mode 100644 index 0000000000000000000000000000000000000000..c26583baabab221149ac394b270ced08a66539f3 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/try_catch.ets @@ -0,0 +1,27 @@ +/* + * 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 Fx extends Exception {} +function main(): int { + let exc : Fx = new Fx(); + try { + if (1 == 2) throw exc; + return 0; + } catch (f : Fx) { + return 1; + } +} + +/* @@? 22:18 Error SyntaxError: Unexpected token 'Fx'. */ diff --git a/ets2panda/test/ast/compiler/ts/test-interface5.ts b/ets2panda/test/ast/compiler/ts/test-interface5.ts index b5b547dc485e4ba255660d369c5b6ab2288de0ad..f75fa9652878519cf1721ffd0e1d1b24c1a8ad39 100644 --- a/ets2panda/test/ast/compiler/ts/test-interface5.ts +++ b/ets2panda/test/ast/compiler/ts/test-interface5.ts @@ -15,4 +15,4 @@ interface A { readonly /* @@ label */new(a: number): string }; -/* @@@ label Error SyntaxError: Unexpected token in property key */ +/* @@@ label Error SyntaxError: Unexpected token in property key */ diff --git a/ets2panda/test/ast/compiler/ts/test-type-literal5.ts b/ets2panda/test/ast/compiler/ts/test-type-literal5.ts index 4eeeccc157677798cc70d37474381dc73bf61541..964158265e8689abf842a03432ff5a464ff73fba 100644 --- a/ets2panda/test/ast/compiler/ts/test-type-literal5.ts +++ b/ets2panda/test/ast/compiler/ts/test-type-literal5.ts @@ -15,4 +15,4 @@ var a: { readonly /* @@ label */new (a:number):string }; -/* @@@ label Error SyntaxError: Unexpected token in property key */ +/* @@@ label Error SyntaxError: Unexpected token in property key */ diff --git a/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt b/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt index 399704b9aa35cd712bafe73314e772130d085305..7d08ad5690d04945dbddf837292325617b1ec6b4 100644 --- a/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt +++ b/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt @@ -913,4 +913,4 @@ } } } -Warning: The catch statement with type annotation is deprecated, use catch(e). [catch-soft-keyword.ets:26:19] +SyntaxError: Unexpected token 'Exception'. [catch-soft-keyword.ets:26:19] diff --git a/ets2panda/test/compiler/ets/catchParamScope-expected.txt b/ets2panda/test/compiler/ets/catchParamScope-expected.txt index b1b53cb272f8d2fb8a5dc3d9b7c1a87b5f5bf4bc..c29b4ece7cc260999f63b86d28bdf9d3e961d075 100644 --- a/ets2panda/test/compiler/ets/catchParamScope-expected.txt +++ b/ets2panda/test/compiler/ets/catchParamScope-expected.txt @@ -719,4 +719,4 @@ } } } -Warning: The catch statement with type annotation is deprecated, use catch(e). [catchParamScope.ets:22:25] +SyntaxError: Unexpected token 'Exception'. [catchParamScope.ets:22:25] diff --git a/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt b/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt index b93c660e8315cb04146dde8a413082a652bb9fd4..be50fbf5973d323f0a140b7580ac38a564a58cff 100644 --- a/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt +++ b/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt @@ -435,4 +435,4 @@ } } } -Warning: The catch statement with type annotation is deprecated, use catch(e). [tryDefaultCatches.ets:19:15] +SyntaxError: Unexpected token 'Exception'. [tryDefaultCatches.ets:19:15] diff --git a/ets2panda/test/parser/ets/try_catch-expected.txt b/ets2panda/test/parser/ets/try_catch-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..10994195bfc82541cb4251794787d03edb3d78b3 --- /dev/null +++ b/ets2panda/test/parser/ets/try_catch-expected.txt @@ -0,0 +1,793 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Fx", + "loc": { + "start": { + "line": 16, + "column": 7, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 9, + "program": "try_catch.ets" + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Exception", + "loc": { + "start": { + "line": 16, + "column": 18, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 27, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 18, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 27, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 18, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 27, + "program": "try_catch.ets" + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + }, + "end": { + "line": 16, + "column": 29, + "program": "try_catch.ets" + } + } + }, + "overloads": [], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": null + }, + "end": { + "line": 1, + "column": 1, + "program": null + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 28, + "program": "try_catch.ets" + }, + "end": { + "line": 17, + "column": 9, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1, + "program": "try_catch.ets" + }, + "end": { + "line": 17, + "column": 9, + "program": "try_catch.ets" + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "loc": { + "start": { + "line": 1, + "column": 1, + "program": "try_catch.ets" + }, + "end": { + "line": 1, + "column": 1, + "program": "try_catch.ets" + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "loc": { + "start": { + "line": 17, + "column": 10, + "program": "try_catch.ets" + }, + "end": { + "line": 17, + "column": 14, + "program": "try_catch.ets" + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "loc": { + "start": { + "line": 17, + "column": 10, + "program": "try_catch.ets" + }, + "end": { + "line": 17, + "column": 14, + "program": "try_catch.ets" + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 17, + "column": 18, + "program": "try_catch.ets" + }, + "end": { + "line": 17, + "column": 21, + "program": "try_catch.ets" + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "exc", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fx", + "loc": { + "start": { + "line": 18, + "column": 15, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 17, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 17, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 17, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 12, + "program": "try_catch.ets" + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fx", + "loc": { + "start": { + "line": 18, + "column": 24, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 26, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 26, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 26, + "program": "try_catch.ets" + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 18, + "column": 20, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 29, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 29, + "program": "try_catch.ets" + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 18, + "column": 5, + "program": "try_catch.ets" + }, + "end": { + "line": 18, + "column": 29, + "program": "try_catch.ets" + } + } + }, + { + "type": "TryStatement", + "block": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "BooleanLiteral", + "value": false, + "loc": { + "start": { + "line": 20, + "column": 13, + "program": "try_catch.ets" + }, + "end": { + "line": 20, + "column": 19, + "program": "try_catch.ets" + } + } + }, + "consequent": { + "type": "ThrowStatement", + "argument": { + "type": "Identifier", + "name": "exc", + "loc": { + "start": { + "line": 20, + "column": 27, + "program": "try_catch.ets" + }, + "end": { + "line": 20, + "column": 30, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 21, + "program": "try_catch.ets" + }, + "end": { + "line": 20, + "column": 31, + "program": "try_catch.ets" + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 20, + "column": 9, + "program": "try_catch.ets" + }, + "end": { + "line": 20, + "column": 31, + "program": "try_catch.ets" + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 21, + "column": 16, + "program": "try_catch.ets" + }, + "end": { + "line": 21, + "column": 17, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 9, + "program": "try_catch.ets" + }, + "end": { + "line": 21, + "column": 18, + "program": "try_catch.ets" + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9, + "program": "try_catch.ets" + }, + "end": { + "line": 22, + "column": 6, + "program": "try_catch.ets" + } + } + }, + "handler": [ + { + "type": "CatchClause", + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 23, + "column": 16, + "program": "try_catch.ets" + }, + "end": { + "line": 23, + "column": 17, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 9, + "program": "try_catch.ets" + }, + "end": { + "line": 23, + "column": 18, + "program": "try_catch.ets" + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 22, + "program": "try_catch.ets" + }, + "end": { + "line": 24, + "column": 6, + "program": "try_catch.ets" + } + } + }, + "param": { + "type": "Identifier", + "name": "f", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Fx", + "loc": { + "start": { + "line": 22, + "column": 18, + "program": "try_catch.ets" + }, + "end": { + "line": 22, + "column": 20, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18, + "program": "try_catch.ets" + }, + "end": { + "line": 22, + "column": 20, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 18, + "program": "try_catch.ets" + }, + "end": { + "line": 22, + "column": 20, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 14, + "program": "try_catch.ets" + }, + "end": { + "line": 22, + "column": 15, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7, + "program": "try_catch.ets" + }, + "end": { + "line": 24, + "column": 6, + "program": "try_catch.ets" + } + } + } + ], + "finalizer": null, + "loc": { + "start": { + "line": 19, + "column": 5, + "program": "try_catch.ets" + }, + "end": { + "line": 24, + "column": 6, + "program": "try_catch.ets" + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 22, + "program": "try_catch.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10, + "program": "try_catch.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10, + "program": "try_catch.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "try_catch.ets" + } + } + }, + "overloads": [], + "loc": { + "start": { + "line": 17, + "column": 1, + "program": "try_catch.ets" + }, + "end": { + "line": 25, + "column": 2, + "program": "try_catch.ets" + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": "try_catch.ets" + }, + "end": { + "line": 1, + "column": 1, + "program": "try_catch.ets" + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1, + "program": "try_catch.ets" + }, + "end": { + "line": 1, + "column": 1, + "program": "try_catch.ets" + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1, + "program": "try_catch.ets" + }, + "end": { + "line": 26, + "column": 1, + "program": "try_catch.ets" + } + } +} +SyntaxError: Unexpected token 'Fx'. [try_catch.ets:22:18] diff --git a/ets2panda/test/runtime/ets/CastReference3.ets b/ets2panda/test/runtime/ets/CastReference3.ets index e4c0300b0cd970eeb772cb945c06d95a993a7377..ec83cc3f33f4ff98f141ca4a05ca0695fde16023 100644 --- a/ets2panda/test/runtime/ets/CastReference3.ets +++ b/ets2panda/test/runtime/ets/CastReference3.ets @@ -43,13 +43,15 @@ function main() { { let caught = false; try { - let As: FixedArray = new A[1]; - let Bs = As as FixedArray; - } catch (e: ClassCastError) { - caught = true; + let As: FixedArray = new A[1]; + let Bs = As as FixedArray; } catch (e) { - arktest.assertTrue(false) + if (e instanceof ClassCastError) { + caught = true; + } else { + arktest.assertTrue(false); + } } - arktest.assertTrue(caught) + arktest.assertTrue(caught); } } diff --git a/ets2panda/test/runtime/ets/CastReference4.ets b/ets2panda/test/runtime/ets/CastReference4.ets index 1d6541d0c413ae94b4726de489a02f86a5184261..ae7b57662778effea81cf399c90bcc00cd65a5a5 100644 --- a/ets2panda/test/runtime/ets/CastReference4.ets +++ b/ets2panda/test/runtime/ets/CastReference4.ets @@ -32,10 +32,12 @@ function main() { // Element type in array in accumulator is of incompatible type 'A'. // Instruction 'checkcast' will always throw an exception here. It may be a sign of possible error here. let Bs: FixedArray = Is as FixedArray; - } catch (e: ClassCastError) { - caught = true; } catch (e) { - arktest.assertTrue(false) + if (e instanceof ClassCastError) { + caught = true; + } else { + arktest.assertTrue(false) + } } arktest.assertTrue(caught) diff --git a/ets2panda/test/runtime/ets/Enum3.ets b/ets2panda/test/runtime/ets/Enum3.ets index 150f7e76c6e6928ef87ffbb4a3b84972834b9a4b..659156291b147136b9c846c79438f5f237ae29d7 100644 --- a/ets2panda/test/runtime/ets/Enum3.ets +++ b/ets2panda/test/runtime/ets/Enum3.ets @@ -43,9 +43,11 @@ function main(): void { try { let yellow: Color = Color.getValueOf("Yellow"); arktest.assertTrue(false) - } catch (e: Exception) { - arktest.assertTrue((e as Object).toString().startsWith("No enum constant Color.Yellow")) - } catch (e) {} + } catch (e) { + if (e instanceof Exception) { + arktest.assertTrue((e as Object).toString().startsWith("No enum constant Color.Yellow")) + } + } let one: int = 1; let green = one as Color; @@ -53,9 +55,11 @@ function main(): void { try { let x = 5 as Color; - arktest.assertTrue( false) - } catch (e: Error) { - arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum Color with value 5")) + arktest.assertTrue(false) + } catch (e) { + if (e instanceof Error) { + arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum Color with value 5")) + } } arktest.assertEQ(2 as Color as int, 2) diff --git a/ets2panda/test/runtime/ets/Enum4.ets b/ets2panda/test/runtime/ets/Enum4.ets index bfac7dcebc85a435ecec9896a98e2b461b0d6625..7c5e1f0534d783c6af7feb21fbe802f7fd757dc6 100644 --- a/ets2panda/test/runtime/ets/Enum4.ets +++ b/ets2panda/test/runtime/ets/Enum4.ets @@ -85,10 +85,12 @@ function main(): void { try { let yellow: Color = Color.getValueOf("Yellow"); - arktest.assertTrue( false) - } catch (e: Error) { - arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum constant Color.Yellow")) - } catch (e) {} + arktest.assertTrue(false) + } catch (e) { + if (e instanceof Error) { + arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum constant Color.Yellow")) + } + } ord = 0; let green: Color = ord as Color; @@ -98,8 +100,10 @@ function main(): void { try { let x = 5 as Color; arktest.assertTrue( false) - } catch (e: Error) { - arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum Color with value 5")) + } catch (e) { + if (e instanceof Error) { + arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum Color with value 5")) + } } arktest.assertEQ( 2 as Color as int, 2) @@ -107,6 +111,5 @@ function main(): void { arktest.assertEQ( (Color.Green as int + 2) as Color, (Color.Blue as int - 1) as Color) try { arktest.assertEQ((Color.Green as int + 1) as Color, Color.getValueOf("Red")) - } catch (e) { - } + } catch (e) {} } diff --git a/ets2panda/test/runtime/ets/Enum5.ets b/ets2panda/test/runtime/ets/Enum5.ets index c765271af61c591276d4cd6e795e06b582498f6c..7528e1b08c1fab7236a9aa548b774703be2009d9 100644 --- a/ets2panda/test/runtime/ets/Enum5.ets +++ b/ets2panda/test/runtime/ets/Enum5.ets @@ -77,9 +77,11 @@ function main(): void { try { let yellow: Color = Color.getValueOf("Yellow"); arktest.assertTrue(false) - } catch (e: Exception) { - arktest.assertTrue((e as Object).toString().startsWith("No enum constant Color.Yellow")) - } catch (e) {} + } catch (e) { + if (e instanceof Exception) { + arktest.assertTrue((e as Object).toString().startsWith("No enum constant Color.Yellow")) + } + } ord = "red"; let green: Color = ord as Color; @@ -88,14 +90,15 @@ function main(): void { try { let x = "a" as Color; arktest.assertTrue( false) - } catch (e: Error) { - arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum Color with value a")) + } catch (e) { + if (e instanceof Error) { + arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum Color with value a")) + } } arktest.assertEQ( "red" as Color as string, "red") arktest.assertEQ( Color.Blue as string as Color, Color.Blue) try { arktest.assertEQ( (Color.Green as string) as Color, Color.getValueOf("red")) - } catch (e) { - } + } catch (e) {} } diff --git a/ets2panda/test/runtime/ets/OptionalChains.ets b/ets2panda/test/runtime/ets/OptionalChains.ets index f42438891591830a61ecae41c4d469191e355ea8..ce6c95837105b99ca3d1db874a55e1fa51326743 100644 --- a/ets2panda/test/runtime/ets/OptionalChains.ets +++ b/ets2panda/test/runtime/ets/OptionalChains.ets @@ -19,8 +19,10 @@ function assert_o(v: Object | null | undefined) { arktest.assertTrue(v !== null function assert_npe(f: () => void) { try { f(); - } catch (e: NullPointerError) { + } catch (e) { + if (e instanceof NullPointerError) { return; + } } arktest.assertTrue(false, "npe was not thrown") } diff --git a/ets2panda/test/runtime/ets/SmartCast_08.ets b/ets2panda/test/runtime/ets/SmartCast_08.ets index 0e14d653491caf6d2b6f577265c8b733d75d4c4d..0883a081859707261cd839e502cdacf3b2097b4a 100644 --- a/ets2panda/test/runtime/ets/SmartCast_08.ets +++ b/ets2panda/test/runtime/ets/SmartCast_08.ets @@ -25,10 +25,12 @@ function foo(flag: boolean): int { if (flag) { throw new Error(); } - } catch(ex: NullPointerError) { - z = 2; - } catch(ex) { - w = undefined; + } catch (ex) { + if (ex instanceof NullPointerError) { + z = 2; + } else { + w = undefined; + } } return x + y! + z + w!; diff --git a/ets2panda/test/runtime/ets/UnboxingCheckcast.ets b/ets2panda/test/runtime/ets/UnboxingCheckcast.ets index d7ddb16a64e38e8862efe31fc98e118b161b9e92..d97dffe1855e4137cc8d45a95e6774477f2f004d 100644 --- a/ets2panda/test/runtime/ets/UnboxingCheckcast.ets +++ b/ets2panda/test/runtime/ets/UnboxingCheckcast.ets @@ -33,8 +33,9 @@ function main() { try{ c as double; - } catch (e: ClassCastError){ - } catch(other) { - arktest.assertEQ(1, 0) + } catch (e) { + if (e instanceof ClassCastError) {} else { + arktest.assertEQ(1, 0) + } } } diff --git a/ets2panda/test/runtime/ets/division-by-zero.ets b/ets2panda/test/runtime/ets/division-by-zero.ets index e38756ea60228c21b53cae4b4e7e83a74734afa2..291db8e4198711ae37ab78078aa9a01cf6359c11 100644 --- a/ets2panda/test/runtime/ets/division-by-zero.ets +++ b/ets2panda/test/runtime/ets/division-by-zero.ets @@ -23,29 +23,37 @@ function main() : void { try { let result : int = INT_ONE / INT_ZERO; - } catch (error: ArithmeticError) { - caught_counter++; + } catch (error) { + if (error instanceof ArithmeticError) { + caught_counter++; + } } arktest.assertEQ(caught_counter, 1) try { let result : long = LONG_ONE / LONG_ZERO; - } catch (error: ArithmeticError) { - caught_counter++; + } catch (error) { + if (error instanceof ArithmeticError) { + caught_counter++; + } } arktest.assertEQ(caught_counter, 2) try { let result : int = INT_ONE % INT_ZERO; - } catch (error: ArithmeticError) { - caught_counter++; + } catch (error) { + if (error instanceof ArithmeticError) { + caught_counter++; + } } arktest.assertEQ(caught_counter, 3) try { let result : long = LONG_ONE % LONG_ZERO; - } catch (error: ArithmeticError) { - caught_counter++; + } catch (error) { + if (error instanceof ArithmeticError) { + caught_counter++; + } } arktest.assertEQ(caught_counter, 4) @@ -54,37 +62,49 @@ function main() : void { try { let result : double = DOUBLE_ONE / DOUBLE_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } } try { let result = INT_ONE / DOUBLE_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } } try { let result = DOUBLE_ONE / INT_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } } try { let result : double = DOUBLE_ONE % DOUBLE_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } } try { let result = INT_ONE % DOUBLE_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } } try { let result = DOUBLE_ONE % INT_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } } } diff --git a/ets2panda/test/runtime/ets/finallyClauseThrow.ets b/ets2panda/test/runtime/ets/finallyClauseThrow.ets index 2b9537b10a5f0082fa06ea58bc64e0afea04126f..5d0bbf9e0969c0bcb762c6033600db63c572e5b8 100644 --- a/ets2panda/test/runtime/ets/finallyClauseThrow.ets +++ b/ets2panda/test/runtime/ets/finallyClauseThrow.ets @@ -17,14 +17,17 @@ function main() : int { try { try { throw new Exception(); - } catch (e:Error) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof Error) { + arktest.assertTrue(false); + } } finally { throw new Error(); } - } catch (e:Error) { - } catch (e) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof Error) {} else { + arktest.assertTrue(false) + } } return 0; } \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/generic_Error_class.ets b/ets2panda/test/runtime/ets/generic_Error_class.ets index 50aa86c29d8a809c25b462be3dfa1a89073cb288..3533691896e75a912a01e5e08150ac1cce2764e6 100644 --- a/ets2panda/test/runtime/ets/generic_Error_class.ets +++ b/ets2panda/test/runtime/ets/generic_Error_class.ets @@ -18,12 +18,14 @@ class E extends Error {} function main(): int { try { throw new E(); - } catch (e: E) { - return 0; - } catch (e: E) { - return 0; } catch (e) { - return 0; + if (e instanceof E) { + return 0; + } else if (e instanceof E) { + return 0; + } else { + return 0; + } } } diff --git a/ets2panda/test/runtime/ets/generic_exception.ets b/ets2panda/test/runtime/ets/generic_exception.ets index e5ef48a63f646553b16525d043806002585b72e1..b298b85889cabe226614dedba139361688d5b9d2 100644 --- a/ets2panda/test/runtime/ets/generic_exception.ets +++ b/ets2panda/test/runtime/ets/generic_exception.ets @@ -18,12 +18,14 @@ class E extends Exception {} function main(): int { try { throw new E(); - } catch (e: E) { - return 0; - } catch (e: E) { - return 0; } catch (e) { - return 0; + if (e instanceof E) { + return 0; + } else if (e instanceof E) { + return 0; + } else { + return 0; + } } } diff --git a/ets2panda/test/runtime/ets/member-expression-nullptr.ets b/ets2panda/test/runtime/ets/member-expression-nullptr.ets index f0eeafcc767a9ebd12bdca097c5e7429ab7d2287..24711fe3643e503110e055692caa336d893543b7 100644 --- a/ets2panda/test/runtime/ets/member-expression-nullptr.ets +++ b/ets2panda/test/runtime/ets/member-expression-nullptr.ets @@ -44,8 +44,10 @@ function main(): void { try { let residence = (john as Person).residence; - } catch (e: ClassCastError) { - test = true; + } catch (e) { + if (e instanceof ClassCastError) { + test = true; + } } arktest.assertEQ(test, true) @@ -54,8 +56,10 @@ function main(): void { try { let numbers: int = john!.residence.numberOfRooms; - } catch (e: NullPointerError) { - test = true; + } catch (e) { + if (e instanceof NullPointerError) { + test = true; + } } arktest.assertEQ(test, true) @@ -63,8 +67,10 @@ function main(): void { arktest.assertEQ(test, false) try { let numbers: int = foo() + bar() + john!.residence.numberOfRooms; - } catch (e: NullPointerError) { - test = true; + } catch (e) { + if (e instanceof NullPointerError) { + test = true; + } } arktest.assertEQ(test, true) arktest.assertEQ(a, 2) // foo and bar were evaluated diff --git a/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets b/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets index 353980fef8872f5ef352441052a8aefc8f01b89d..ab8a06edc7a42ac54827c72b38e3a84d48ec5999 100644 --- a/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets +++ b/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets @@ -20,8 +20,10 @@ function main(): void { let catched = false; try { a = new Number[A.length + 2.][4][A.length + 3.00001]; - } catch (e: TypeError) { - catched = true; + } catch (e) { + if (e instanceof TypeError) { + catched = true; + } } arktest.assertTrue(catched) diff --git a/ets2panda/test/runtime/ets/multi-array-new-catched-2.ets b/ets2panda/test/runtime/ets/multi-array-new-catched-2.ets index f518d1b800f8731cc3e75f064a6771df3bf80461..dfc04b8f38101d2ce7b5d562ca0a9edd24c6711e 100644 --- a/ets2panda/test/runtime/ets/multi-array-new-catched-2.ets +++ b/ets2panda/test/runtime/ets/multi-array-new-catched-2.ets @@ -23,8 +23,10 @@ function main(): void { let catched = false; try { a = new Number[baz()][4][A.length + 3.0000]; - } catch (e: TypeError) { - catched = true; + } catch (e) { + if (e instanceof TypeError) { + catched = true; + } } arktest.assertTrue(catched) diff --git a/ets2panda/test/runtime/ets/notNull.ets b/ets2panda/test/runtime/ets/notNull.ets index cf3943bff0f0f3c6fa2177f4c14075298bb0b577..65fe54e6150bf76547f0025557edfa49d7e4fd52 100644 --- a/ets2panda/test/runtime/ets/notNull.ets +++ b/ets2panda/test/runtime/ets/notNull.ets @@ -101,8 +101,10 @@ function testNPE() : void { try { (o as Object | null)!; arktest.assertTrue(false, "this must not be executed") - } catch (ex: NullPointerError) { - npe_caught = true; + } catch (ex) { + if (ex instanceof NullPointerError) { + npe_caught = true; + } } arktest.assertTrue(npe_caught, "NPE must be caught") @@ -110,8 +112,10 @@ function testNPE() : void { try { baz()!; arktest.assertTrue(false, "this must not be executed") - } catch (ex: NullPointerError) { - npe_caught = true; + } catch (ex) { + if (ex instanceof NullPointerError) { + npe_caught = true; + } } arktest.assertTrue(npe_caught, "NPE must be caught") diff --git a/ets2panda/test/runtime/ets/optional-chaining-function-call.ets b/ets2panda/test/runtime/ets/optional-chaining-function-call.ets index b4b6bac3362b531b2c531339cdac4bd756f2e240..0a1e3133c62f47afa32c6d16a341951a2d5b2cba 100644 --- a/ets2panda/test/runtime/ets/optional-chaining-function-call.ets +++ b/ets2panda/test/runtime/ets/optional-chaining-function-call.ets @@ -34,8 +34,10 @@ function foo(a: funcType | null) { let test = false; try { fruit = a!(); - } catch (e: NullPointerError) { - test = true; + } catch (e) { + if (e instanceof NullPointerError) { + test = true; + } } arktest.assertEQ(test, true) diff --git a/ets2panda/test/runtime/ets/overload_declaration/notNull.ets b/ets2panda/test/runtime/ets/overload_declaration/notNull.ets index 837a42a528f0edc9fb2ba1665921c09dd136784b..031d8ee92704897078c8abc8a098c778ec2dce38 100644 --- a/ets2panda/test/runtime/ets/overload_declaration/notNull.ets +++ b/ets2panda/test/runtime/ets/overload_declaration/notNull.ets @@ -103,8 +103,10 @@ function testNPE(): void { try { (o as Object | null)!; arktest.assertTrue(false, "this must not be executed") - } catch (ex: NullPointerError) { - npe_caught = true; + } catch (ex) { + if (ex instanceof NullPointerError) { + npe_caught = true; + } } arktest.assertTrue(npe_caught, "NPE must be caught") @@ -112,8 +114,10 @@ function testNPE(): void { try { baz()!; arktest.assertTrue(false, "this must not be executed") - } catch (ex: NullPointerError) { - npe_caught = true; + } catch (ex) { + if (ex instanceof NullPointerError) { + npe_caught = true; + } } arktest.assertTrue(npe_caught, "NPE must be caught") diff --git a/ets2panda/test/runtime/ets/top_level_02.ets b/ets2panda/test/runtime/ets/top_level_02.ets index bbdf6f16085fac745a3fe7c28b521f4cd420ce79..484bb2b4873f1ea3d4b22c2705895314caac839e 100644 --- a/ets2panda/test/runtime/ets/top_level_02.ets +++ b/ets2panda/test/runtime/ets/top_level_02.ets @@ -37,11 +37,11 @@ try { s += "cba"; q += 5; throw new TestException(); -} -catch (e: TestException) { -} -catch (e) { - arktest.assertTrue(false) +} catch (e) { + if (e instanceof TestException) {} + else { + arktest.assertTrue(false) + } } arktest.assertEQ(q, 8) diff --git a/ets2panda/test/runtime/ets/try-catch-error.ets b/ets2panda/test/runtime/ets/try-catch-error.ets index 5428c1e6c629ad2acc15364a1b43126d491fc0af..efd9a4c0c0b0fbdb3563c5552a6bbe1bd06e8a37 100644 --- a/ets2panda/test/runtime/ets/try-catch-error.ets +++ b/ets2panda/test/runtime/ets/try-catch-error.ets @@ -20,40 +20,48 @@ let catchCode = 0; function main(): void { try { throw new DivideByZeroError(); - } catch (p: DivideByZeroError) { - catchCode = 1; - } catch (p: Error) { - arktest.assertTrue(false) + } catch (p) { + if (p instanceof DivideByZeroError) { + catchCode = 1; + } else if (p instanceof Error) { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 1) try { throw new DivideByZeroError(); - } catch (p: Error) { - catchCode = 2; - } catch (p: DivideByZeroError) { - arktest.assertTrue(false) + } catch (p) { + if (p instanceof Error) { + catchCode = 2; + } else if (p instanceof DivideByZeroError) { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 2) try { throw new TestError(); - } catch (p: TestError) { - catchCode = 3; - } catch (p: Error) { - arktest.assertTrue(false) + } catch (p) { + if (p instanceof TestError) { + catchCode = 3; + } else if (p instanceof Error) { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 3) try { throw new TestError(); - } catch (p: Error) { - catchCode = 4; - } catch (p: TestError) { - arktest.assertTrue(false) + } catch (p) { + if (p instanceof Error) { + catchCode = 4; + } else if (p instanceof TestError) { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 4) diff --git a/ets2panda/test/runtime/ets/try-catch.ets b/ets2panda/test/runtime/ets/try-catch.ets index 9415ba2e5840a644054f27acd1689d61c62b4700..aaa60ef1686681232c0485e0f1d27fdb9889fb49 100644 --- a/ets2panda/test/runtime/ets/try-catch.ets +++ b/ets2panda/test/runtime/ets/try-catch.ets @@ -20,48 +20,56 @@ let catchCode = 0; function main(): void { try { throw new NullPointerError(); - } catch (e: NullPointerError) { - catchCode = 1; - } catch (e: Error) { - arktest.assertTrue(false) } catch (e) { - arktest.assertTrue(false) + if (e instanceof NullPointerError) { + catchCode = 1; + } else if (e instanceof Error) { + arktest.assertTrue(false) + } else { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 1) try { throw new NullPointerError(); - } catch (e: Error) { - catchCode = 2; - } catch (e: NullPointerError) { - arktest.assertTrue(false) } catch (e) { - arktest.assertTrue(false) + if (e instanceof Error) { + catchCode = 2; + } else if (e instanceof NullPointerError) { + arktest.assertTrue(false) + } else { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 2) try { throw new TestException(); - } catch(e: TestException) { - catchCode = 3; - } catch (e: Exception) { - arktest.assertTrue(false) } catch (e) { - arktest.assertTrue(false) + if (e instanceof TestException) { + catchCode = 3; + } else if (e instanceof Exception) { + arktest.assertTrue(false) + } else { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 3) try { throw new TestException(); - } catch (e: Exception) { - catchCode = 4; - } catch (e: TestException) { - arktest.assertTrue(false) } catch (e) { - arktest.assertTrue(false) + if (e instanceof Exception) { + catchCode = 4; + } else if (e instanceof TestException) { + arktest.assertTrue(false) + } else { + arktest.assertTrue(false) + } } arktest.assertEQ(catchCode, 4) diff --git a/ets2panda/test/runtime/ets/union_type_RTE.ets b/ets2panda/test/runtime/ets/union_type_RTE.ets index 0c73ea88d3f91be6dc4b4bba1db151f30d794901..57ff53bc382bc4968f6f2ddffe3bb1df34f91b1f 100644 --- a/ets2panda/test/runtime/ets/union_type_RTE.ets +++ b/ets2panda/test/runtime/ets/union_type_RTE.ets @@ -29,8 +29,10 @@ function main() { try { foo(new A(11) as Object) - } catch (error: ClassCastError) { - caught_counter++ + } catch (error) { + if (error instanceof ClassCastError) { + caught_counter++; + } } arktest.assertEQ(caught_counter, 1) diff --git a/ets2panda/test/unit/public/ast_verifier_check_scope_declaration_test.cpp b/ets2panda/test/unit/public/ast_verifier_check_scope_declaration_test.cpp index c5d4a0d67cbea8e5f0fdb3ce737fb0e1386e37b1..1112e68ff3e3871ad50883d662e71c94bc366987 100644 --- a/ets2panda/test/unit/public/ast_verifier_check_scope_declaration_test.cpp +++ b/ets2panda/test/unit/public/ast_verifier_check_scope_declaration_test.cpp @@ -90,8 +90,10 @@ TEST_F(ASTVerifierTest, TryCatch) try { throw new NullPointerError(); - } catch (e: NullPointerError) { - catchCode = 1; + } catch (e) { + if (e instanceof NullPointerError) { + catchCode = 1; + } } } )";