From 66a9f0e21b08c8245637a40db12eba4feaa33376 Mon Sep 17 00:00:00 2001 From: Peter Pronai Date: Mon, 14 Jul 2025 10:12:24 +0000 Subject: [PATCH] Increase diagnostic test coverage Adds tests for some diagnostics, removes others that are not even used, merges one that has no tests (and seems to be emitted from an unreachable code path) with one that does. Fixes #26188 internal issue. Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICM8GE Testing: ast, astchecker, parser, func Change-Id: I243ce9400948affcec79f46f49c83a8974a7ed14 Signed-off-by: Peter Pronai --- ...defaultParametersInConstructorLowering.cpp | 7 ++++-- .../ast/parser/ets/default_parameter3.ets | 2 +- ets2panda/test/ast/parser/ets/nolint_bad.ets | 22 ++++++++++++++++ .../test/ast/parser/js/private_ctor_bad.js | 20 +++++++++++++++ .../test/ast/parser/js/private_number_bad.js | 20 +++++++++++++++ .../test/ast/parser/js/private_ref_bad.js | 21 ++++++++++++++++ .../ast/parser/js/private_sqbracket_bad.js | 23 +++++++++++++++++ .../test/ast/parser/js/private_string_bad.js | 20 +++++++++++++++ .../astchecker/astchecker-ets-ignored.txt | 1 - ets2panda/util/diagnostic/syntax.yaml | 25 ++++--------------- 10 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/nolint_bad.ets create mode 100644 ets2panda/test/ast/parser/js/private_ctor_bad.js create mode 100644 ets2panda/test/ast/parser/js/private_number_bad.js create mode 100644 ets2panda/test/ast/parser/js/private_ref_bad.js create mode 100644 ets2panda/test/ast/parser/js/private_sqbracket_bad.js create mode 100644 ets2panda/test/ast/parser/js/private_string_bad.js diff --git a/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp b/ets2panda/compiler/lowering/ets/defaultParametersInConstructorLowering.cpp index 3b7466ef9f8..61e62947c6d 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 a1ea174314a..80c76508f8a 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 00000000000..b4aa54d0974 --- /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 00000000000..1b9477045f2 --- /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 00000000000..94cd82cad0a --- /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 00000000000..cc4b234705d --- /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 00000000000..426ccec09f4 --- /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 00000000000..58c411b6fd9 --- /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 f6ce7f89771..857f45c9f14 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 9a9440342d6..17be683a796 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 -- Gitee