From c4bcb90c535892be0802352a6af9bc6165c24c78 Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Thu, 29 May 2025 16:00:05 +0800 Subject: [PATCH] fix arkts-no-ts-like-smart-type https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICB9GI Test scenarios:Fix bugs for arkts-no-ts-like-smart-type Signed-off-by: zhongning5 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 5 +++-- ets2panda/linter/test/main/no_ts_like_smart_type.ets | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index c6c80448bc..ee42dcbb4b 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -8889,11 +8889,12 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } - if (className && isStaticPropertyAccess(returnStmt.expression, className)) { + const returnType = this.tsTypeChecker.getTypeAtLocation(returnStmt.expression); + if (className && isStaticPropertyAccess(returnStmt.expression, className) && returnType.isUnion()) { this.incrementCounters(returnStmt, FaultID.NoTsLikeSmartType); } - if (isInstancePropertyAccess(returnStmt.expression)) { + if (isInstancePropertyAccess(returnStmt.expression) && returnType.isUnion()) { this.incrementCounters(returnStmt, FaultID.NoTsLikeSmartType); } }); 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 01a023bc1f..3a4d7ee28d 100755 --- a/ets2panda/linter/test/main/no_ts_like_smart_type.ets +++ b/ets2panda/linter/test/main/no_ts_like_smart_type.ets @@ -31,4 +31,10 @@ class AA2 { } return this.instance; // Error } +} +class A { + private static instance:A = new A(); + static get():A { + return A.instance; + } } \ No newline at end of file -- Gitee