From 0555cc7d38aa7e1e536bd0bdd0cbcc757e68e824 Mon Sep 17 00:00:00 2001 From: ZhongNing Date: Fri, 6 Jun 2025 15:20:09 +0800 Subject: [PATCH] Fix for IsConcurrentDeprecated Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICD38U Test scenarios: fix bug Signed-off-by: ZhongNing --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 38 +++++------- .../linter/test/concurrent/@ohos.taskpool.ets | 25 ++++++++ .../concurrent/@ohos.taskpool.ets.args.json | 18 ++++++ .../test/concurrent/@ohos.taskpool.ets.json | 17 ++++++ .../no_support_isconcurrent.ets.arkts2.json | 20 ------- .../concurrent/no_support_isconcurrent2.ets | 42 ++++++++++++++ .../no_support_isconcurrent2.ets.args.json | 19 ++++++ .../no_support_isconcurrent2.ets.arkts2.json | 58 +++++++++++++++++++ .../no_support_isconcurrent2.ets.json | 17 ++++++ 9 files changed, 212 insertions(+), 42 deletions(-) create mode 100755 ets2panda/linter/test/concurrent/@ohos.taskpool.ets create mode 100755 ets2panda/linter/test/concurrent/@ohos.taskpool.ets.args.json create mode 100755 ets2panda/linter/test/concurrent/@ohos.taskpool.ets.json create mode 100755 ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets create mode 100755 ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.args.json create mode 100755 ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.arkts2.json create mode 100755 ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.json diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index ec2c5e4463..564091114a 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -47,7 +47,6 @@ import { PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE } from './utils/consts/PropertyH import { CONCURRENT_DECORATOR, ISCONCURRENT, - TASKPOOL, SENDABLE_DECORATOR, SENDABLE_DECORATOR_NODES, SENDABLE_FUNCTION_UNSUPPORTED_STAGES_IN_API12, @@ -1499,36 +1498,31 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!ts.isCallExpression(node.parent)) { return; } - const methodName = node.name.getText(); if (methodName !== ISCONCURRENT) { return; } - - const symbol = this.tsUtils.trueSymbolAtLocation(node.expression); - if (!symbol) { + const moduleSpecifier = this.findModuleSpecifierforDepricatedIsConcurrent(node); + if (!moduleSpecifier || !ts.isStringLiteral(moduleSpecifier)) { return; } + if ( + TASKPOOL_MODULES.some((moduleName) => { + return TsUtils.removeOrReplaceQuotes(moduleSpecifier.getText(), false) === moduleName; + }) + ) { + this.incrementCounters(node.name, FaultID.IsConcurrentDeprecated); + } + } - if (symbol.name === TASKPOOL) { - const decl = TsUtils.getDeclaration(symbol); - - if (!decl) { - return; - } - - const sourceFile = decl.getSourceFile(); - const fileName = path.basename(sourceFile.fileName); - - if ( - TASKPOOL_MODULES.some((moduleName) => { - return fileName.startsWith(moduleName); - }) - ) { - this.incrementCounters(node.name, FaultID.IsConcurrentDeprecated); - } + findModuleSpecifierforDepricatedIsConcurrent(node: ts.PropertyAccessExpression): ts.Expression | undefined { + let symbol = this.tsUtils.trueSymbolAtLocation(node.expression); + if (symbol && 'unknown' === symbol.name) { + symbol = this.tsTypeChecker.getSymbolAtLocation(node.expression); } + const importDecl = ts.findAncestor(TsUtils.getDeclaration(symbol), ts.isImportDeclaration); + return importDecl?.moduleSpecifier; } checkFunctionProperty( diff --git a/ets2panda/linter/test/concurrent/@ohos.taskpool.ets b/ets2panda/linter/test/concurrent/@ohos.taskpool.ets new file mode 100755 index 0000000000..a2a9094098 --- /dev/null +++ b/ets2panda/linter/test/concurrent/@ohos.taskpool.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ +type func = ()=>void +export namespace taskpool{ + export function isConcurrent(param:func):boolean { + return true + } +} +export namespace otherTaskPool{ + export function isConcurrent(param:func):boolean { + return true + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/@ohos.taskpool.ets.args.json b/ets2panda/linter/test/concurrent/@ohos.taskpool.ets.args.json new file mode 100755 index 0000000000..0adede204e --- /dev/null +++ b/ets2panda/linter/test/concurrent/@ohos.taskpool.ets.args.json @@ -0,0 +1,18 @@ +{ + "copyright": [ + "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." + ], + "mode": { + } +} diff --git a/ets2panda/linter/test/concurrent/@ohos.taskpool.ets.json b/ets2panda/linter/test/concurrent/@ohos.taskpool.ets.json new file mode 100755 index 0000000000..9f305c86d7 --- /dev/null +++ b/ets2panda/linter/test/concurrent/@ohos.taskpool.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "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." + ], + "result": [] +} diff --git a/ets2panda/linter/test/concurrent/no_support_isconcurrent.ets.arkts2.json b/ets2panda/linter/test/concurrent/no_support_isconcurrent.ets.arkts2.json index 9b627b9d72..428032b2d8 100644 --- a/ets2panda/linter/test/concurrent/no_support_isconcurrent.ets.arkts2.json +++ b/ets2panda/linter/test/concurrent/no_support_isconcurrent.ets.arkts2.json @@ -23,26 +23,6 @@ "suggest": "", "rule": "Usage of standard library is restricted(arkts-limited-stdlib-no-concurrent-decorator)", "severity": "ERROR" - }, - { - "line": 23, - "column": 32, - "endLine": 23, - "endColumn": 44, - "problem": "IsConcurrentDeprecated", - "suggest": "", - "rule": "isConcurrent is not supported (arkts-limited-stdlib-no-support-isConcurrent)", - "severity": "ERROR" - }, - { - "line": 25, - "column": 27, - "endLine": 25, - "endColumn": 39, - "problem": "IsConcurrentDeprecated", - "suggest": "", - "rule": "isConcurrent is not supported (arkts-limited-stdlib-no-support-isConcurrent)", - "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets new file mode 100755 index 0000000000..2db768e0e8 --- /dev/null +++ b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets @@ -0,0 +1,42 @@ +/* + * 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 { taskpool } from '@ohos.taskpool'; +import { taskpool as taskpool2 } from './@ohos.taskpool'; +import { otherTaskPool as taskpool1 } from './@ohos.taskpool'; + +function test1(){ +} +function isConcurrent() {} + +typeof taskpool.isConcurrent() ; //error +function test(){ + taskpool.isConcurrent(test5()) ; //error +} + +console.log(''+taskpool2.isConcurrent(test1)); + +taskpool2.isConcurrent(test1) +taskpool2.isConcurrent(test1) +taskpool2.isConcurrent(isConcurrent) +function test5(){ + taskpool2.isConcurrent(test1) + taskpool2.isConcurrent(test1) + taskpool2.isConcurrent(isConcurrent) +} +class Demo{ + get(){ + return taskpool1.isConcurrent(test); + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.args.json b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.args.json new file mode 100755 index 0000000000..e2b903f0aa --- /dev/null +++ b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "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." + ], + "mode": { + "arkts2": "" + } + } \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.arkts2.json b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.arkts2.json new file mode 100755 index 0000000000..b418f42b21 --- /dev/null +++ b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.arkts2.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "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." + ], + "result": [ + { + "line": 15, + "column": 1, + "endLine": 15, + "endColumn": 43, + "problem": "LimitedStdLibNoImportConcurrency", + "suggest": "", + "rule": "Import Concurrency is not required (arkts-limited-stdlib-no-import-concurrency)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 17, + "endLine": 23, + "endColumn": 29, + "problem": "IsConcurrentDeprecated", + "suggest": "", + "rule": "isConcurrent is not supported (arkts-limited-stdlib-no-support-isConcurrent)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 12, + "endLine": 25, + "endColumn": 24, + "problem": "IsConcurrentDeprecated", + "suggest": "", + "rule": "isConcurrent is not supported (arkts-limited-stdlib-no-support-isConcurrent)", + "severity": "ERROR" + }, + { + "line": 25, + "column": 25, + "endLine": 25, + "endColumn": 32, + "problem": "LimitedVoidType", + "suggest": "", + "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.json b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.json new file mode 100755 index 0000000000..b9331d05ba --- /dev/null +++ b/ets2panda/linter/test/concurrent/no_support_isconcurrent2.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "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." + ], + "result": [] + } \ No newline at end of file -- Gitee