diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 6b8010a45d5bde99cd24576b3b2dc12bb04d2776..f30bf40f8e88a43a1e4d8b3ab3697c2f868e1108 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 1c858dc1e1aac2057224f507ae790b707a338f32..78878b39c241b97c7abe6cf239e8640ea7728f7a 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