diff --git a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp index 3b7466ef9f897a990ee8dd8fc993079a97ad7dc7..61e62947c6dbe331b77f01b099267e94104b861d 100644 --- a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp +++ b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp @@ -35,8 +35,11 @@ static bool HasDefaultParameters(const ir::ScriptFunction *function, util::Diagn } if (hasRestParameter) { - util::DiagnosticMessageParams diagnosticParams = {}; - diagnosticEngine.LogDiagnostic(diagnostic::REST_PARAM_LAST, std::move(diagnosticParams), param->Start()); + // NOTE(pronai): This seems to be covered in parser. As the comment above says, it's unclear why the + // lowering is needed. + ES2PANDA_UNREACHABLE_POS(param->Start()); + diagnosticEngine.LogDiagnostic(diagnostic::REST_PARAM_NOT_LAST, util::DiagnosticMessageParams {}, + param->Start()); } if (param->IsOptional()) { diff --git a/ets2panda/test/ast/parser/ets/default_parameter3.ets b/ets2panda/test/ast/parser/ets/default_parameter3.ets index a1ea174314af3add6e8317a2595810cc60eeafa6..80c76508f8a0a8e3b18f3bd1bc9ff341ff6df977 100644 --- a/ets2panda/test/ast/parser/ets/default_parameter3.ets +++ b/ets2panda/test/ast/parser/ets/default_parameter3.ets @@ -18,4 +18,4 @@ function foo(a : int = 10, /* @@ label */b : int, c : int = 15) : int return a + b; } -/* @@@ label Error SyntaxError: Required parameter follows default parameter(s). */ +/* @@@ label Error SyntaxError: A required parameter cannot follow an optional parameter. */ diff --git a/ets2panda/test/ast/parser/ets/nolint_bad.ets b/ets2panda/test/ast/parser/ets/nolint_bad.ets new file mode 100644 index 0000000000000000000000000000000000000000..b4aa54d09744e878c4403a61fc3792f11e0aa11d --- /dev/null +++ b/ets2panda/test/ast/parser/ets/nolint_bad.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. + */ + + +// ETSNOLINT(definitely-not-a-real-etsnolint-argument) +// ETSNOLINT(@) +function main() {} +/* @@? 1:3 Error SyntaxError: Invalid argument for ETSNOLINT! */ +/* @@? 1:3 Error SyntaxError: Unexpected character for ETSNOLINT argument! [VALID ONLY: a-z, '-']. */ +/* @@? 1:3 Error SyntaxError: Invalid argument for ETSNOLINT! */ diff --git a/ets2panda/test/ast/parser/js/private_ctor_bad.js b/ets2panda/test/ast/parser/js/private_ctor_bad.js new file mode 100644 index 0000000000000000000000000000000000000000..1b9477045f2682176e219e5d18c7db2125030c6d --- /dev/null +++ b/ets2panda/test/ast/parser/js/private_ctor_bad.js @@ -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. + */ + + +class A { + #constructor(){} +} +/* @@? 18:6 Error SyntaxError: Private identifier can not be constructor. */ diff --git a/ets2panda/test/ast/parser/js/private_number_bad.js b/ets2panda/test/ast/parser/js/private_number_bad.js new file mode 100644 index 0000000000000000000000000000000000000000..94cd82cad0adec7fc72ee2b4572247a0019ed93a --- /dev/null +++ b/ets2panda/test/ast/parser/js/private_number_bad.js @@ -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. + */ + +class WeAre { + #1 +} +/* @@? 17:6 Error SyntaxError: Unexpected token in private field. */ +/* @@? 17:6 Error SyntaxError: Private identifier name can not be number. */ diff --git a/ets2panda/test/ast/parser/js/private_ref_bad.js b/ets2panda/test/ast/parser/js/private_ref_bad.js new file mode 100644 index 0000000000000000000000000000000000000000..cc4b234705d69a92b2be25ca18a4cc86fb8deede --- /dev/null +++ b/ets2panda/test/ast/parser/js/private_ref_bad.js @@ -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{ + m(){ + return this.#x + } +} +/* @@? 18:21 Error SyntaxError: Private field 'x' must be declared in an enclosing class */ diff --git a/ets2panda/test/ast/parser/js/private_sqbracket_bad.js b/ets2panda/test/ast/parser/js/private_sqbracket_bad.js new file mode 100644 index 0000000000000000000000000000000000000000..426ccec09f494b4ac77389b6317cfa181521c25e --- /dev/null +++ b/ets2panda/test/ast/parser/js/private_sqbracket_bad.js @@ -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 WeAre { + #[ +} +/* @@? 17:6 Error SyntaxError: Unexpected token in private field. */ +/* @@? 17:6 Error SyntaxError: Unexpected character in private identifier. */ +/* @@? 18:1 Error SyntaxError: Unexpected token '}'. */ +/* @@? 18:1 Error SyntaxError: Unexpected token, expected ']'. */ +/* @@? 24:1 Error SyntaxError: Expected '}', got 'end of stream'. */ diff --git a/ets2panda/test/ast/parser/js/private_string_bad.js b/ets2panda/test/ast/parser/js/private_string_bad.js new file mode 100644 index 0000000000000000000000000000000000000000..58c411b6fd9fcc16fd4c6cbaa533c681c3b85836 --- /dev/null +++ b/ets2panda/test/ast/parser/js/private_string_bad.js @@ -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. + */ + +class WeAre { + #"one" +} +/* @@? 17:6 Error SyntaxError: Unexpected token in private field. */ +/* @@? 17:6 Error SyntaxError: Private identifier name can not be string. */ diff --git a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt index f6ce7f89771847e79cca31e8d503afcabd7e9957..857f45c9f14fef63bfe2fb392c13dde024a6aff2 100644 --- a/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt +++ b/ets2panda/test/test-lists/astchecker/astchecker-ets-ignored.txt @@ -77,7 +77,6 @@ ast/compiler/ets/readonlyType_5.ets ast/parser/ets/InferTypeParamFromParam2.ets # Issue: #23080 -ast/parser/ets/default_parameter3.ets ast/parser/ets/default_parameters_multi_error.ets ast/parser/ets/rest_parameter_03.ets diff --git a/ets2panda/util/diagnostic/syntax.yaml b/ets2panda/util/diagnostic/syntax.yaml index 9a9440342d68c36cb550610b74158cd609639d22..17be683a79678cebc0e27690a1628748332a485c 100644 --- a/ets2panda/util/diagnostic/syntax.yaml +++ b/ets2panda/util/diagnostic/syntax.yaml @@ -398,10 +398,6 @@ syntax: id: 172 message: "Illegal newline after throw." -- name: ILLEGAL_START_EXPRESSION - id: 208 - message: "Illegal start of expression." - - name: ILLEGAL_START_STRUCT_CLASS id: 40 message: "Illegal start of {} expression." @@ -459,10 +455,6 @@ syntax: id: 18 message: "Index type must be number in index signature." -- name: INITIALIZERS_INTERFACE_PROPS - id: 123 - message: "Initializers are not allowed on interface properties." - - name: INITIALIZERS_IN_AMBIENT_CONTEXTS id: 125 message: "Initializers are not allowed in ambient contexts." @@ -822,10 +814,6 @@ syntax: id: 73 message: "'new.Target' is not allowed here." -- name: NEW_TARGET_WITH_ESCAPED_CHARS - id: 74 - message: "'new.Target' must not contain escaped characters." - - name: NEW_WITH_IMPORT id: 60 message: "Cannot use new with import(...)." @@ -878,10 +866,6 @@ syntax: id: 321 message: "initModule() only accept string literal as argument." -- name: ONLY_THROWS_IN_FUN_TYPE - id: 103 - message: "Only 'throws' can be used with function types." - - name: OPTIONAL_VARIABLE id: 306 message: "Optional variable is deprecated and no longer supported." @@ -990,10 +974,6 @@ syntax: id: 15 message: "Both optional and rest parameters are not allowed in function's parameter list." -- name: REST_PARAM_LAST - id: 236 - message: "Rest parameter should be the last one." - - name: REST_PARAM_NOT_LAST id: 67 message: "Rest parameter must be the last formal parameter." @@ -1271,13 +1251,18 @@ graveyard: - 29 - 37 - 41 +- 74 +- 103 - 109 +- 123 - 139 - 142 - 152 - 157 +- 208 - 218 - 235 +- 236 - 272 - 274 - 275