diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index c6c80448bc57d1644e616a5dbe8952548e49052e..ee42dcbb4bed991ccb7cf36539c35b8ae64c6478 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 01a023bc1fb85ad7b5d4f8c352dd8ef27e1beb15..3a4d7ee28d66e130c6375b18bfdc3baa0a308241 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