From cd00ac3ccf29c5e43be34eac1478dff51024cc4d Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Wed, 16 Jul 2025 15:52:28 +0800 Subject: [PATCH] fix arkts-incompatible-function-types Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMN5P Test scenarios:Fix bugs for arkts-incompatible-function-types Signed-off-by: zhongning5 --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 6 ++++-- .../test/main/incompatible_function.ets.arkts2.json | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 666921f942..447a600f58 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -3649,7 +3649,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!ts.isClassDeclaration(classDecl)) { return; } - + this.checkIncompatibleFunctionTypes(node); const isStatic = node.modifiers?.some((mod) => { return mod.kind === ts.SyntaxKind.StaticKeyword; @@ -3663,7 +3663,6 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (allBaseTypes && allBaseTypes.length > 0) { this.checkMethodType(allBaseTypes, methodName, node); } - this.checkIncompatibleFunctionTypes(node); } private checkMethodType(allBaseTypes: ts.Type[], methodName: string, node: ts.MethodDeclaration): void { @@ -3708,6 +3707,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (declaredReturnTypeStr === actualReturnTypeStr) { return; } + if (actualReturnType.flags & ts.TypeFlags.Any || declaredReturnType.flags & ts.TypeFlags.Any) { + return; + } if (this.isSubtypeByBaseTypesList(actualReturnType, declaredReturnType)) { this.incrementCounters(returnStmt.expression, FaultID.IncompationbleFunctionType); return; diff --git a/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json b/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json index 83f24a944f..2757f6f80c 100644 --- a/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json +++ b/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json @@ -204,6 +204,16 @@ "rule": "Numeric semantics is different for integer values (arkts-numeric-semantic)", "severity": "ERROR" }, + { + "line": 92, + "column": 12, + "endLine": 92, + "endColumn": 20, + "problem": "IncompationbleFunctionType", + "suggest": "", + "rule": "Stricter assignments into variables of function type (arkts-incompatible-function-types)", + "severity": "ERROR" + }, { "line": 92, "column": 12, -- Gitee