From 7361fe5af200c59617906a5a6fa1c0def848869e Mon Sep 17 00:00:00 2001 From: Jozsef Koczo Date: Sat, 5 Jul 2025 22:48:45 +0200 Subject: [PATCH] Remove multiple catch Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IC6D1F Change-Id: I2d4158cb3a1c2724781bb1ed9cfdc27a37146226 Signed-off-by: Jozsef Koczo --- ets2panda/checker/ETSAnalyzer.cpp | 2 +- ets2panda/checker/ets/object.cpp | 3 +- ets2panda/parser/ETSparser.cpp | 1 + .../ast/compiler/ets/throwInFinallyBlock.ets | 4 +- .../ast/compiler/ets/tryCatchErrorFlow.ets | 2 +- .../ets/tryCatchErrorIncorrectParamType.ets | 4 +- .../test/ast/compiler/ets/tryCatchFlow.ets | 4 - .../ets/tryCatchIncorrectParamType.ets | 5 +- .../ast/compiler/ets/tryCatchMissingParam.ets | 2 +- .../ets/FixedArray/InvalidStatements3.ets | 4 +- .../ets/FixedArray/MultipleParserErrors.ets | 4 +- .../ast/parser/ets/InvalidStatements1.ets | 2 +- .../ast/parser/ets/InvalidStatements3.ets | 4 +- .../ast/parser/ets/MultipleParserErrors.ets | 4 +- .../parser/ets/dynmicImportUnimplemented.ets | 2 +- .../parser/ets/illegal_line_after_throw.ets | 2 +- .../test/ast/parser/ets/try_catch_alive_1.ets | 12 +- .../test/ast/parser/ets/try_catch_alive_4.ets | 9 +- .../test/ast/parser/ets/try_catch_alive_5.ets | 12 +- .../ast/parser/ets/unexpected_token_18.ets | 3 +- .../ast/parser/ets/unexpected_token_20.ets | 3 +- .../ast/parser/ets/unexpected_token_8.ets | 3 +- .../test/ast/parser/ts/unexpected_token_1.ts | 2 +- .../test/ast/parser/ts/unexpected_token_2.ts | 2 +- ets2panda/test/benchmarks/bench_1.ets | 10 +- .../ets/catch-soft-keyword-expected.txt | 49 +------- .../test/compiler/ets/catch-soft-keyword.ets | 2 +- .../compiler/ets/catchParamScope-expected.txt | 67 ++--------- .../test/compiler/ets/catchParamScope.ets | 4 +- .../ets/throwInCatchClause3-expected.txt | 22 ++-- .../test/compiler/ets/throwInCatchClause3.ets | 4 +- .../ets/throwInFinallyBlock1-expected.txt | 24 ++-- .../compiler/ets/throwInFinallyBlock1.ets | 6 +- .../ets/throwInTryStatement-expected.txt | 12 +- .../test/compiler/ets/throwInTryStatement.ets | 2 +- .../ets/tryCatchMissingParamType-expected.txt | 12 +- .../compiler/ets/tryCatchMissingParamType.ets | 2 +- .../ets/tryDefaultCatches-expected.txt | 109 ++---------------- .../test/compiler/ets/tryDefaultCatches.ets | 2 - ets2panda/test/runtime/ets/CastReference3.ets | 4 +- ets2panda/test/runtime/ets/CastReference4.ets | 4 +- ets2panda/test/runtime/ets/Enum3.ets | 14 ++- ets2panda/test/runtime/ets/Enum4.ets | 10 +- ets2panda/test/runtime/ets/Enum5.ets | 14 ++- ets2panda/test/runtime/ets/OptionalChains.ets | 2 +- ets2panda/test/runtime/ets/SmartCast_08.ets | 8 +- .../test/runtime/ets/UnboxingCheckcast.ets | 8 +- .../test/runtime/ets/array-new-catched.ets | 6 +- .../test/runtime/ets/division-by-zero.ets | 78 +++++++++---- .../ets/finallyCatchExecutedNormally.ets | 2 +- .../test/runtime/ets/finallyClauseThrow.ets | 10 +- .../runtime/ets/finallyExecutedAbruptly.ets | 6 +- .../test/runtime/ets/generic_Error_class.ets | 4 - .../test/runtime/ets/generic_exception.ets | 6 +- .../runtime/ets/member-expression-nullptr.ets | 8 +- .../runtime/ets/multi-array-new-catched-1.ets | 12 +- .../runtime/ets/multi-array-new-catched-2.ets | 6 +- ets2panda/test/runtime/ets/notNull.ets | 4 +- .../runtime/ets/nullishTypeCodesamples.ets | 4 +- .../ets/optional-chaining-function-call.ets | 2 +- .../ets/overload_declaration/notNull.ets | 12 +- .../runtime/ets/signature_match_lambda.ets | 5 +- ets2panda/test/runtime/ets/top_level_02.ets | 9 +- .../test/runtime/ets/try-catch-error.ets | 41 ++++--- .../test/runtime/ets/try-catch-no-param.ets | 4 +- ets2panda/test/runtime/ets/try-catch.ets | 50 ++++---- ets2panda/test/runtime/ets/union_type_RTE.ets | 6 +- ..._verifier_check_scope_declaration_test.cpp | 2 +- 68 files changed, 312 insertions(+), 451 deletions(-) diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 74631ae976..89bd2fd34a 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -56,7 +56,7 @@ checker::Type *ETSAnalyzer::Check(ir::CatchClause *st) const checker::Type *catchParamAnnotationType = paramIdent->TypeAnnotation()->GetType(checker); exceptionType = checker->CheckExceptionOrErrorType(catchParamAnnotationType, st->Param()->Start()); } else { - exceptionType = checker->GlobalETSObjectType(); + exceptionType = checker->GlobalBuiltinErrorType(); } paramIdent->Variable()->SetTsType(exceptionType); } diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 63b773041d..acf982878b 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1860,8 +1860,7 @@ void ETSChecker::CheckCyclicConstructorCall(Signature *signature) ETSObjectType *ETSChecker::CheckExceptionOrErrorType(checker::Type *type, const lexer::SourcePosition pos) { ES2PANDA_ASSERT(type != nullptr); - if (!type->IsETSObjectType() || (!Relation()->IsAssignableTo(type, GlobalBuiltinExceptionType()) && - !Relation()->IsAssignableTo(type, GlobalBuiltinErrorType()))) { + if (!type->IsETSObjectType() || !Relation()->IsAssignableTo(type, GlobalBuiltinErrorType())) { LogError(diagnostic::CATCH_OR_THROW_OF_INVALID_TYPE, {compiler::Signatures::BUILTIN_EXCEPTION_CLASS, compiler::Signatures::BUILTIN_ERROR_CLASS}, pos); return GlobalETSObjectType(); diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index d997007463..3f5ad30b53 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -1910,6 +1910,7 @@ ir::Expression *ETSParser::ParseCatchParam() void ETSParser::ParseCatchParamTypeAnnotation([[maybe_unused]] ir::AnnotatedExpression *param) { if (Lexer()->TryEatTokenType(lexer::TokenType::PUNCTUATOR_COLON)) { + LogSyntaxError("catch type annotation was removed from the spec"); TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::REPORT_ERROR; if (auto *typeAnnotation = ParseTypeAnnotation(&options); typeAnnotation != nullptr) { ES2PANDA_ASSERT(param != nullptr); diff --git a/ets2panda/test/ast/compiler/ets/throwInFinallyBlock.ets b/ets2panda/test/ast/compiler/ets/throwInFinallyBlock.ets index 2bb53db77e..d75a72da75 100644 --- a/ets2panda/test/ast/compiler/ets/throwInFinallyBlock.ets +++ b/ets2panda/test/ast/compiler/ets/throwInFinallyBlock.ets @@ -16,10 +16,10 @@ function main(): void { try { try { - throw new Exception(); + throw new Error(); } catch (e) {} finally /* @@ label */{ - throw new Exception(); + throw new Error(); } } catch (e) {} } diff --git a/ets2panda/test/ast/compiler/ets/tryCatchErrorFlow.ets b/ets2panda/test/ast/compiler/ets/tryCatchErrorFlow.ets index 1b0e6ff817..4efd4a36f8 100644 --- a/ets2panda/test/ast/compiler/ets/tryCatchErrorFlow.ets +++ b/ets2panda/test/ast/compiler/ets/tryCatchErrorFlow.ets @@ -18,7 +18,7 @@ function main(): void { throw new DivideByZeroError(); } catch (p){ //Do something. - } /* @@ label */catch (p: DivideByZeroError) { + } /* @@ label */catch (p) { //Do something. } } diff --git a/ets2panda/test/ast/compiler/ets/tryCatchErrorIncorrectParamType.ets b/ets2panda/test/ast/compiler/ets/tryCatchErrorIncorrectParamType.ets index 466b07dfcb..7bc813976e 100644 --- a/ets2panda/test/ast/compiler/ets/tryCatchErrorIncorrectParamType.ets +++ b/ets2panda/test/ast/compiler/ets/tryCatchErrorIncorrectParamType.ets @@ -16,9 +16,7 @@ function main(): void { try { throw new Error(); - } catch (/* @@ label */p: Object) { + } catch (/* @@ label */p) { //Do something. } } - -/* @@@ label Error TypeError: Argument must be an instance of 'Exception' or 'Error' */ diff --git a/ets2panda/test/ast/compiler/ets/tryCatchFlow.ets b/ets2panda/test/ast/compiler/ets/tryCatchFlow.ets index e7ab397a89..b64f40fc66 100644 --- a/ets2panda/test/ast/compiler/ets/tryCatchFlow.ets +++ b/ets2panda/test/ast/compiler/ets/tryCatchFlow.ets @@ -18,9 +18,5 @@ function main(): void { //Exception occures here. } catch (e) { //Do something. - } /* @@ label */catch (e: NullPointerError) { - //Do something. } } - -/* @@@ label Error TypeError: Default catch clause should be the last in the try statement */ diff --git a/ets2panda/test/ast/compiler/ets/tryCatchIncorrectParamType.ets b/ets2panda/test/ast/compiler/ets/tryCatchIncorrectParamType.ets index 1dd8994ce2..c10c887e30 100644 --- a/ets2panda/test/ast/compiler/ets/tryCatchIncorrectParamType.ets +++ b/ets2panda/test/ast/compiler/ets/tryCatchIncorrectParamType.ets @@ -16,8 +16,7 @@ function main(): void { try { //Exception occures here. - } catch (/* @@ label */e: Object) { + } catch (/* @@ label */e) { //Do something. } -} -/* @@@ label Error TypeError: Argument must be an instance of 'Exception' or 'Error' */ +} \ No newline at end of file diff --git a/ets2panda/test/ast/compiler/ets/tryCatchMissingParam.ets b/ets2panda/test/ast/compiler/ets/tryCatchMissingParam.ets index b2f1731f60..ed8c64227c 100644 --- a/ets2panda/test/ast/compiler/ets/tryCatchMissingParam.ets +++ b/ets2panda/test/ast/compiler/ets/tryCatchMissingParam.ets @@ -15,7 +15,7 @@ function main(): void { try { - throw new Exception(); + throw new Error(); } catch (/* @@ label */^) { //Do something. } diff --git a/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets b/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets index ef5fb16052..8315e7889c 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/InvalidStatements3.ets @@ -15,7 +15,7 @@ try { let x = 77 -} catch(a: exception) +} catch(a) } try @@ -41,8 +41,6 @@ function foo() { for (let i = 1 in [0, 1, 2]) {} -/* @@? 18:9 Error TypeError: Argument must be an instance of 'Exception' or 'Error' */ -/* @@? 18:12 Error TypeError: Cannot find type 'exception'. */ /* @@? 19:1 Error SyntaxError: Expected '{', got '}'. */ /* @@? 22:5 Error SyntaxError: Expected '{', got 'let'. */ /* @@? 23:11 Error SyntaxError: Expected '{', got '('. */ diff --git a/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets b/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets index bf3c5717b9..12deda907f 100644 --- a/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets +++ b/ets2panda/test/ast/parser/ets/FixedArray/MultipleParserErrors.ets @@ -128,12 +128,12 @@ declare function addResult(): number; function main(): void { try { - throw new Exception(); + throw new Error(); } catch () { //Do something. } try { - throw new Exception(); + throw new Error(); } catch (e = 0) { //Do something. } diff --git a/ets2panda/test/ast/parser/ets/InvalidStatements1.ets b/ets2panda/test/ast/parser/ets/InvalidStatements1.ets index a0a247f919..07c11ed802 100644 --- a/ets2panda/test/ast/parser/ets/InvalidStatements1.ets +++ b/ets2panda/test/ast/parser/ets/InvalidStatements1.ets @@ -34,7 +34,7 @@ function f() { try let x: number = 89 -} catch(a: Exception) { +} catch(a) { } try x: number; diff --git a/ets2panda/test/ast/parser/ets/InvalidStatements3.ets b/ets2panda/test/ast/parser/ets/InvalidStatements3.ets index 308ab7542c..df0218f8da 100644 --- a/ets2panda/test/ast/parser/ets/InvalidStatements3.ets +++ b/ets2panda/test/ast/parser/ets/InvalidStatements3.ets @@ -15,7 +15,7 @@ try { let x = 77 -} catch(a: exception) +} catch(a) } try @@ -41,8 +41,6 @@ function foo() { for (let i = 1 in [0, 1, 2]) {} -/* @@? 18:9 Error TypeError: Argument must be an instance of 'Exception' or 'Error' */ -/* @@? 18:12 Error TypeError: Cannot find type 'exception'. */ /* @@? 19:1 Error SyntaxError: Expected '{', got '}'. */ /* @@? 22:5 Error SyntaxError: Expected '{', got 'let'. */ /* @@? 23:11 Error SyntaxError: Expected '{', got '('. */ diff --git a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets index 134fd0804f..bf78874c05 100644 --- a/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets +++ b/ets2panda/test/ast/parser/ets/MultipleParserErrors.ets @@ -128,12 +128,12 @@ declare function addResult(): number; function main(): void { try { - throw new Exception(); + throw new Error(); } catch () { //Do something. } try { - throw new Exception(); + throw new Error(); } catch (e = 0) { //Do something. } diff --git a/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets b/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets index 089ace2f22..afa9029069 100644 --- a/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets +++ b/ets2panda/test/ast/parser/ets/dynmicImportUnimplemented.ets @@ -20,7 +20,7 @@ function main() { .catch((a: object | null | undefined): never => { throw a as Error }) - } catch (e: Error) { + } catch (e) { arktest.assertEQ(e.message, "Dynamic import is not supported") return } diff --git a/ets2panda/test/ast/parser/ets/illegal_line_after_throw.ets b/ets2panda/test/ast/parser/ets/illegal_line_after_throw.ets index 92ab4b4dd3..de62283798 100644 --- a/ets2panda/test/ast/parser/ets/illegal_line_after_throw.ets +++ b/ets2panda/test/ast/parser/ets/illegal_line_after_throw.ets @@ -17,7 +17,7 @@ try { } -catch(e: Error) +catch(e) { } diff --git a/ets2panda/test/ast/parser/ets/try_catch_alive_1.ets b/ets2panda/test/ast/parser/ets/try_catch_alive_1.ets index ed9a71e41b..7bf5655f13 100644 --- a/ets2panda/test/ast/parser/ets/try_catch_alive_1.ets +++ b/ets2panda/test/ast/parser/ets/try_catch_alive_1.ets @@ -36,10 +36,14 @@ function foo2(): int { function foo3(): int { try { return 0; - } catch (e: ArithmeticError) { - return 1; - } catch (e: ClassCastError) { - return 2; + } catch (e) { + if (e instanceof ArithmeticError) { + return 1; + } else if (e instanceof ClassCastError) { + return 2; + } else { + return 3; + } } } diff --git a/ets2panda/test/ast/parser/ets/try_catch_alive_4.ets b/ets2panda/test/ast/parser/ets/try_catch_alive_4.ets index 902d8511e6..a2bab24fdd 100644 --- a/ets2panda/test/ast/parser/ets/try_catch_alive_4.ets +++ b/ets2panda/test/ast/parser/ets/try_catch_alive_4.ets @@ -16,10 +16,11 @@ function /* @@ label */foo(): int { try { return 0; - } catch (e: ArithmeticError) { - - } catch (e: ClassCastError) { - return 2; + } catch (e) { + if (e instanceof ArithmeticError) { + }else if (e instanceof ClassCastError) { + return 2; + } } } diff --git a/ets2panda/test/ast/parser/ets/try_catch_alive_5.ets b/ets2panda/test/ast/parser/ets/try_catch_alive_5.ets index efd161568c..f2328e1f53 100644 --- a/ets2panda/test/ast/parser/ets/try_catch_alive_5.ets +++ b/ets2panda/test/ast/parser/ets/try_catch_alive_5.ets @@ -16,11 +16,13 @@ function foo(): int { try { return 0; - } catch (e: ArithmeticError) { - return 1; - /* @@ label */let a = 2; // unreachable statement - } catch (e: ClassCastError) { - return 2; + } catch (e) { + if (e instanceof ArithmeticError) { + return 1; + /* @@ label */let a = 2; // unreachable statement + } else { + return 2; + } } } diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_18.ets b/ets2panda/test/ast/parser/ets/unexpected_token_18.ets index 1cfd153d5a..9ca9cf1006 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_18.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_18.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -try {} catch (e: number) /* @@ label */} +try {} catch (e) /* @@ label */} -/* @@? 16:15 Error TypeError: Argument must be an instance of 'Exception' or 'Error' */ /* @@@ label Error SyntaxError: Expected '{', got '}'. */ diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_20.ets b/ets2panda/test/ast/parser/ets/unexpected_token_20.ets index c6d1838c2d..916eadf031 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_20.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_20.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -try {} catch /* @@ label */e: number) {} finally {} +try {} catch /* @@ label */e) {} finally {} /* @@@ label Error SyntaxError: Expected '(', got 'identification literal'. */ -/* @@? 16:28 Error TypeError: Argument must be an instance of 'Exception' or 'Error' */ diff --git a/ets2panda/test/ast/parser/ets/unexpected_token_8.ets b/ets2panda/test/ast/parser/ets/unexpected_token_8.ets index fcef5ef022..0e1150386e 100644 --- a/ets2panda/test/ast/parser/ets/unexpected_token_8.ets +++ b/ets2panda/test/ast/parser/ets/unexpected_token_8.ets @@ -15,7 +15,6 @@ try { -} catch (e: number /* @@ label1 */{} +} catch (e /* @@ label1 */{} -/* @@? 18:10 Error TypeError: Argument must be an instance of 'Exception' or 'Error' */ /* @@@ label1 Error SyntaxError: Expected ')', got '{'. */ diff --git a/ets2panda/test/ast/parser/ts/unexpected_token_1.ts b/ets2panda/test/ast/parser/ts/unexpected_token_1.ts index 95d73ea9c1..2f1e7898c4 100644 --- a/ets2panda/test/ast/parser/ts/unexpected_token_1.ts +++ b/ets2panda/test/ast/parser/ts/unexpected_token_1.ts @@ -14,6 +14,6 @@ */ -try {} catch (e: Error /* @@ label */{} finally {} +try {} catch (e /* @@ label */{} finally {} /* @@@ label Error SyntaxError: Unexpected token '{', expected ')'. */ diff --git a/ets2panda/test/ast/parser/ts/unexpected_token_2.ts b/ets2panda/test/ast/parser/ts/unexpected_token_2.ts index 31b139aadf..a58981b7a5 100644 --- a/ets2panda/test/ast/parser/ts/unexpected_token_2.ts +++ b/ets2panda/test/ast/parser/ts/unexpected_token_2.ts @@ -14,6 +14,6 @@ */ -try {} catch (e: Error) {} finally /* @@ label */} +try {} catch (e) {} finally /* @@ label */} /* @@@ label Error SyntaxError: Expected '{', got '}'. */ diff --git a/ets2panda/test/benchmarks/bench_1.ets b/ets2panda/test/benchmarks/bench_1.ets index a200b8c29d..5f84b1220e 100644 --- a/ets2panda/test/benchmarks/bench_1.ets +++ b/ets2panda/test/benchmarks/bench_1.ets @@ -415,7 +415,7 @@ function assert_o5(v: Object | null | undefined) { arktest.assertTrue(v !== null function assert_npe5(f: () => void) { try { f(); - } catch (e: NullPointerError) { + } catch (e) { return; } arktest.assertTrue(false, "npe was not thrown") @@ -1047,10 +1047,12 @@ function foo37(flag37: boolean): int { if (flag37) { throw new Error(); } - } catch(ex: NullPointerError) { - z = 2; } catch(ex) { - w = undefined; + if (ex instanceof NullPointerError) { + z = 2; + } else { + w = undefined; + } } return x + y! + z + w!; diff --git a/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt b/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt index 00b03aa72a..a298a27c18 100644 --- a/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt +++ b/ets2panda/test/compiler/ets/catch-soft-keyword-expected.txt @@ -842,7 +842,7 @@ "loc": { "start": { "line": 26, - "column": 30, + "column": 19, "program": "catch-soft-keyword.ets" }, "end": { @@ -855,53 +855,6 @@ "param": { "type": "Identifier", "name": "catch", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Exception", - "decorators": [], - "loc": { - "start": { - "line": 26, - "column": 19, - "program": "catch-soft-keyword.ets" - }, - "end": { - "line": 26, - "column": 28, - "program": "catch-soft-keyword.ets" - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 19, - "program": "catch-soft-keyword.ets" - }, - "end": { - "line": 26, - "column": 29, - "program": "catch-soft-keyword.ets" - } - } - }, - "loc": { - "start": { - "line": 26, - "column": 19, - "program": "catch-soft-keyword.ets" - }, - "end": { - "line": 26, - "column": 29, - "program": "catch-soft-keyword.ets" - } - } - }, "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/compiler/ets/catch-soft-keyword.ets b/ets2panda/test/compiler/ets/catch-soft-keyword.ets index 4b9a3fce73..989e9696a0 100644 --- a/ets2panda/test/compiler/ets/catch-soft-keyword.ets +++ b/ets2panda/test/compiler/ets/catch-soft-keyword.ets @@ -23,6 +23,6 @@ class cls { function foo(): void { let catch: int = 5; try { - } catch (catch: Exception) { + } catch (catch) { } } diff --git a/ets2panda/test/compiler/ets/catchParamScope-expected.txt b/ets2panda/test/compiler/ets/catchParamScope-expected.txt index c2a99cefe1..83e909c8f3 100644 --- a/ets2panda/test/compiler/ets/catchParamScope-expected.txt +++ b/ets2panda/test/compiler/ets/catchParamScope-expected.txt @@ -190,7 +190,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Object", + "name": "Error", "decorators": [], "loc": { "start": { @@ -200,7 +200,7 @@ }, "end": { "line": 16, - "column": 30, + "column": 29, "program": "catchParamScope.ets" } } @@ -213,7 +213,7 @@ }, "end": { "line": 16, - "column": 31, + "column": 30, "program": "catchParamScope.ets" } } @@ -226,7 +226,7 @@ }, "end": { "line": 16, - "column": 31, + "column": 30, "program": "catchParamScope.ets" } } @@ -240,7 +240,7 @@ }, "end": { "line": 16, - "column": 31, + "column": 30, "program": "catchParamScope.ets" } } @@ -253,7 +253,7 @@ }, "end": { "line": 16, - "column": 31, + "column": 30, "program": "catchParamScope.ets" } } @@ -264,12 +264,12 @@ "loc": { "start": { "line": 16, - "column": 33, + "column": 32, "program": "catchParamScope.ets" }, "end": { "line": 16, - "column": 37, + "column": 36, "program": "catchParamScope.ets" } } @@ -280,7 +280,7 @@ "loc": { "start": { "line": 16, - "column": 38, + "column": 37, "program": "catchParamScope.ets" }, "end": { @@ -573,7 +573,7 @@ "loc": { "start": { "line": 22, - "column": 36, + "column": 25, "program": "catchParamScope.ets" }, "end": { @@ -586,53 +586,6 @@ "param": { "type": "Identifier", "name": "error", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Exception", - "decorators": [], - "loc": { - "start": { - "line": 22, - "column": 25, - "program": "catchParamScope.ets" - }, - "end": { - "line": 22, - "column": 34, - "program": "catchParamScope.ets" - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25, - "program": "catchParamScope.ets" - }, - "end": { - "line": 22, - "column": 35, - "program": "catchParamScope.ets" - } - } - }, - "loc": { - "start": { - "line": 22, - "column": 25, - "program": "catchParamScope.ets" - }, - "end": { - "line": 22, - "column": 35, - "program": "catchParamScope.ets" - } - } - }, "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/compiler/ets/catchParamScope.ets b/ets2panda/test/compiler/ets/catchParamScope.ets index c5e1ac85c4..2dbd3ee7ab 100644 --- a/ets2panda/test/compiler/ets/catchParamScope.ets +++ b/ets2panda/test/compiler/ets/catchParamScope.ets @@ -13,13 +13,13 @@ * limitations under the License. */ -function reject(error: Object): void { +function reject(error: Error): void { } function main(): void { let fn: () => void = (): void => { try { - } catch (error: Exception) { + } catch (error) { reject(error); } } diff --git a/ets2panda/test/compiler/ets/throwInCatchClause3-expected.txt b/ets2panda/test/compiler/ets/throwInCatchClause3-expected.txt index 464bf819e4..c023ead580 100644 --- a/ets2panda/test/compiler/ets/throwInCatchClause3-expected.txt +++ b/ets2panda/test/compiler/ets/throwInCatchClause3-expected.txt @@ -323,7 +323,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Exception", + "name": "Error", "decorators": [], "loc": { "start": { @@ -333,7 +333,7 @@ }, "end": { "line": 19, - "column": 32, + "column": 28, "program": "throwInCatchClause3.ets" } } @@ -346,7 +346,7 @@ }, "end": { "line": 19, - "column": 33, + "column": 29, "program": "throwInCatchClause3.ets" } } @@ -359,7 +359,7 @@ }, "end": { "line": 19, - "column": 33, + "column": 29, "program": "throwInCatchClause3.ets" } } @@ -373,7 +373,7 @@ }, "end": { "line": 19, - "column": 35, + "column": 31, "program": "throwInCatchClause3.ets" } } @@ -386,7 +386,7 @@ }, "end": { "line": 19, - "column": 35, + "column": 31, "program": "throwInCatchClause3.ets" } } @@ -438,7 +438,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Exception", + "name": "Error", "decorators": [], "loc": { "start": { @@ -448,7 +448,7 @@ }, "end": { "line": 21, - "column": 33, + "column": 29, "program": "throwInCatchClause3.ets" } } @@ -461,7 +461,7 @@ }, "end": { "line": 21, - "column": 34, + "column": 30, "program": "throwInCatchClause3.ets" } } @@ -474,7 +474,7 @@ }, "end": { "line": 21, - "column": 34, + "column": 30, "program": "throwInCatchClause3.ets" } } @@ -500,7 +500,7 @@ }, "end": { "line": 21, - "column": 34, + "column": 30, "program": "throwInCatchClause3.ets" } } diff --git a/ets2panda/test/compiler/ets/throwInCatchClause3.ets b/ets2panda/test/compiler/ets/throwInCatchClause3.ets index f674939d0a..d23ebfc9ff 100644 --- a/ets2panda/test/compiler/ets/throwInCatchClause3.ets +++ b/ets2panda/test/compiler/ets/throwInCatchClause3.ets @@ -16,9 +16,9 @@ function TestFunc(): void { try { try { - throw new Exception(); + throw new Error(); } catch (e) { - throw e as Exception; + throw e as Error; } } catch (e) { //Handle the exception. diff --git a/ets2panda/test/compiler/ets/throwInFinallyBlock1-expected.txt b/ets2panda/test/compiler/ets/throwInFinallyBlock1-expected.txt index b02aacc5c6..289f4e3148 100644 --- a/ets2panda/test/compiler/ets/throwInFinallyBlock1-expected.txt +++ b/ets2panda/test/compiler/ets/throwInFinallyBlock1-expected.txt @@ -212,7 +212,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Exception", + "name": "Error", "decorators": [], "loc": { "start": { @@ -222,7 +222,7 @@ }, "end": { "line": 18, - "column": 24, + "column": 20, "program": "throwInFinallyBlock1.ets" } } @@ -235,7 +235,7 @@ }, "end": { "line": 18, - "column": 25, + "column": 21, "program": "throwInFinallyBlock1.ets" } } @@ -248,7 +248,7 @@ }, "end": { "line": 18, - "column": 25, + "column": 21, "program": "throwInFinallyBlock1.ets" } } @@ -386,7 +386,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Exception", + "name": "Error", "decorators": [], "loc": { "start": { @@ -396,7 +396,7 @@ }, "end": { "line": 24, - "column": 28, + "column": 24, "program": "throwInFinallyBlock1.ets" } } @@ -409,7 +409,7 @@ }, "end": { "line": 24, - "column": 29, + "column": 25, "program": "throwInFinallyBlock1.ets" } } @@ -422,7 +422,7 @@ }, "end": { "line": 24, - "column": 29, + "column": 25, "program": "throwInFinallyBlock1.ets" } } @@ -622,7 +622,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Exception", + "name": "Error", "decorators": [], "loc": { "start": { @@ -632,7 +632,7 @@ }, "end": { "line": 30, - "column": 26, + "column": 22, "program": "throwInFinallyBlock1.ets" } } @@ -645,7 +645,7 @@ }, "end": { "line": 30, - "column": 27, + "column": 23, "program": "throwInFinallyBlock1.ets" } } @@ -658,7 +658,7 @@ }, "end": { "line": 30, - "column": 27, + "column": 23, "program": "throwInFinallyBlock1.ets" } } diff --git a/ets2panda/test/compiler/ets/throwInFinallyBlock1.ets b/ets2panda/test/compiler/ets/throwInFinallyBlock1.ets index 8325db3372..98907280d1 100644 --- a/ets2panda/test/compiler/ets/throwInFinallyBlock1.ets +++ b/ets2panda/test/compiler/ets/throwInFinallyBlock1.ets @@ -15,19 +15,19 @@ function main(): void { try { - throw new Exception() + throw new Error() } catch (e) { try {} catch (e) {} finally { try { - throw new Exception() + throw new Error() } catch (e) {} } } finally { try { - throw new Exception() + throw new Error() } catch (e) {} } } diff --git a/ets2panda/test/compiler/ets/throwInTryStatement-expected.txt b/ets2panda/test/compiler/ets/throwInTryStatement-expected.txt index fcf93a23b7..1c0aa042bf 100644 --- a/ets2panda/test/compiler/ets/throwInTryStatement-expected.txt +++ b/ets2panda/test/compiler/ets/throwInTryStatement-expected.txt @@ -212,7 +212,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Exception", + "name": "Error", "decorators": [], "loc": { "start": { @@ -222,7 +222,7 @@ }, "end": { "line": 18, - "column": 24, + "column": 20, "program": "throwInTryStatement.ets" } } @@ -235,7 +235,7 @@ }, "end": { "line": 18, - "column": 25, + "column": 21, "program": "throwInTryStatement.ets" } } @@ -248,7 +248,7 @@ }, "end": { "line": 18, - "column": 25, + "column": 21, "program": "throwInTryStatement.ets" } } @@ -262,7 +262,7 @@ }, "end": { "line": 18, - "column": 27, + "column": 23, "program": "throwInTryStatement.ets" } } @@ -275,7 +275,7 @@ }, "end": { "line": 18, - "column": 27, + "column": 23, "program": "throwInTryStatement.ets" } } diff --git a/ets2panda/test/compiler/ets/throwInTryStatement.ets b/ets2panda/test/compiler/ets/throwInTryStatement.ets index 584334e8c2..98a3cf9cb6 100644 --- a/ets2panda/test/compiler/ets/throwInTryStatement.ets +++ b/ets2panda/test/compiler/ets/throwInTryStatement.ets @@ -15,6 +15,6 @@ function main(): void { try { - throw new Exception(); + throw new Error(); } catch (e) {} } diff --git a/ets2panda/test/compiler/ets/tryCatchMissingParamType-expected.txt b/ets2panda/test/compiler/ets/tryCatchMissingParamType-expected.txt index 4b3df3d329..b68a994cc8 100644 --- a/ets2panda/test/compiler/ets/tryCatchMissingParamType-expected.txt +++ b/ets2panda/test/compiler/ets/tryCatchMissingParamType-expected.txt @@ -212,7 +212,7 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Exception", + "name": "Error", "decorators": [], "loc": { "start": { @@ -222,7 +222,7 @@ }, "end": { "line": 18, - "column": 28, + "column": 24, "program": "tryCatchMissingParamType.ets" } } @@ -235,7 +235,7 @@ }, "end": { "line": 18, - "column": 29, + "column": 25, "program": "tryCatchMissingParamType.ets" } } @@ -248,7 +248,7 @@ }, "end": { "line": 18, - "column": 29, + "column": 25, "program": "tryCatchMissingParamType.ets" } } @@ -262,7 +262,7 @@ }, "end": { "line": 18, - "column": 31, + "column": 27, "program": "tryCatchMissingParamType.ets" } } @@ -275,7 +275,7 @@ }, "end": { "line": 18, - "column": 31, + "column": 27, "program": "tryCatchMissingParamType.ets" } } diff --git a/ets2panda/test/compiler/ets/tryCatchMissingParamType.ets b/ets2panda/test/compiler/ets/tryCatchMissingParamType.ets index 01c088b713..ebd6b0f73d 100644 --- a/ets2panda/test/compiler/ets/tryCatchMissingParamType.ets +++ b/ets2panda/test/compiler/ets/tryCatchMissingParamType.ets @@ -15,7 +15,7 @@ function main(): void { try { - throw new Exception(); + throw new Error(); } catch (e) { //Do something. } diff --git a/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt b/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt index cae4964823..1256689dfa 100644 --- a/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt +++ b/ets2panda/test/compiler/ets/tryDefaultCatches-expected.txt @@ -303,7 +303,7 @@ "loc": { "start": { "line": 19, - "column": 26, + "column": 15, "program": "tryDefaultCatches.ets" }, "end": { @@ -316,53 +316,6 @@ "param": { "type": "Identifier", "name": "e", - "typeAnnotation": { - "type": "ETSTypeReference", - "part": { - "type": "ETSTypeReferencePart", - "name": { - "type": "Identifier", - "name": "Exception", - "decorators": [], - "loc": { - "start": { - "line": 19, - "column": 15, - "program": "tryDefaultCatches.ets" - }, - "end": { - "line": 19, - "column": 24, - "program": "tryDefaultCatches.ets" - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 15, - "program": "tryDefaultCatches.ets" - }, - "end": { - "line": 19, - "column": 25, - "program": "tryDefaultCatches.ets" - } - } - }, - "loc": { - "start": { - "line": 19, - "column": 15, - "program": "tryDefaultCatches.ets" - }, - "end": { - "line": 19, - "column": 25, - "program": "tryDefaultCatches.ets" - } - } - }, "decorators": [], "loc": { "start": { @@ -389,54 +342,6 @@ "program": "tryDefaultCatches.ets" } } - }, - { - "type": "CatchClause", - "body": { - "type": "BlockStatement", - "statements": [], - "loc": { - "start": { - "line": 21, - "column": 15, - "program": "tryDefaultCatches.ets" - }, - "end": { - "line": 23, - "column": 4, - "program": "tryDefaultCatches.ets" - } - } - }, - "param": { - "type": "Identifier", - "name": "e", - "decorators": [], - "loc": { - "start": { - "line": 21, - "column": 12, - "program": "tryDefaultCatches.ets" - }, - "end": { - "line": 21, - "column": 13, - "program": "tryDefaultCatches.ets" - } - } - }, - "loc": { - "start": { - "line": 21, - "column": 5, - "program": "tryDefaultCatches.ets" - }, - "end": { - "line": 23, - "column": 4, - "program": "tryDefaultCatches.ets" - } - } } ], "finalizer": null, @@ -447,7 +352,7 @@ "program": "tryDefaultCatches.ets" }, "end": { - "line": 23, + "line": 21, "column": 4, "program": "tryDefaultCatches.ets" } @@ -461,7 +366,7 @@ "program": "tryDefaultCatches.ets" }, "end": { - "line": 24, + "line": 22, "column": 2, "program": "tryDefaultCatches.ets" } @@ -474,7 +379,7 @@ "program": "tryDefaultCatches.ets" }, "end": { - "line": 24, + "line": 22, "column": 2, "program": "tryDefaultCatches.ets" } @@ -487,7 +392,7 @@ "program": "tryDefaultCatches.ets" }, "end": { - "line": 24, + "line": 22, "column": 2, "program": "tryDefaultCatches.ets" } @@ -502,7 +407,7 @@ "program": "tryDefaultCatches.ets" }, "end": { - "line": 24, + "line": 22, "column": 2, "program": "tryDefaultCatches.ets" } @@ -543,7 +448,7 @@ "program": "tryDefaultCatches.ets" }, "end": { - "line": 25, + "line": 23, "column": 1, "program": "tryDefaultCatches.ets" } diff --git a/ets2panda/test/compiler/ets/tryDefaultCatches.ets b/ets2panda/test/compiler/ets/tryDefaultCatches.ets index 90b180275b..7aec62e693 100644 --- a/ets2panda/test/compiler/ets/tryDefaultCatches.ets +++ b/ets2panda/test/compiler/ets/tryDefaultCatches.ets @@ -16,8 +16,6 @@ function main(): void { try { throw new NullPointerError(); - } catch (e: Exception) { - //Do something. } catch (e) { //Do something. } diff --git a/ets2panda/test/runtime/ets/CastReference3.ets b/ets2panda/test/runtime/ets/CastReference3.ets index e4c0300b0c..3f629b5bbd 100644 --- a/ets2panda/test/runtime/ets/CastReference3.ets +++ b/ets2panda/test/runtime/ets/CastReference3.ets @@ -45,10 +45,8 @@ function main() { try { let As: FixedArray = new A[1]; let Bs = As as FixedArray; - } catch (e: ClassCastError) { - caught = true; } catch (e) { - arktest.assertTrue(false) + caught = true; } arktest.assertTrue(caught) } diff --git a/ets2panda/test/runtime/ets/CastReference4.ets b/ets2panda/test/runtime/ets/CastReference4.ets index 1d6541d0c4..7ae84977f9 100644 --- a/ets2panda/test/runtime/ets/CastReference4.ets +++ b/ets2panda/test/runtime/ets/CastReference4.ets @@ -32,10 +32,8 @@ 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) + caught = true } arktest.assertTrue(caught) diff --git a/ets2panda/test/runtime/ets/Enum3.ets b/ets2panda/test/runtime/ets/Enum3.ets index 150f7e76c6..59a6265267 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; @@ -54,8 +56,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) diff --git a/ets2panda/test/runtime/ets/Enum4.ets b/ets2panda/test/runtime/ets/Enum4.ets index bfac7dcebc..935d0aeb25 100644 --- a/ets2panda/test/runtime/ets/Enum4.ets +++ b/ets2panda/test/runtime/ets/Enum4.ets @@ -86,9 +86,11 @@ 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) {} + } 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,7 +100,7 @@ function main(): void { try { let x = 5 as Color; arktest.assertTrue( false) - } catch (e: Error) { + } catch (e) { arktest.assertTrue( (e as Object).toString().startsWith("Error: No enum Color with value 5")) } diff --git a/ets2panda/test/runtime/ets/Enum5.ets b/ets2panda/test/runtime/ets/Enum5.ets index c765271af6..3fbd7436d6 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,8 +90,10 @@ 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") diff --git a/ets2panda/test/runtime/ets/OptionalChains.ets b/ets2panda/test/runtime/ets/OptionalChains.ets index f424388915..213bbe0f12 100644 --- a/ets2panda/test/runtime/ets/OptionalChains.ets +++ b/ets2panda/test/runtime/ets/OptionalChains.ets @@ -19,7 +19,7 @@ function assert_o(v: Object | null | undefined) { arktest.assertTrue(v !== null function assert_npe(f: () => void) { try { f(); - } catch (e: NullPointerError) { + } catch (e) { 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 0e14d65349..b545a44090 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; + 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 d7ddb16a64..4d32e69b60 100644 --- a/ets2panda/test/runtime/ets/UnboxingCheckcast.ets +++ b/ets2panda/test/runtime/ets/UnboxingCheckcast.ets @@ -33,8 +33,10 @@ 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/array-new-catched.ets b/ets2panda/test/runtime/ets/array-new-catched.ets index 320374a011..b997912487 100644 --- a/ets2panda/test/runtime/ets/array-new-catched.ets +++ b/ets2panda/test/runtime/ets/array-new-catched.ets @@ -20,8 +20,10 @@ function baz(): number { let catched = false; try { let a:FixedArray = new int[baz()] - } catch (e: TypeError) { - catched = true + } catch (e) { + if (e instanceof TypeError) { + catched = true + } } arktest.assertTrue(catched) } diff --git a/ets2panda/test/runtime/ets/division-by-zero.ets b/ets2panda/test/runtime/ets/division-by-zero.ets index e38756ea60..884c4b8ce0 100644 --- a/ets2panda/test/runtime/ets/division-by-zero.ets +++ b/ets2panda/test/runtime/ets/division-by-zero.ets @@ -23,29 +23,43 @@ 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++; + } else { + console.log(error); + } } 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++; + } else { + console.log(error); + } } 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++; + } else { + console.log(error); + } } arktest.assertEQ(caught_counter, 4) @@ -54,37 +68,61 @@ 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) + } else { + console.log(error); + } } try { let result = INT_ONE / DOUBLE_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } else { + console.log(error); + } } try { let result = DOUBLE_ONE / INT_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } else { + console.log(error); + } } try { let result : double = DOUBLE_ONE % DOUBLE_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } else { + console.log(error); + } } try { let result = INT_ONE % DOUBLE_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } else { + console.log(error); + } } try { let result = DOUBLE_ONE % INT_ZERO; - } catch (error: ArithmeticError) { - arktest.assertTrue(false) + } catch (error) { + if (error instanceof ArithmeticError) { + arktest.assertTrue(false) + } else { + console.log(error); + } } } diff --git a/ets2panda/test/runtime/ets/finallyCatchExecutedNormally.ets b/ets2panda/test/runtime/ets/finallyCatchExecutedNormally.ets index a9b85803f1..5d37cc8123 100644 --- a/ets2panda/test/runtime/ets/finallyCatchExecutedNormally.ets +++ b/ets2panda/test/runtime/ets/finallyCatchExecutedNormally.ets @@ -16,7 +16,7 @@ function main() : void { let a = 0; try { - throw new Exception(); + throw new Error(); } catch (e) { a = 2; } finally { diff --git a/ets2panda/test/runtime/ets/finallyClauseThrow.ets b/ets2panda/test/runtime/ets/finallyClauseThrow.ets index 2b9537b10a..1f988a0dd7 100644 --- a/ets2panda/test/runtime/ets/finallyClauseThrow.ets +++ b/ets2panda/test/runtime/ets/finallyClauseThrow.ets @@ -16,15 +16,17 @@ function main() : int { try { try { - throw new Exception(); - } catch (e:Error) { + throw new Error(); + } catch (e) { arktest.assertTrue(false) } finally { throw new Error(); } - } catch (e:Error) { } catch (e) { - arktest.assertTrue(false) + if (e instanceof Error ) { + }else{ + arktest.assertTrue(false) + } } return 0; } \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/finallyExecutedAbruptly.ets b/ets2panda/test/runtime/ets/finallyExecutedAbruptly.ets index 5482e1c919..e5156f1ed8 100644 --- a/ets2panda/test/runtime/ets/finallyExecutedAbruptly.ets +++ b/ets2panda/test/runtime/ets/finallyExecutedAbruptly.ets @@ -13,14 +13,14 @@ * limitations under the License. */ -class exc extends Exception{} +class exc extends Error{} function main() : void{ let a = 0; try { try { - throw new Exception(); - } catch (e: exc) { + throw new Error(); + } catch (e) { arktest.assertTrue(false) } finally { a = 1; diff --git a/ets2panda/test/runtime/ets/generic_Error_class.ets b/ets2panda/test/runtime/ets/generic_Error_class.ets index 50aa86c29d..40f23d4b04 100644 --- a/ets2panda/test/runtime/ets/generic_Error_class.ets +++ b/ets2panda/test/runtime/ets/generic_Error_class.ets @@ -18,10 +18,6 @@ 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; } diff --git a/ets2panda/test/runtime/ets/generic_exception.ets b/ets2panda/test/runtime/ets/generic_exception.ets index e5ef48a63f..fa7f5e78c7 100644 --- a/ets2panda/test/runtime/ets/generic_exception.ets +++ b/ets2panda/test/runtime/ets/generic_exception.ets @@ -13,15 +13,11 @@ * limitations under the License. */ -class E extends Exception {} +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; } diff --git a/ets2panda/test/runtime/ets/member-expression-nullptr.ets b/ets2panda/test/runtime/ets/member-expression-nullptr.ets index f0eeafcc76..18217414b9 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) { + } catch (e) { + if (e instanceof ClassCastError) { test = true; + } } arktest.assertEQ(test, true) @@ -54,7 +56,7 @@ function main(): void { try { let numbers: int = john!.residence.numberOfRooms; - } catch (e: NullPointerError) { + } catch (e) { test = true; } arktest.assertEQ(test, true) @@ -63,7 +65,7 @@ function main(): void { arktest.assertEQ(test, false) try { let numbers: int = foo() + bar() + john!.residence.numberOfRooms; - } catch (e: NullPointerError) { + } catch (e) { test = true; } arktest.assertEQ(test, true) 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 353980fef8..9bdd96e730 100644 --- a/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets +++ b/ets2panda/test/runtime/ets/multi-array-new-catched-1.ets @@ -17,12 +17,12 @@ function main(): void { let A: Array = new Array(); let a: FixedArray>>; - let catched = false; - try { - a = new Number[A.length + 2.][4][A.length + 3.00001]; - } catch (e: TypeError) { - catched = true; - } + let catched = false; + try { + a = new Number[A.length + 2.][4][A.length + 3.00001]; + } catch (e) { + 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 f518d1b800..ebf7f0d802 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 cf3943bff0..f28e77b2c6 100644 --- a/ets2panda/test/runtime/ets/notNull.ets +++ b/ets2panda/test/runtime/ets/notNull.ets @@ -101,7 +101,7 @@ function testNPE() : void { try { (o as Object | null)!; arktest.assertTrue(false, "this must not be executed") - } catch (ex: NullPointerError) { + } catch (ex) { npe_caught = true; } @@ -110,7 +110,7 @@ function testNPE() : void { try { baz()!; arktest.assertTrue(false, "this must not be executed") - } catch (ex: NullPointerError) { + } catch (ex) { npe_caught = true; } diff --git a/ets2panda/test/runtime/ets/nullishTypeCodesamples.ets b/ets2panda/test/runtime/ets/nullishTypeCodesamples.ets index c1fe13d93e..0b2d399d64 100644 --- a/ets2panda/test/runtime/ets/nullishTypeCodesamples.ets +++ b/ets2panda/test/runtime/ets/nullishTypeCodesamples.ets @@ -116,12 +116,12 @@ function main() { try { new DTree().up(); arktest.assertTrue(false) - } catch (e: NullPointerError) { } + } catch (e) { } testb(); try { testf(123); arktest.assertTrue(false) - } catch (e: NullPointerError) { } + } catch (e) { } arktest.assertTrue((testcond() instanceof Int) && (testcond() == 1)) foo(123); diff --git a/ets2panda/test/runtime/ets/optional-chaining-function-call.ets b/ets2panda/test/runtime/ets/optional-chaining-function-call.ets index b4b6bac336..c716ddd261 100644 --- a/ets2panda/test/runtime/ets/optional-chaining-function-call.ets +++ b/ets2panda/test/runtime/ets/optional-chaining-function-call.ets @@ -34,7 +34,7 @@ function foo(a: funcType | null) { let test = false; try { fruit = a!(); - } catch (e: NullPointerError) { + } catch (e) { test = true; } diff --git a/ets2panda/test/runtime/ets/overload_declaration/notNull.ets b/ets2panda/test/runtime/ets/overload_declaration/notNull.ets index 837a42a528..fc18d56afa 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/signature_match_lambda.ets b/ets2panda/test/runtime/ets/signature_match_lambda.ets index 5d7055c93c..23b0d38145 100644 --- a/ets2panda/test/runtime/ets/signature_match_lambda.ets +++ b/ets2panda/test/runtime/ets/signature_match_lambda.ets @@ -35,8 +35,5 @@ class A { function main(){ let a = new A() arktest.assertEQ(a.catch(()=>{}),"first catch is matched") - arktest.assertEQ(a.catch((e:Error|undefined|null)=>{}),"second catch is matched") - arktest.assertEQ(a.catch((e:Error)=>{}),"second catch is matched") - arktest.assertEQ(a.catch((e:Error,e2:Error)=>{}),"third catch is matched") - arktest.assertEQ(a.catch((e:Error,e2:Error,e3:Error)=>{}),"fourth catch is matched") + arktest.assertEQ(a.catch((e)=>{}),"second catch is matched") } diff --git a/ets2panda/test/runtime/ets/top_level_02.ets b/ets2panda/test/runtime/ets/top_level_02.ets index 2e8c92e5d7..59ac9ba28b 100644 --- a/ets2panda/test/runtime/ets/top_level_02.ets +++ b/ets2panda/test/runtime/ets/top_level_02.ets @@ -27,7 +27,7 @@ switch (q) { } } -class TestException extends Exception { +class TestException extends Error { } arktest.assertEQ(q, 3) @@ -38,10 +38,11 @@ try { q += 5; throw new TestException(); } -catch (e: TestException) { -} catch (e) { - arktest.assertTrue(false) + 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 5428c1e6c6..83c7cb8b28 100644 --- a/ets2panda/test/runtime/ets/try-catch-error.ets +++ b/ets2panda/test/runtime/ets/try-catch-error.ets @@ -20,40 +20,47 @@ 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-no-param.ets b/ets2panda/test/runtime/ets/try-catch-no-param.ets index 96d6bbc534..e8bdd76ca5 100644 --- a/ets2panda/test/runtime/ets/try-catch-no-param.ets +++ b/ets2panda/test/runtime/ets/try-catch-no-param.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -class TestException extends Exception {} +class TestException extends Error {} let catchCode = 0; @@ -27,7 +27,7 @@ function main(): void { arktest.assertEQ(catchCode, 1) try { - throw new Exception(); + throw new Error(); } catch (e) { catchCode = 2; } diff --git a/ets2panda/test/runtime/ets/try-catch.ets b/ets2panda/test/runtime/ets/try-catch.ets index 9415ba2e58..c117c93964 100644 --- a/ets2panda/test/runtime/ets/try-catch.ets +++ b/ets2panda/test/runtime/ets/try-catch.ets @@ -13,56 +13,54 @@ * limitations under the License. */ -class TestException extends Exception {} +class TestException extends Error {} 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 { + 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) + } catch(e) { + if (e instanceof TestException) { + catchCode = 3; + } 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 Error) { + catchCode = 4; + } 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 0c73ea88d3..5412b37bfc 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 c5d4a0d67c..3805861dfe 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,7 +90,7 @@ TEST_F(ASTVerifierTest, TryCatch) try { throw new NullPointerError(); - } catch (e: NullPointerError) { + } catch (e) { catchCode = 1; } } -- Gitee