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 0000000000000000000000000000000000000000..b1742f0904d6633fd9b9f26522bf17f5c933d53f --- /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 0000000000000000000000000000000000000000..4ad076809c979c88e0a213c8f308c22e0c69c5e1 --- /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 0000000000000000000000000000000000000000..87f5f5d42b9d82e7d425f96172508cc993fdaba9 --- /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 0000000000000000000000000000000000000000..3fa4db972b6a78a9cd0b5bc02141a4989bdcdae7 --- /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 0000000000000000000000000000000000000000..8fa28a9dfd60bedc97dd19a34a2158e3057d38a1 --- /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 0000000000000000000000000000000000000000..0a60c142cf451617e25dfc9a7ea542f40fca3734 --- /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 0000000000000000000000000000000000000000..f1cc239c03adb15c2d20f2d25a77b599aab4e907 --- /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 0000000000000000000000000000000000000000..977346c1fc847a8039ed848d22c0f35e4c1e4837 --- /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 0000000000000000000000000000000000000000..de7743e5e147db81827e77cc1650a7497eb9adda --- /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 0000000000000000000000000000000000000000..7689881b26f56d6667fc302120ca63d3f193db33 --- /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 0000000000000000000000000000000000000000..c252dac978ff97dbcfd3e63473e4dc6451847542 --- /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 0000000000000000000000000000000000000000..e848925826876399d475d57e90ef4cd98b96a733 --- /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 0000000000000000000000000000000000000000..edca47a0b91445a525b3b8e372e5aa25a3bb80bf --- /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 0000000000000000000000000000000000000000..4d2ef7f96c174f453dc31f0619cac7bc2851fb92 --- /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 0000000000000000000000000000000000000000..e5dd57a09b1356ccffe518ce668dfea2b21f00fe --- /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 0000000000000000000000000000000000000000..2e8f1a7a273db4ffdfc103228c3eaf0a79633c42 --- /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 0000000000000000000000000000000000000000..5a9b88cf89aad3fb9c6754cdcdefd526fecbd760 --- /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 0000000000000000000000000000000000000000..6e2dac0b3bde90ef1f85f875be4fddd4c4c6748e --- /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 0000000000000000000000000000000000000000..550a9f67ef5dc63264eabb823c11d1ed13e51b63 --- /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 0000000000000000000000000000000000000000..172af2baf1ec11b46c8c569fa1ba653b9e97857d --- /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 0000000000000000000000000000000000000000..504d667f3b86f928c8e8ef0b365148eb0d57d81e --- /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 0000000000000000000000000000000000000000..66b3af5d9ea887d0c7872e142a261f4fdb878878 --- /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 0000000000000000000000000000000000000000..9a35e671ec14558a13a53f173dcce472a4880d47 --- /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 0000000000000000000000000000000000000000..22f1f480ee84045e737c68b9bfb62fcb6ead3349 --- /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 0000000000000000000000000000000000000000..f4fbc84b67c0a68c11d0cb4e69cd9f16f3c9b6d6 --- /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 0000000000000000000000000000000000000000..78fd5442678232fa92b1702055da0e56a6df1cb4 --- /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 0000000000000000000000000000000000000000..71088e2fb4f660feea17e39b55776878ee3fcec3 --- /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. */