From 1402cc75836c0accba4a3258bada555e2f553ed3 Mon Sep 17 00:00:00 2001 From: Nazarov Konstantin Date: Thu, 28 Dec 2023 14:30:25 +0300 Subject: [PATCH] [arkts-linter] fix #15086 Signed-off-by: Nazarov Konstantin --- linter-4.2/src/TypeScriptLinter.ts | 5 +-- linter-4.2/test_regression/15086.ts | 38 +++++++++++++++++++ .../test_regression/15086.ts.autofix.skip | 0 .../test_regression/15086.ts.relax.json | 17 +++++++++ .../test_regression/15086.ts.strict.json | 17 +++++++++ linter/lib/TypeScriptLinter.ts | 2 +- linter/test_regression/15086.ts | 38 +++++++++++++++++++ linter/test_regression/15086.ts.autofix.skip | 0 linter/test_regression/15086.ts.relax.json | 17 +++++++++ linter/test_regression/15086.ts.strict.json | 17 +++++++++ 10 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 linter-4.2/test_regression/15086.ts create mode 100644 linter-4.2/test_regression/15086.ts.autofix.skip create mode 100644 linter-4.2/test_regression/15086.ts.relax.json create mode 100644 linter-4.2/test_regression/15086.ts.strict.json create mode 100644 linter/test_regression/15086.ts create mode 100644 linter/test_regression/15086.ts.autofix.skip create mode 100644 linter/test_regression/15086.ts.relax.json create mode 100644 linter/test_regression/15086.ts.strict.json diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index 7c737747..447911d4 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -1998,10 +1998,7 @@ export class TypeScriptLinter { // spread assignment is disabled // spread element is allowed only for arrays as rest parameter if (ts.isSpreadElement(node)) { - let spreadElemNode = node as ts.SpreadElement; - let spreadExprType = this.tsTypeChecker.getTypeAtLocation( - spreadElemNode.expression - ); + const spreadExprType = this.tsUtils.getTypeOrTypeConstraintAtLocation(node.expression); if (spreadExprType) { if (ts.isCallLikeExpression(node.parent) || ts.isArrayLiteralExpression(node.parent)) { if (this.tsUtils.isOrDerivedFrom(spreadExprType, this.tsUtils.isArray)) { diff --git a/linter-4.2/test_regression/15086.ts b/linter-4.2/test_regression/15086.ts new file mode 100644 index 00000000..c41e5717 --- /dev/null +++ b/linter-4.2/test_regression/15086.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022-2023 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 foo1(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} + +function foo2(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} + +function foo3>(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} + +function foo4>(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} diff --git a/linter-4.2/test_regression/15086.ts.autofix.skip b/linter-4.2/test_regression/15086.ts.autofix.skip new file mode 100644 index 00000000..e69de29b diff --git a/linter-4.2/test_regression/15086.ts.relax.json b/linter-4.2/test_regression/15086.ts.relax.json new file mode 100644 index 00000000..c2495eb8 --- /dev/null +++ b/linter-4.2/test_regression/15086.ts.relax.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 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." + ], + "nodes": [] +} diff --git a/linter-4.2/test_regression/15086.ts.strict.json b/linter-4.2/test_regression/15086.ts.strict.json new file mode 100644 index 00000000..c2495eb8 --- /dev/null +++ b/linter-4.2/test_regression/15086.ts.strict.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 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." + ], + "nodes": [] +} diff --git a/linter/lib/TypeScriptLinter.ts b/linter/lib/TypeScriptLinter.ts index 74dd53cc..dbb1daca 100644 --- a/linter/lib/TypeScriptLinter.ts +++ b/linter/lib/TypeScriptLinter.ts @@ -1921,7 +1921,7 @@ export class TypeScriptLinter { * spread element is allowed only for arrays as rest parameter */ if (ts.isSpreadElement(node)) { - const spreadExprType = this.tsTypeChecker.getTypeAtLocation(node.expression); + const spreadExprType = this.tsUtils.getTypeOrTypeConstraintAtLocation(node.expression); if (spreadExprType) { if (ts.isCallLikeExpression(node.parent) || ts.isArrayLiteralExpression(node.parent)) { if (this.tsUtils.isOrDerivedFrom(spreadExprType, this.tsUtils.isArray)) { diff --git a/linter/test_regression/15086.ts b/linter/test_regression/15086.ts new file mode 100644 index 00000000..c41e5717 --- /dev/null +++ b/linter/test_regression/15086.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022-2023 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 foo1(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} + +function foo2(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} + +function foo3>(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} + +function foo4>(cb: (...args: T) => void) { + return (...args: T) => { + cb(...args); + }; +} diff --git a/linter/test_regression/15086.ts.autofix.skip b/linter/test_regression/15086.ts.autofix.skip new file mode 100644 index 00000000..e69de29b diff --git a/linter/test_regression/15086.ts.relax.json b/linter/test_regression/15086.ts.relax.json new file mode 100644 index 00000000..c2495eb8 --- /dev/null +++ b/linter/test_regression/15086.ts.relax.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 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." + ], + "nodes": [] +} diff --git a/linter/test_regression/15086.ts.strict.json b/linter/test_regression/15086.ts.strict.json new file mode 100644 index 00000000..c2495eb8 --- /dev/null +++ b/linter/test_regression/15086.ts.strict.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 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." + ], + "nodes": [] +} -- Gitee