From 5e0305873727e0f03bc21cad4eca34837c230670 Mon Sep 17 00:00:00 2001 From: cihatfurkaneken Date: Fri, 15 Aug 2025 15:31:59 +0300 Subject: [PATCH] arkts-no-ts-like-smart-type false error fix Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICT167 Signed-off-by: cihatfurkaneken --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 15 +++++++++++--- .../test/main/no_ts_like_smart_type.ets | 20 ++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 6b8010a45d..f30bf40f8e 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -12295,7 +12295,16 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { staticProps: Map, instanceProps: Map ): void { - forEachNodeInSubtree(body, (node) => { + const stopCondition = (node: ts.Node): boolean => { + return ( + ts.isFunctionDeclaration(node) || + ts.isFunctionExpression(node) || + ts.isMethodDeclaration(node) || + ts.isAccessor(node) || + ts.isArrowFunction(node) + ); + }; + const callback = (node: ts.Node): void => { if (!ts.isReturnStatement(node) || !node.expression) { return; } @@ -12303,7 +12312,6 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (ts.isPropertyAccessExpression(expr)) { return expr; } - if (ts.isCallExpression(expr) && ts.isPropertyAccessExpression(expr.expression)) { return expr.expression; } @@ -12327,7 +12335,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (isInstancePropertyAccess(node.expression)) { this.checkPropertyAccess(node, node.expression as ts.PropertyAccessExpression, instanceProps, methodReturnType); } - }); + }; + forEachNodeInSubtree(body, callback, stopCondition); } private checkPropertyAccess( diff --git a/ets2panda/linter/test/main/no_ts_like_smart_type.ets b/ets2panda/linter/test/main/no_ts_like_smart_type.ets index 1c858dc1e1..78878b39c2 100755 --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets @@ -231,4 +231,22 @@ export class N extends T { toString(): string { return this._t // legal } -} \ No newline at end of file +} + +type AsyncCB = () => T | Promise; + +class AsyncLock { + lockAsync(callback: AsyncCB): Promise { + } +} + +export class AB { + private count_: number = 0 + public lock_: AsyncLock = new AsyncLock(); + + public async getCount(): Promise { + return this.lock_.lockAsync(() => { + return this.count_; //legal + }) + } +} \ No newline at end of file -- Gitee