diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index 7c737747445c840b142e2223111bde513849cff4..447911d476a3131d1fe21c1f3b6c91047bd25771 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 0000000000000000000000000000000000000000..c41e5717791985674c5147b410fb50d8c3aa2d54 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 0000000000000000000000000000000000000000..c2495eb8c3919dd79cb3ed585a426ec4404f02a3 --- /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 0000000000000000000000000000000000000000..c2495eb8c3919dd79cb3ed585a426ec4404f02a3 --- /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 74dd53cce33797a457b90eb6c0f1ab88f8ca5e2a..dbb1daca9084a4d3c52d4f63c5a3e071e2426b9a 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 0000000000000000000000000000000000000000..c41e5717791985674c5147b410fb50d8c3aa2d54 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/linter/test_regression/15086.ts.relax.json b/linter/test_regression/15086.ts.relax.json new file mode 100644 index 0000000000000000000000000000000000000000..c2495eb8c3919dd79cb3ed585a426ec4404f02a3 --- /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 0000000000000000000000000000000000000000..c2495eb8c3919dd79cb3ed585a426ec4404f02a3 --- /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": [] +}