From 6443db319452df93d0a8c5e73007b2ba88fd9c01 Mon Sep 17 00:00:00 2001 From: liujia178 Date: Tue, 15 Apr 2025 14:43:12 +0800 Subject: [PATCH] part III: Add test case for CTS about SyntaxError TypeError Signed-off-by: liujia178 --- .../syntax/catch_clause_var_has_init.ets | 30 ++++++++++++++++ .../syntax/default_undef_not_allowed.ets | 18 ++++++++++ .../ets/errors/syntax/duplicated_modifier.ets | 19 ++++++++++ .../syntax/extension_setter_wrong_param.ets | 24 +++++++++++++ .../errors/syntax/for_in_loop_has_init.ets | 18 ++++++++++ .../ets/errors/syntax/identifier_expected.ets | 20 +++++++++++ .../ets/errors/syntax/illegal_use_strict.ets | 20 +++++++++++ .../errors/syntax/implements_clause_empty.ets | 18 ++++++++++ .../implicit_octal_literal_not_allowed.ets | 18 ++++++++++ .../syntax/initializers_interface_props.ets | 23 ++++++++++++ .../ets/errors/syntax/insert_node_absent.ets | 23 ++++++++++++ .../errors/syntax/invalid_bigInt_number.ets | 18 ++++++++++ .../ets/errors/syntax/invalid_character.ets | 18 ++++++++++ .../ets/errors/syntax/invalid_digit.ets | 20 +++++++++++ .../syntax/invalid_end_numeric_separators.ets | 20 +++++++++++ .../errors/syntax/invalid_identifier_part.ets | 20 +++++++++++ .../errors/syntax/invalid_left_in_prefix.ets | 18 ++++++++++ .../syntax/invalid_left_site_operator.ets | 20 +++++++++++ .../errors/syntax/invalid_numeric_literal.ets | 18 ++++++++++ .../syntax/invalid_numeric_separator.ets | 18 ++++++++++ .../invalid_octal_decimal_integer_literal.ets | 18 ++++++++++ .../ets/errors/syntax/invalid_octal_digit.ets | 20 +++++++++++ .../invalid_unicode_escape_sequence.ets | 18 ++++++++++ .../ets/errors/syntax/invalid_union_type.ets | 19 ++++++++++ .../errors/syntax/label_already_declared.ets | 30 ++++++++++++++++ .../ets/errors/syntax/multiple_default.ets | 24 +++++++++++++ .../syntax/native_flag_only_for_top_fun.ets | 24 +++++++++++++ .../ets/errors/syntax/number_is_too_large.ets | 19 ++++++++++ .../numeric_separator_start_with_zero.ets | 18 ++++++++++ .../ets/errors/syntax/only_array_for_rest.ets | 20 +++++++++++ .../ets/errors/syntax/return_in_fun_body.ets | 19 ++++++++++ ...cial_predefined_method_cannot_be_async.ets | 22 ++++++++++++ ...redefined_method_should_have_one_param.ets | 22 ++++++++++++ ...edefined_method_should_have_two_params.ets | 20 +++++++++++ ...edefined_method_should_not_have_params.ets | 20 +++++++++++ .../ets/errors/syntax/unexpected_super.ets | 19 ++++++++++ .../syntax/unsupported_character_literal.ets | 18 ++++++++++ .../ets/errors/syntax/unterminated_string.ets | 22 ++++++++++++ .../ets/errors/type/abstract_in_concrete.ets | 21 +++++++++++ .../errors/type/abstract_instantiation.ets | 21 +++++++++++ .../ets/errors/type/abstract_is_final.ets | 22 ++++++++++++ .../errors/type/ambient_const_invalid_lit.ets | 18 ++++++++++ .../ets/errors/type/assert_not_logical.ets | 19 ++++++++++ .../errors/type/assignment_invalid_lhs.ets | 21 +++++++++++ .../compiler/ets/errors/type/binop_union.ets | 34 ++++++++++++++++++ .../errors/type/infer_failure_func_param.ets | 19 ++++++++++ .../ets/errors/type/invalid_enums.ets | 21 +++++++++++ .../ets/errors/type/mixed_void_nonvoid.ets | 19 ++++++++++ .../ets/errors/type/multiple_spreads.ets | 23 ++++++++++++ .../compiler/ets/errors/type/not_generic.ets | 18 ++++++++++ .../ets/errors/type/not_interface.ets | 23 ++++++++++++ .../errors/type/switch_case_invalid_type.ets | 35 +++++++++++++++++++ .../errors/type/template_count_mismatch.ets | 21 +++++++++++ 53 files changed, 1108 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/catch_clause_var_has_init.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/default_undef_not_allowed.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/duplicated_modifier.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/extension_setter_wrong_param.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/for_in_loop_has_init.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/identifier_expected.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/illegal_use_strict.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/implements_clause_empty.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/implicit_octal_literal_not_allowed.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/initializers_interface_props.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/insert_node_absent.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_bigInt_number.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_character.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_digit.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_end_numeric_separators.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_identifier_part.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_in_prefix.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_site_operator.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_literal.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_separator.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_decimal_integer_literal.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_digit.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_unicode_escape_sequence.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_union_type.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/label_already_declared.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/multiple_default.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/native_flag_only_for_top_fun.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/number_is_too_large.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/numeric_separator_start_with_zero.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/only_array_for_rest.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/return_in_fun_body.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_cannot_be_async.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_one_param.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_two_params.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_not_have_params.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_super.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/unsupported_character_literal.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/unterminated_string.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/abstract_in_concrete.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/abstract_instantiation.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/abstract_is_final.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/ambient_const_invalid_lit.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/assert_not_logical.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/assignment_invalid_lhs.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/binop_union.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/infer_failure_func_param.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/invalid_enums.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/mixed_void_nonvoid.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/multiple_spreads.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/not_generic.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/not_interface.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/switch_case_invalid_type.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/template_count_mismatch.ets diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/catch_clause_var_has_init.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/catch_clause_var_has_init.ets new file mode 100644 index 0000000000..7a5b1b28d1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/catch_clause_var_has_init.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +try { + throw new Exception(); +} catch (e = 0) { + //Do something. +} + +/* @@? 18:12 Error SyntaxError: Catch clause variable cannot have an initializer. */ +/* @@? 18:12 Error SyntaxError: Expected ')', got '='. */ +/* @@? 18:12 Error SyntaxError: Expected '{', got '='. */ +/* @@? 18:12 Error SyntaxError: Expected '{', got '='. */ +/* @@? 18:12 Error SyntaxError: Unexpected token '='. */ +/* @@? 18:15 Error SyntaxError: Unexpected token ')'. */ +/* @@? 18:15 Error SyntaxError: Unexpected token ')'. */ +/* @@? 18:15 Error SyntaxError: Unexpected token ')'. */ +/* @@? 31:1 Error SyntaxError: Expected '}', got 'eos'. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/default_undef_not_allowed.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/default_undef_not_allowed.ets new file mode 100644 index 0000000000..3d2a8f5d68 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/default_undef_not_allowed.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function f2(a?: int = /* @@ label */44): void {} + +/* @@@ label Error SyntaxError: Not enable default value with default undefined. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/duplicated_modifier.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/duplicated_modifier.ets new file mode 100644 index 0000000000..4c69efec0b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/duplicated_modifier.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +abstract /* @@ label */abstract class B { +} + +/* @@@ label Error SyntaxError: Duplicated modifier is not allowed. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/extension_setter_wrong_param.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/extension_setter_wrong_param.ets new file mode 100644 index 0000000000..ef9ca5d36f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/extension_setter_wrong_param.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A{ + field_: int; +} + +/* @@ label */set field(this: A, a: int, b: int) { + +} + +/* @@@ label Error SyntaxError: Extension Setter can only have 2 parameters. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/for_in_loop_has_init.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/for_in_loop_has_init.ets new file mode 100644 index 0000000000..84ec416e04 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/for_in_loop_has_init.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +for (let i = 1 /* @@ label */of [0, 1, 2]) {} + +/* @@@ label Error SyntaxError: for-of loop variable declaration may not have an initializer. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/identifier_expected.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/identifier_expected.ets new file mode 100644 index 0000000000..0f80ede994 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/identifier_expected.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function f1(a: int, ...b: int[] = /* @@ label */47/* @@ label1 */) { +} + +/* @@@ label Error SyntaxError: Rest parameter cannot have the default value. */ +/* @@@ label1 Error SyntaxError: Identifier is needed here. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/illegal_use_strict.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/illegal_use_strict.ets new file mode 100644 index 0000000000..f0be055b3e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/illegal_use_strict.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function f(x: number, ... args: number[]) { + /* @@ label */"use strict" +} + +/* @@@ label Error SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/implements_clause_empty.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/implements_clause_empty.ets new file mode 100644 index 0000000000..7b59264af7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/implements_clause_empty.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A implements /* @@ label */{} + +/* @@@ label Error SyntaxError: Implements clause can not be empty. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/implicit_octal_literal_not_allowed.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/implicit_octal_literal_not_allowed.ets new file mode 100644 index 0000000000..e3ef93cc2f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/implicit_octal_literal_not_allowed.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const n2 = 0134 + +/* @@? 16:12 Error SyntaxError: Implicit octal literal not allowed. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/initializers_interface_props.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/initializers_interface_props.ets new file mode 100644 index 0000000000..f645ec780d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/initializers_interface_props.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface A { + readonly filed: number /* @@ label */== /* @@ label1 */1/* @@ label2 */; +} + +/* @@@ label Error SyntaxError: Initializers are not allowed on interface properties. */ +/* @@@ label1 Error SyntaxError: Unexpected token, expected ','. */ +/* @@@ label1 Error SyntaxError: Unexpected token, expected 'private' or identifier. */ +/* @@@ label2 Error SyntaxError: Identifier expected. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/insert_node_absent.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/insert_node_absent.ets new file mode 100644 index 0000000000..4d265db767 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/insert_node_absent.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let /* @@ label */@@/* @@ label1 */I2 + +/* @@@ label Error SyntaxError: There is no any node to insert at the placeholder position. */ +/* @@@ label Error SyntaxError: Identifier expected, got '@@'. */ +/* @@@ label1 Error SyntaxError: Variable must be initialized or it's type must be declared. */ +/* @@@ label1 Error SyntaxError: Variable must be initialized or it's type must be declared. */ +/* @@@ label1 Error SyntaxError: Unexpected token 'I2'. */ +/* @@@ label1 Error TypeError: Unresolved reference I2 */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_bigInt_number.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_bigInt_number.ets new file mode 100644 index 0000000000..8e466348ea --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_bigInt_number.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +0x291n + +/* @@? 16:1 Error SyntaxError: Invalid BigInt number. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_character.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_character.ets new file mode 100644 index 0000000000..c2392d48d1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_character.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +\U4444 + +/* @@? 16:1 Error SyntaxError: Invalid character. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_digit.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_digit.ets new file mode 100644 index 0000000000..bd28141a87 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_digit.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const badBin = 0bF0011101 + +/* @@? 16:16 Error SyntaxError: Invalid digit. */ +/* @@? 16:18 Error SyntaxError: Unexpected token 'F0011101'. */ +/* @@? 16:18 Error TypeError: Unresolved reference F0011101 */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_end_numeric_separators.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_end_numeric_separators.ets new file mode 100644 index 0000000000..d885c4b2f6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_end_numeric_separators.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +0o251042_ + +/* @@? 16:1 Error SyntaxError: Numeric separators are not allowed at the end of numeric literals. */ +/* @@? 16:9 Error SyntaxError: Unexpected token '_'. */ +/* @@? 16:9 Error TypeError: Unresolved reference _ */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_identifier_part.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_identifier_part.ets new file mode 100644 index 0000000000..053437bd52 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_identifier_part.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +undef\u0xFF00ned + +/* @@? 16:1 Error SyntaxError: Invalid Unicode escape. */ +/* @@? 16:1 Error SyntaxError: Invalid identifier part. */ +/* @@? 16:1 Error TypeError: Unresolved reference undefFF00ned */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_in_prefix.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_in_prefix.ets new file mode 100644 index 0000000000..ebcb9d578f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_in_prefix.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +--58 + +/* @@? 19:1 Error SyntaxError: Invalid left-hand side in prefix operation. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_site_operator.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_site_operator.ets new file mode 100644 index 0000000000..b6ad5986a6 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_left_site_operator.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function f4() { + 69/* @@ label */++ +} + +/* @@@ label Error SyntaxError: Invalid left-hand side operator. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_literal.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_literal.ets new file mode 100644 index 0000000000..7c896865fd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_literal.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const f1 = 1.00000000f1 + +/* @@? 16:12 Error SyntaxError: Invalid numeric literal. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_separator.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_separator.ets new file mode 100644 index 0000000000..8e116eb766 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_numeric_separator.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @@ label */0x0D00__0000 + +/* @@@ label Error SyntaxError: Invalid numeric separator. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_decimal_integer_literal.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_decimal_integer_literal.ets new file mode 100644 index 0000000000..18a234867f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_decimal_integer_literal.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const n2 = /* @@ label */0999 + +/* @@@ label Error SyntaxError: NonOctalDecimalIntegerLiteral is not enabled in strict mode code. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_digit.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_digit.ets new file mode 100644 index 0000000000..cb4f84dfca --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_octal_digit.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const o1 = /* @@ label */0o0008 + +/* @@@ label Error SyntaxError: Invalid octal digit. */ +/* @@@ label Error SyntaxError: Invalid numeric literal. */ +/* @@? 16:31 Error SyntaxError: Unexpected token '8'. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_unicode_escape_sequence.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_unicode_escape_sequence.ets new file mode 100644 index 0000000000..9f6fdb1da8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_unicode_escape_sequence.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @@ label */"\u{0x0096}" + +/* @@@ label Error SyntaxError: Invalid Unicode escape. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_union_type.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_union_type.ets new file mode 100644 index 0000000000..7e012dde99 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_union_type.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +type A = undefined | null | int +/* @@ label */new A() + +/* @@@ label Error TypeError: The union type is not constructible. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/label_already_declared.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/label_already_declared.ets new file mode 100644 index 0000000000..5637c2cb74 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/label_already_declared.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function f(x: int): void { + for (let i = 0; i < x; ++i) { + aa: + while (i < 10) { + /* @@ label */aa: + while (i > 10) { + ++i + break aa + } + ++i + } + } +} + +/* @@@ label Error SyntaxError: Label already declared. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/multiple_default.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/multiple_default.ets new file mode 100644 index 0000000000..c5238645f1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/multiple_default.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function g(x: int): int { + switch (x) { + case 1: return 0; + default: return -1; + /* @@ label */default: return -2; + } +} + +/* @@@ label Error SyntaxError: Multiple default clauses. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/native_flag_only_for_top_fun.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/native_flag_only_for_top_fun.ets new file mode 100644 index 0000000000..22854ecb34 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/native_flag_only_for_top_fun.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +native /* @@ label */class /* @@ label1 */Z /* @@ label2 */{/* @@ label3 */} + +/* @@@ label Error SyntaxError: 'native' flags must be used for functions only at top-level. */ +/* @@@ label1 Error TypeError: Native and Declare methods should have explicit return type. */ +/* @@@ label2 Error SyntaxError: Unexpected token, expected '('. */ +/* @@@ label3 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@@ label3 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ +/* @@@ label3 Error SyntaxError: Unexpected token, expected ',' or ')'. */ +/* @@@ label3 Error SyntaxError: Unexpected token '}'. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/number_is_too_large.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/number_is_too_large.ets new file mode 100644 index 0000000000..80a0bed489 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/number_is_too_large.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const n4 = /* @@ label */0xFFFFFFFFFFFFFFFF0 + +/* @@@ label Error SyntaxError: Number is too large. */ +/* @@? 16:44 Error SyntaxError: Unexpected token '0'. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/numeric_separator_start_with_zero.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/numeric_separator_start_with_zero.ets new file mode 100644 index 0000000000..7fd6a07cec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/numeric_separator_start_with_zero.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const n3 = /* @@ label */0_01 + +/* @@@ label Error SyntaxError: Numeric separator '_' is not allowed in numbers that start with '0'. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/only_array_for_rest.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/only_array_for_rest.ets new file mode 100644 index 0000000000..291e5944a8 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/only_array_for_rest.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function foo(...p: Object/* @@ label */): Object { + return new Object(); +} + +/* @@@ label Error SyntaxError: Rest parameter should be either array or tuple type. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/return_in_fun_body.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/return_in_fun_body.ets new file mode 100644 index 0000000000..1e6352e196 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/return_in_fun_body.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @@ label */return /* @@ label1 */48; + +/* @@@ label Error SyntaxError: return keyword should be used in function body. */ +/* @@@ label1 Error TypeError: All return statements in the function should be empty or have a value. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_cannot_be_async.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_cannot_be_async.ets new file mode 100644 index 0000000000..cc2f2f12ab --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_cannot_be_async.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +abstract class B { + /* @@ label */async $_get(a: int): Promise { + return 5; + } +} + +/* @@@ label Error SyntaxError: The special predefined method '$_get' cannot be asynchronous. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_one_param.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_one_param.ets new file mode 100644 index 0000000000..9faf2196ec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_one_param.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +abstract class B { + /* @@ label */$_get(): int { + return 5; + } +} + +/* @@@ label Error SyntaxError: The special predefined method '$_get' should have exactly one required parameter. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_two_params.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_two_params.ets new file mode 100644 index 0000000000..ce818cbf8f --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_have_two_params.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +abstract class B { + /* @@ label */$_set(): void {} +} + +/* @@@ label Error SyntaxError: The special predefined method '$_set' should have exactly two required parameter. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_not_have_params.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_not_have_params.ets new file mode 100644 index 0000000000..72cc6e625a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/special_predefined_method_should_not_have_params.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +abstract class B { + /* @@ label */abstract $_iterator(a: int): Iterator +} + +/* @@@ label Error SyntaxError: The special predefined method '$_iterator' should not have parameters. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_super.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_super.ets new file mode 100644 index 0000000000..962c5a4e44 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_super.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @@ label */super/* @@ label1 */() + +/* @@@ label Error TypeError: Call to 'super' must be first statement in constructor */ +/* @@@ label1 Error SyntaxError: Unexpected super keyword. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/unsupported_character_literal.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/unsupported_character_literal.ets new file mode 100644 index 0000000000..863e9aa443 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/unsupported_character_literal.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const c2 = /* @@ label */c'😀' + +/* @@@ label Error SyntaxError: Unsupported character literal. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/unterminated_string.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/unterminated_string.ets new file mode 100644 index 0000000000..d806127547 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/unterminated_string.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let expr = "test"; +`string ${expr + +/* @@? 23:1 Error SyntaxError: Expected '}', got 'eos'. */ +/* @@? 23:1 Error SyntaxError: Unterminated string. */ +/* @@? 23:1 Error SyntaxError: Unexpected token, expected '${' or '`' */ +/* @@? 23:1 Error SyntaxError: Unexpected token, expected '`'. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/abstract_in_concrete.ets b/ets2panda/test/ast/compiler/ets/errors/type/abstract_in_concrete.ets new file mode 100644 index 0000000000..225b5e2371 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/abstract_in_concrete.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A /* @@ label */{ + /* @@ label1 */abstract foo(); +} + +/* @@@ label Error TypeError: A is not abstract and does not override abstract method foo(): void in A */ +/* @@@ label1 Error TypeError: Non abstract class has abstract method. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/abstract_instantiation.ets b/ets2panda/test/ast/compiler/ets/errors/type/abstract_instantiation.ets new file mode 100644 index 0000000000..afad3f8848 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/abstract_instantiation.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +abstract class AbstractLocalClass{ + method1(){} +} +let a:AbstractLocalClass = /* @@ label */new AbstractLocalClass(); + +/* @@@ label Error TypeError: AbstractLocalClass is abstract therefore cannot be instantiated. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/abstract_is_final.ets b/ets2panda/test/ast/compiler/ets/errors/type/abstract_is_final.ets new file mode 100644 index 0000000000..0213d29343 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/abstract_is_final.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class A_class{ + foo(){ + abstract final class AbstractFinalLocalClass/* @@ label */{} + } +} + +/* @@@ label Error TypeError: Cannot use both 'final' and 'abstract' modifiers. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/ambient_const_invalid_lit.ets b/ets2panda/test/ast/compiler/ets/errors/type/ambient_const_invalid_lit.ets new file mode 100644 index 0000000000..943a1a72d7 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/ambient_const_invalid_lit.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export declare const int_1 = /* @@ label */1 + 2 + 3 + 4 + +/* @@@ label Error TypeError: A 'const' initializer in an ambient context must be a string or numeric literal: int_1 */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/assert_not_logical.ets b/ets2panda/test/ast/compiler/ets/errors/type/assert_not_logical.ets new file mode 100644 index 0000000000..a56bb6730a --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/assert_not_logical.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +! + +/* @@? 20:1 Error SyntaxError: Unexpected token 'eos'. */ +/* @@? 20:1 Error TypeError: Bad operand type, the type of the operand must be boolean type. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/assignment_invalid_lhs.ets b/ets2panda/test/ast/compiler/ets/errors/type/assignment_invalid_lhs.ets new file mode 100644 index 0000000000..9f30b4e7d1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/assignment_invalid_lhs.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function foo() { + /* @@ label */55 /* @@ label1 */= int; +} + +/* @@@ label Error TypeError: Invalid left-hand side of assignment expression */ +/* @@@ label1 Error SyntaxError: Invalid left-hand side in assignment expression. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/binop_union.ets b/ets2panda/test/ast/compiler/ets/errors/type/binop_union.ets new file mode 100644 index 0000000000..b9fbd78c3c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/binop_union.ets @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class Cat { + name: string = 'cat'; +} + +class Dog { + name: string = 'dog'; +} + +type Animal = Cat | Dog | number; + +let cat: Animal = new Cat(); +let dog: Animal = new Dog(); +cat < dog; +cat & dog; +cat << 2; + +/* @@? 28:1 Error TypeError: Bad operand type, unions are not allowed in binary expressions except equality. */ +/* @@? 29:1 Error TypeError: Bad operand type, unions are not allowed in binary expressions except equality. */ +/* @@? 30:1 Error TypeError: Bad operand type, unions are not allowed in binary expressions except equality. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/infer_failure_func_param.ets b/ets2panda/test/ast/compiler/ets/errors/type/infer_failure_func_param.ets new file mode 100644 index 0000000000..bc13add926 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/infer_failure_func_param.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function f(/* @@ label */a/* @@ label1 */): void {} + +/* @@@ label Error TypeError: The type of parameter 'a' cannot be inferred */ +/* @@@ label1 Error SyntaxError: Parameter declaration should have an explicit type annotation. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/invalid_enums.ets b/ets2panda/test/ast/compiler/ets/errors/type/invalid_enums.ets new file mode 100644 index 0000000000..3e930b55fa --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/invalid_enums.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +enum EStrNotInit { + Str1 = "str1", + Str2 +} + +/* @@? 18:9 Error SyntaxError: All items of string-type enumeration should be explicitly initialized. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/mixed_void_nonvoid.ets b/ets2panda/test/ast/compiler/ets/errors/type/mixed_void_nonvoid.ets new file mode 100644 index 0000000000..1e6352e196 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/mixed_void_nonvoid.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* @@ label */return /* @@ label1 */48; + +/* @@@ label Error SyntaxError: return keyword should be used in function body. */ +/* @@@ label1 Error TypeError: All return statements in the function should be empty or have a value. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/multiple_spreads.ets b/ets2panda/test/ast/compiler/ets/errors/type/multiple_spreads.ets new file mode 100644 index 0000000000..3860e66de5 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/multiple_spreads.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function foo(...numbers: number[]): number { + return numbers[0] +} +let a = [0,1,2] +/* @@ label */foo(a[0], a[1], /* @@ label1 */...a) + +/* @@@ label Error TypeError: No matching call signature for foo(double, double, double) */ +/* @@@ label1 Error TypeError: Spread argument for the rest parameter can be only one. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/not_generic.ets b/ets2panda/test/ast/compiler/ets/errors/type/not_generic.ets new file mode 100644 index 0000000000..6d52da0ac4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/not_generic.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let entry: /* @@ label */Int = new Int(); + +/* @@@ label Error TypeError: Type 'Int' is not generic. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/not_interface.ets b/ets2panda/test/ast/compiler/ets/errors/type/not_interface.ets new file mode 100644 index 0000000000..e5ad29b756 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/not_interface.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace MySpace { + let a:string = "1" +} + +class B implements /* @@ label */MySpace{} + +/* @@@ label Error TypeError: Namespace 'MySpace' cannot be used as a type. */ +/* @@@ label Error TypeError: Interface expected here. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/switch_case_invalid_type.ets b/ets2panda/test/ast/compiler/ets/errors/type/switch_case_invalid_type.ets new file mode 100644 index 0000000000..27a58739aa --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/switch_case_invalid_type.ets @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function with_param(fn: () => int): void { + fn() +} + +function main(): void { + const switch_arg = 2 + const aa = 1.0; + with_param() { + switch (switch_arg) { + /* @@ label */case aa: + break + case 2: + break + default: assertTrue(false, "Not expected execution here"); + } + return 0; + } +} + +/* @@@ label Error TypeError: Unexpected type double */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/template_count_mismatch.ets b/ets2panda/test/ast/compiler/ets/errors/type/template_count_mismatch.ets new file mode 100644 index 0000000000..4794212cce --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/template_count_mismatch.ets @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const o = /* @@ label */`\251` + +/* @@@ label Error TypeError: Invalid string template expression */ +/* @@@ label Error SyntaxError: Invalid character escape sequence. */ +/* @@? 16:26 Error SyntaxError: Invalid character escape sequence. */ +/* @@? 16:26 Error SyntaxError: Octal escape sequences are not allowed in template strings. */ -- Gitee