diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index 74631ae9763e2b213ee071ef4526bb980238433b..89bd2fd34a5a83e5a33ab9ec5c07305b6c3a2916 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 63b773041d3e79286d070beb32f93153d5344656..acf982878b785376f33293888ee3056803f85572 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 d9970074638f4d87b7610d70336eedddf0b3a7ca..3f5ad30b530d73f537654063f10b34ff3ebef7b3 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 2bb53db77eab4763747c63a019afb22ce2c763a1..d75a72da751d60e0feef688b2406129d0bcecb33 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 1b0e6ff8171ed285c7a7b46ab3d4eb44360211a9..4efd4a36f80aa0467017aeb9216d00588d215dac 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 466b07dfcb6e2d64959eb6d5ef17abc280e9d9c7..7bc813976e0535f070a84f33032f33f65048bd0e 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 e7ab397a8977d58f2a05eedebb5045ec9573fb05..b64f40fc663b11e3fa70c05b1f62bb7251592253 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 1dd8994ce2f4f7d7d97a8fb0c1d0bf70c048961a..c10c887e30f838d6849e43549cab5cbf93fce199 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 b2f1731f602830064845198374938f2c00396ab7..ed8c64227c6b3e19dffa09802871e70a57438c44 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 ef5fb160524f486bcf001ae132a3c0868e648940..8315e7889cadc4361658f04f9981d79dca780dad 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 bf3c5717b906f081bc34692dda911d86fb0597a8..12deda907f732d5eae31e2a52b00af7c2b2822d1 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 a0a247f919d757f0fafc4182bfdef3bac049e3bc..07c11ed802bb88da3e3f60fc25813ed724ceb06f 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 308ab7542c9dc3dca8077fb5dfc665065e625eba..df0218f8dafa9504cbc6beb0294d82b00ef53995 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 134fd0804fc8e36b16d4e607ab019596474b96ac..bf78874c0568db42e93b17f14b1128bb6dc9c791 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 089ace2f225f9df2dbe72da3c65e489a40573c6b..afa9029069e12c5ab27332bab27d386845738dc5 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 92ab4b4dd3c7bd2682db99ba19fc2a783acfc70d..de6228379823b9e17cec897619b56c7e804db3e8 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 ed9a71e41b2f629280be0f58336c00f3a163916d..7bf5655f13fa10d9d5b3835204fd0e6d792b6d0b 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 902d8511e6396423e26357d6c944828ba96795ad..a2bab24fdd21aa0c8e264e5d5d48a2f0c0e7bcc7 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 efd161568ce1a49ade7948dc0034b2cc98aff744..f2328e1f53d21dc457c263e3ed53622b4ff577dc 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 1cfd153d5a913fd8581fd9123d0e34fc6c9651de..9ca9cf1006f7ef9a110da298f2bdc73709ab8173 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 c6d1838c2db549c89a240fd9540b5f315a1264b3..916eadf031f33e454509f83bf76db591d822e53b 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 fcef5ef0227e6e8494c716ed7d53d5367acc983c..0e1150386e3952250fcc0a9e5660d176c480a06d 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 95d73ea9c1da530acdbb9317e0600a56f1013a6c..2f1e7898c4ec63c508ebf9c10562cc57fb491efa 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 31b139aadf6b976527f62fdbb4c66bb91250a08e..a58981b7a51c120e929c794d8a38f446a5194e7a 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 a200b8c29d28a7b0b7332f96f72f3e5dbe958c30..5f84b1220ec34ce129fa63c91fa22c5403d714c9 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 00b03aa72af595fe5a3c7186233ebeafafb76f48..a298a27c185d786c4e22a7e62fb60eb9305b9991 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 4b9a3fce73cd5ff25b31e26d6cf3c2d053457bc5..989e9696a02bf0583613d569053f4e5a7071adb8 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 c2a99cefe1181218ee130e7875277c7f5dc9c22d..83e909c8f3faa6037c2f66937452e43acb11306e 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 c5e1ac85c487fa5ce7d28589e132ddadc6023319..2dbd3ee7ab3d96557a8d99fd24091840f0b17944 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 464bf819e4d2b828b3844aca9d7171d65bff5532..c023ead580d2e858011d7cc7ad11fc14c72de58a 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 f674939d0a1de1f69be8fd5e6611971843ee0c61..d23ebfc9ffee8f30ea05785020cb8f91b4da59d5 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 b02aacc5c6c4746bdfa22a711a2fba79f9f7ce1d..289f4e3148222e459c8af09a9709b2ccc05a6d75 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 8325db3372af2a70620318a9ff9bd9c979be17a2..98907280d1d337c0238c9b91a54e958f5ac1c64e 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 fcf93a23b72d9b628d6eb0eb61681f2827af88fd..1c0aa042bfedceca4e54cac41ff977a34820e77a 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 584334e8c2311c4dcbfd8e96653d582929a30b2f..98a3cf9cb6d83d3b1c72d9640f7b35274e69d834 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 4b3df3d3296ea06877596862a0daa295db17a08f..b68a994cc848dfc5dc9d3744c68a9f9cb3cc4576 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 01c088b7132c3e9c3988ccb2a1602e362bcedd86..ebd6b0f73da19f52aeccd56d452bbbb052b37d4b 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 cae4964823da63113cf6213747eb22040b08f222..1256689dfa6ef32f653a4f75a239c2af60497115 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 90b180275b9d8cbbd52ee4279e9328653a6853af..7aec62e6931969f4ab038c2d07364ab126822e04 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 e4c0300b0cd970eeb772cb945c06d95a993a7377..3f629b5bbd994967021c8fd8f8c5923855635f67 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 1d6541d0c413ae94b4726de489a02f86a5184261..7ae84977f95ab4dfb1fee5ed008b38c369bfb00e 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 150f7e76c6e6928ef87ffbb4a3b84972834b9a4b..59a62652672e3ab95b8ab7ca2688414c0eb1b61e 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 bfac7dcebc85a435ecec9896a98e2b461b0d6625..935d0aeb25f9e0d035da2404312486a235a5e697 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 c765271af61c591276d4cd6e795e06b582498f6c..3fbd7436d6612da1220151b668aa72b21571fabf 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 f42438891591830a61ecae41c4d469191e355ea8..213bbe0f120629291efd7d06fedd680ea38c57c6 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 0e14d653491caf6d2b6f577265c8b733d75d4c4d..b545a4409018d6a036185998704225e035a14125 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 d7ddb16a64e38e8862efe31fc98e118b161b9e92..4d32e69b60273a4b57f15e8f417bbaeb08944186 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 320374a0114ea3c7d44884151122096dc8cf0ce3..b99791248722edd9b454a777b2ca3193fe36dc59 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 e38756ea60228c21b53cae4b4e7e83a74734afa2..884c4b8ce0f1928c9b6e8f415cd21e2b4009cd68 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 a9b85803f1a915d757f30558d3f581834b5cba8f..5d37cc812337a9117bff387b4d6f2fcc2280973a 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 2b9537b10a5f0082fa06ea58bc64e0afea04126f..1f988a0dd7d5eb1238673b84f7ca069ae881e999 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 5482e1c919e826e8eac803b4130585d81a30c1fa..e5156f1ed8ad0e51b51c702b8b6a29612bb828e6 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 50aa86c29d8a809c25b462be3dfa1a89073cb288..40f23d4b04ca974d9cf2c10260520a859977bdfe 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 e5ef48a63f646553b16525d043806002585b72e1..fa7f5e78c74f6f4aa7f51ae62d05919e563d8b61 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 f0eeafcc767a9ebd12bdca097c5e7429ab7d2287..18217414b9cd59a9e774aa4b800ddb5de0f5e615 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 353980fef8872f5ef352441052a8aefc8f01b89d..9bdd96e73000d85eea47523ec35ea7dd00537147 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 f518d1b800f8731cc3e75f064a6771df3bf80461..ebf7f0d802bd002836b6ec7f52700986077ae36a 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..f28e77b2c6fd00fa87b847c97268508c38a54c68 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 c1fe13d93e07aa815e93b5a3347f7a78448b5d84..0b2d399d649f7a0495fd9b7e312c3fd5339ace15 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 b4b6bac3362b531b2c531339cdac4bd756f2e240..c716ddd26133f423dd903098e8ddcd046fcaecb2 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 837a42a528f0edc9fb2ba1665921c09dd136784b..fc18d56afaa0666ff5857b25f37c6ba375244587 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 5d7055c93cb0c9c301b275f40f0c1cfef9b24659..23b0d381450b8f647920adc0f0ec600f6e2864e5 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 2e8c92e5d73cb64ab52808d971b8f598cfe53d47..59ac9ba28b7657890e60037a6af6cb9675e890ee 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 5428c1e6c629ad2acc15364a1b43126d491fc0af..83c7cb8b28137a2108a344f35f71694bbe4bc723 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 96d6bbc534370ec361f6c181ff8e9a04643d628c..e8bdd76ca5bbee7b1f1d03afed8f3168188ad8c5 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 9415ba2e5840a644054f27acd1689d61c62b4700..c117c93964e15d1db7489ba0120244f3859a30e5 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 0c73ea88d3f91be6dc4b4bba1db151f30d794901..5412b37bfc0f342aceece312200ab3643bf3b0c8 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..3805861dfe28e0d0f6c108e01985e85127b4e0d3 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; } }