From e713a3c3a51ebd8e8d1254168247acd250a189a5 Mon Sep 17 00:00:00 2001 From: liujia178 Date: Fri, 28 Mar 2025 19:30:53 +0800 Subject: [PATCH] Add test case for CTS about SyntaxError TypeError Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/IBTHBV Signed-off-by: liujia178 --- .../Unterminated_multi_line_comment.ets | 20 ++++++++++++ .../errors/syntax/assign_to_args_invalid.ets | 21 +++++++++++++ .../errors/syntax/assign_to_eval_invalid.ets | 21 +++++++++++++ ...eriks_not_allowed_in_selective_binding.ets | 21 +++++++++++++ .../syntax/decalre_in_ambient_context.ets | 20 ++++++++++++ .../eval_or_arguments_in_strict_mode.ets | 21 +++++++++++++ .../syntax/getter_setter_not_abstract.ets | 23 ++++++++++++++ .../syntax/invalid_destructuring_target.ets | 21 +++++++++++++ .../nullish_coalescing_missing_parens.ets | 21 +++++++++++++ .../errors/syntax/type_param_list_empty.ets | 18 +++++++++++ .../syntax/unexpected_arrowparam_element.ets | 24 ++++++++++++++ .../ambient_annot_impl_of_undefined_field.ets | 23 ++++++++++++++ .../compiler/ets/errors/type/ambient_src.ets | 18 +++++++++++ .../ets/errors/type/coalesce_not_ref.ets | 20 ++++++++++++ .../ets/errors/type/duplicate_accessor.ets | 27 ++++++++++++++++ .../errors/type/enum_invalid_discriminant.ets | 31 +++++++++++++++++++ .../generic_type_param_count_mismatch.ets | 21 +++++++++++++ .../ets/errors/type/main_with_rest.ets | 20 ++++++++++++ .../errors/type/method_accessor_collision.ets | 26 ++++++++++++++++ .../ets/errors/type/negative_index.ets | 20 ++++++++++++ .../ets/errors/type/not_cond_type.ets | 26 ++++++++++++++++ .../errors/type/spread_onto_single_param.ets | 23 ++++++++++++++ .../ets/errors/type/tuple_index_nonconst.ets | 23 ++++++++++++++ .../ets/errors/type/tuple_index_not_int.ets | 21 +++++++++++++ .../errors/type/tuple_unassignable_array.ets | 20 ++++++++++++ .../ets/errors/type/unexpected_nonvoid.ets | 23 ++++++++++++++ .../ets/errors/type/unexpected_void.ets | 22 +++++++++++++ 27 files changed, 595 insertions(+) create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/Unterminated_multi_line_comment.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_args_invalid.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_eval_invalid.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/asteriks_not_allowed_in_selective_binding.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/decalre_in_ambient_context.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/eval_or_arguments_in_strict_mode.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/getter_setter_not_abstract.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/invalid_destructuring_target.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/nullish_coalescing_missing_parens.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/type_param_list_empty.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_arrowparam_element.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/ambient_annot_impl_of_undefined_field.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/ambient_src.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/coalesce_not_ref.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/duplicate_accessor.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/enum_invalid_discriminant.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/generic_type_param_count_mismatch.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/main_with_rest.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/method_accessor_collision.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/negative_index.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/not_cond_type.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/spread_onto_single_param.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/tuple_index_nonconst.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/tuple_index_not_int.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/tuple_unassignable_array.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/unexpected_nonvoid.ets create mode 100644 ets2panda/test/ast/compiler/ets/errors/type/unexpected_void.ets diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/Unterminated_multi_line_comment.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/Unterminated_multi_line_comment.ets new file mode 100644 index 0000000000..b1742f0904 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/Unterminated_multi_line_comment.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. + */ + +/* @@? 1:3 Error SyntaxError: Unterminated multi-line comment */ + +/* +This is a multiline comment + diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_args_invalid.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_args_invalid.ets new file mode 100644 index 0000000000..4ad076809c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_args_invalid.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 func() { + let a = /* @@ label1 */arguments/* @@ label */++; +} + +/* @@@ label1 Error TypeError: Unresolved reference arguments */ +/* @@@ label Error SyntaxError: Assigning to 'arguments' in strict mode is invalid. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_eval_invalid.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_eval_invalid.ets new file mode 100644 index 0000000000..87f5f5d42b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/assign_to_eval_invalid.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 func() { + let a = /* @@ label1 */eval/* @@ label */++; +} + +/* @@@ label1 Error TypeError: Unresolved reference eval */ +/* @@@ label Error SyntaxError: Assigning to 'eval' in strict mode is invalid. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/asteriks_not_allowed_in_selective_binding.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/asteriks_not_allowed_in_selective_binding.ets new file mode 100644 index 0000000000..3fa4db972b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/asteriks_not_allowed_in_selective_binding.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. + */ + +import {/* @@ label */*} /* @@ label1 */from /* @@ label2 */'./ambient_src' + +/* @@@ label Error SyntaxError: The '*' token is not allowed as a selective binding (between braces). */ +/* @@@ label Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@@ label1 Error TypeError: Unresolved reference from */ +/* @@@ label2 Error SyntaxError: Unexpected token './ambient_src'. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/decalre_in_ambient_context.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/decalre_in_ambient_context.ets new file mode 100644 index 0000000000..8fa28a9dfd --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/decalre_in_ambient_context.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. + */ + +export declare namespace F { + /* @@ label */declare function s(): void +} + +/* @@@ label Error SyntaxError: A 'declare' modifier cannot be used in an already ambient context. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/eval_or_arguments_in_strict_mode.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/eval_or_arguments_in_strict_mode.ets new file mode 100644 index 0000000000..0a60c142cf --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/eval_or_arguments_in_strict_mode.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. + */ + +/* @@ label1 */cosnt /* @@ label */eval = 1; + +/* @@@ label Error SyntaxError: 'eval' or 'arguments' can't be defined or assigned to in strict mode code. */ +/* @@@ label1 Error TypeError: Unresolved reference cosnt */ +/* @@@ label Error SyntaxError: Unexpected token 'eval'. */ +/* @@@ label Error TypeError: Unresolved reference eval */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/getter_setter_not_abstract.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/getter_setter_not_abstract.ets new file mode 100644 index 0000000000..f1cc239c03 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/getter_setter_not_abstract.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 User { + name_: string; + + get name/* @@ label */(): string {} +} + + +/* @@@ label Error SyntaxError: Getter and setter methods must be abstracts in the interface body. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_destructuring_target.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_destructuring_target.ets new file mode 100644 index 0000000000..977346c1fc --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/invalid_destructuring_target.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. + */ + +let f = ([!/* @@ label1 */]) /* @@ label */=> {}; + +/* @@@ label1 Error SyntaxError: Unexpected token ']'. */ +/* @@@ label Error SyntaxError: Unexpected token '=>'. */ +/* @@@ label Error SyntaxError: Invalid destructuring assignment target. */ +/* @@@ label Error SyntaxError: Unexpected ArrowParameter element. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/nullish_coalescing_missing_parens.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/nullish_coalescing_missing_parens.ets new file mode 100644 index 0000000000..de7743e5e1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/nullish_coalescing_missing_parens.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. + */ + +let a = null; +let b = 1; +let c = 5; +let result = a ?? b && c/* @@ label */; + +/* @@@ label Error SyntaxError: Nullish coalescing operator ?? requires parens when mixing with logical operators. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/type_param_list_empty.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/type_param_list_empty.ets new file mode 100644 index 0000000000..7689881b26 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/type_param_list_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 {} + +/* @@@ label Error SyntaxError: Type parameter list cannot be empty. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_arrowparam_element.ets b/ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_arrowparam_element.ets new file mode 100644 index 0000000000..c252dac978 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/syntax/unexpected_arrowparam_element.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. + */ + +let F = ([C?/* @@ label2 */]/* @@ label1 */) /* @@ label */=> {}; + +/* @@@ label2 Error SyntaxError: Unexpected token ']'. */ +/* @@@ label2 Error SyntaxError: Unexpected token, expected ':'. */ +/* @@@ label1 Error SyntaxError: Unexpected token ')'. */ +/* @@@ label1 Error SyntaxError: Unexpected token, expected ',' or ']'. */ +/* @@@ label Error SyntaxError: Unexpected token '=>'. */ +/* @@@ label Error SyntaxError: Invalid destructuring assignment target. */ +/* @@@ label Error SyntaxError: Unexpected ArrowParameter element. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/ambient_annot_impl_of_undefined_field.ets b/ets2panda/test/ast/compiler/ets/errors/type/ambient_annot_impl_of_undefined_field.ets new file mode 100644 index 0000000000..e848925826 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/ambient_annot_impl_of_undefined_field.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. + */ + +import {Person} from './ambient_src' + +@interface Person { + name: string = "Jack" + /* @@ label */age: number = 20 +} + +/* @@@ label Error TypeError: Field 'age' is not defined in the ambient annotation 'Person' */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/ambient_src.ets b/ets2panda/test/ast/compiler/ets/errors/type/ambient_src.ets new file mode 100644 index 0000000000..edca47a0b9 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/ambient_src.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 @interface Person { + name: string = "Jack" +} diff --git a/ets2panda/test/ast/compiler/ets/errors/type/coalesce_not_ref.ets b/ets2panda/test/ast/compiler/ets/errors/type/coalesce_not_ref.ets new file mode 100644 index 0000000000..4d2ef7f96c --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/coalesce_not_ref.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. + */ + +let a: number = 0; +let b: number = 5; +let x: number = /* @@ label */a ?? b; + +/* @@@ label Error TypeError: Left-hand side of nullish-coalescing expression must be a reference type. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/duplicate_accessor.ets b/ets2panda/test/ast/compiler/ets/errors/type/duplicate_accessor.ets new file mode 100644 index 0000000000..e5dd57a09b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/duplicate_accessor.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class D { + name_: string = "zz"; + get name(): string { + return this.name_ + } + get name/* @@ label */(): string { + return this.name_ + } +} + +/* @@@ label Error TypeError: Function name is already declared. */ +/* @@@ label Error TypeError: Duplicate accessor definition */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/enum_invalid_discriminant.ets b/ets2panda/test/ast/compiler/ets/errors/type/enum_invalid_discriminant.ets new file mode 100644 index 0000000000..2e8f1a7a27 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/enum_invalid_discriminant.ets @@ -0,0 +1,31 @@ +/* + * 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 User { + name: string; + age: number; +}; +const user: User = { + name: "Alice", + age: 25, +}; + +switch (/* @@ label */user){ + /* @@ label1 */case user: break; +} + + +/* @@@ label Error TypeError: Incompatible types. Found: User, required: char , byte , short , int, long , Char , Byte , Short , Int, Long , String or an enum type */ +/* @@@ label1 Error TypeError: Unexpected type User */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/generic_type_param_count_mismatch.ets b/ets2panda/test/ast/compiler/ets/errors/type/generic_type_param_count_mismatch.ets new file mode 100644 index 0000000000..5a9b88cf89 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/generic_type_param_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. + */ + +class B { + constructor(value1: T, value2: U) {} +} +const box = new /* @@ label */B(42, "Hello"); + +/* @@@ label Error TypeError: Type 'B' has 2 number of type parameters, but 1 type arguments were provided. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/main_with_rest.ets b/ets2panda/test/ast/compiler/ets/errors/type/main_with_rest.ets new file mode 100644 index 0000000000..6e2dac0b3b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/main_with_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 main(/* @@ label */...args: string[]) { + console.log(args); +} + +/* @@@ label Error TypeError: Rest parameter is not allowed in the 'main' function. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/method_accessor_collision.ets b/ets2panda/test/ast/compiler/ets/errors/type/method_accessor_collision.ets new file mode 100644 index 0000000000..550a9f67ef --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/method_accessor_collision.ets @@ -0,0 +1,26 @@ +/* + * 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 D { + age_: number = 1; + age/* @@ label */(): number { + return this.age_ + } + get age/* @@ label1 */(): number { + return this.age_ + } +} +/* @@@ label Error TypeError: Method cannot use the same name as age accessor property */ +/* @@@ label1 Error TypeError: Function age with this assembly signature already declared. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/negative_index.ets b/ets2panda/test/ast/compiler/ets/errors/type/negative_index.ets new file mode 100644 index 0000000000..172af2baf1 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/negative_index.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. + */ + +let arr: (string)[] = ['1']; + +arr[/* @@ label */-1]; + +/* @@@ label Error TypeError: Index value cannot be less than zero. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/not_cond_type.ets b/ets2panda/test/ast/compiler/ets/errors/type/not_cond_type.ets new file mode 100644 index 0000000000..504d667f3b --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/not_cond_type.ets @@ -0,0 +1,26 @@ +/* + * 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 F { + name(){ + + } +} +let f = new F(); +if (/* @@ label */f.name()) { +} + +/* @@@ label Error TypeError: Condition must be of possible condition type */ +/* @@@ label Error TypeError: Cannot use type 'void' as value. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/spread_onto_single_param.ets b/ets2panda/test/ast/compiler/ets/errors/type/spread_onto_single_param.ets new file mode 100644 index 0000000000..66b3af5d9e --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/spread_onto_single_param.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. + */ + +const numbers = [1, 2, 3]; +const allNumbers = [...numbers]; +function myFunction(a: number[], b: number[]) { +} +/* @@ label1 */myFunction(/* @@ label */...numbers, allNumbers); + +/* @@@ label1 Error TypeError: No matching call signature for myFunction(double, double[]) */ +/* @@@ label Error TypeError: Spread argument cannot be passed for ordinary parameter. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/tuple_index_nonconst.ets b/ets2panda/test/ast/compiler/ets/errors/type/tuple_index_nonconst.ets new file mode 100644 index 0000000000..9a35e671ec --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/tuple_index_nonconst.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 tupe: [string, number]; +tupe = ["hello", 42]; + +for(let i = 0; i < 2; i++) { + tupe[/* @@ label */i]; +} + +/* @@@ label Error TypeError: Only constant expression allowed for element access on tuples. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/tuple_index_not_int.ets b/ets2panda/test/ast/compiler/ets/errors/type/tuple_index_not_int.ets new file mode 100644 index 0000000000..22f1f480ee --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/tuple_index_not_int.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. + */ + +let tupe: [string, number]; +tupe = ["hello", 42]; + +tupe[/* @@ label */'1']; + +/* @@@ label Error TypeError: Only integer type allowed for element access on tuples. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/tuple_unassignable_array.ets b/ets2panda/test/ast/compiler/ets/errors/type/tuple_unassignable_array.ets new file mode 100644 index 0000000000..f4fbc84b67 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/tuple_unassignable_array.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. + */ + +let tupe: [string, number]; +tupe = [/* @@ label1 */42, /* @@ label */"hello"]; + +/* @@@ label1 Error TypeError: Array initializer's type is not assignable to tuple type at index: 0 */ +/* @@@ label Error TypeError: Array initializer's type is not assignable to tuple type at index: 1 */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/unexpected_nonvoid.ets b/ets2panda/test/ast/compiler/ets/errors/type/unexpected_nonvoid.ets new file mode 100644 index 0000000000..78fd544267 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/unexpected_nonvoid.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. + */ + +class B { + $_set/* @@ label */(p: string, p1: string){ + return 1; + } +} + + +/* @@@ label Error TypeError: 'The special predefined method '$_set' should have void return type. */ diff --git a/ets2panda/test/ast/compiler/ets/errors/type/unexpected_void.ets b/ets2panda/test/ast/compiler/ets/errors/type/unexpected_void.ets new file mode 100644 index 0000000000..71088e2fb4 --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/errors/type/unexpected_void.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 B { + $_get/* @@ label */(p: string): void { + } +} + + +/* @@@ label Error TypeError: 'The special predefined method '$_get' shouldn't have void return type. */ -- Gitee