From 79d39dc4697ca52fd3d03c0c9fd8ad4631af6329 Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Sat, 28 Jun 2025 14:29:51 +0800 Subject: [PATCH] fix arkts-no-inferred-generic-params Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICICX6 Test scenarios:Fix bugs for arkts-no-inferred-generic-params Signed-off-by: zhongning5 --- ets2panda/linter/rule-config.json | 2 +- ets2panda/linter/src/lib/CookBookMsg.ts | 2 +- ets2panda/linter/src/lib/TypeScriptLinter.ts | 20 ++++---- .../test/main/func_inferred_type_args_2.ets | 12 ++++- .../func_inferred_type_args_2.ets.arkts2.json | 50 +++++++++++++++++++ ...func_inferred_type_args_2.ets.autofix.json | 50 +++++++++++++++++++ .../func_inferred_type_args_2.ets.migrate.ets | 12 ++++- ...func_inferred_type_args_2.ets.migrate.json | 50 +++++++++++++++++++ .../test/ohmurl/ohmurl_import.ets.arkts2.json | 10 ++-- .../ohmurl/ohmurl_import.ets.autofix.json | 10 ++-- 10 files changed, 195 insertions(+), 23 deletions(-) diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 86ed49ff43..21370cd2c5 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -123,7 +123,7 @@ "arkts-builtin-cotr" ], "OHMURL": [ - "arkts-ohmurl-full-path" + "arkts-require-fullpath-name" ], "sdk": [ "sdk-limited-void-type", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 31ef5659cb..ee3dd98206 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -291,7 +291,7 @@ cookBookTag[285] = '"setAndProp" function is not supported (arkui-no-setandprop- cookBookTag[286] = 'Parameters decorated with "@Prop" need to call the specific method when receiving data to ensure deep copy of the data (arkui-prop-need-call-method-for-deep-copy)'; cookBookTag[300] = 'The function type should be explicit (arkts-no-ts-like-function-call)'; -cookBookTag[301] = 'Importing from "oh module" requires specifying full path (arkts-ohmurl-full-path)'; +cookBookTag[301] = 'Importing from "oh module" requires specifying full path (arkts-require-fullpath-name)'; cookBookTag[302] = 'Class type is not compatible with "Object" parameter in interop call (arkts-interop-d2s-static-object-on-dynamic-instance)'; cookBookTag[303] = diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 1760649828..7e5377a104 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -4804,8 +4804,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } private handleGenericCallWithNoTypeArgs( - callLikeExpr: ts.CallExpression | ts.NewExpression, - callSignature: ts.Signature + callLikeExpr: ts.CallExpression | ts.NewExpression | ts.ExpressionWithTypeArguments, + callSignature?: ts.Signature ): void { /* @@ -4819,19 +4819,20 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.incrementCounters(callLikeExpr, FaultID.GenericCallNoTypeArgs, autofix); return; } - this.checkTypeArgumentsForGenericCallWithNoTypeArgs(callLikeExpr, callSignature); + if (callSignature) { + this.checkTypeArgumentsForGenericCallWithNoTypeArgs(callLikeExpr, callSignature); + } } - private static isInvalidBuiltinGenericConstructorCall(newExpression: ts.CallExpression | ts.NewExpression): boolean { - if (!ts.isNewExpression(newExpression)) { - return false; - } + private static isInvalidBuiltinGenericConstructorCall( + newExpression: ts.CallExpression | ts.NewExpression | ts.ExpressionWithTypeArguments + ): boolean { const isBuiltin = BUILTIN_GENERIC_CONSTRUCTORS.has(newExpression.expression.getText().replace(/Constructor$/, '')); return isBuiltin && (!newExpression.typeArguments || newExpression.typeArguments.length === 0); } private checkTypeArgumentsForGenericCallWithNoTypeArgs( - callLikeExpr: ts.CallExpression | ts.NewExpression, + callLikeExpr: ts.CallExpression | ts.NewExpression | ts.ExpressionWithTypeArguments, callSignature: ts.Signature ): void { if (ts.isNewExpression(callLikeExpr) && this.isNonGenericClass(callLikeExpr)) { @@ -4872,7 +4873,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } private checkForUnknownTypeInNonArkTS2( - callLikeExpr: ts.CallExpression | ts.NewExpression, + callLikeExpr: ts.CallExpression | ts.NewExpression | ts.ExpressionWithTypeArguments, resolvedTypeArgs: ts.NodeArray, startTypeArg: number ): void { @@ -7141,6 +7142,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (node.token === ts.SyntaxKind.ExtendsKeyword || node.token === ts.SyntaxKind.ImplementsKeyword) { node.types.forEach((type) => { const expr = type.expression; + this.handleGenericCallWithNoTypeArgs(type); if (ts.isCallExpression(expr)) { this.incrementCounters(expr, FaultID.ExtendsExpression); return; diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets index 0df022ea8f..80246fcd42 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets @@ -107,4 +107,14 @@ class A { } else { } } -} \ No newline at end of file +} +class SubArr extends Array {} +let subArr = new SubArr(); +class SubSet extends Set{} +let subSet = new SubSet(); +class SubMap extends Map{} +let subMap = new SubMap(); +class SubWeakMap extends WeakMap{} +let subWeakMap = new SubWeakMap(); +class SubWeakSet extends WeakSet{} +let subWeakSet = new SubWeakSet(); diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json index 91c50bde47..d1ca60d4ff 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json @@ -484,6 +484,56 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 111, + "column": 22, + "endLine": 111, + "endColumn": 27, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 113, + "column": 22, + "endLine": 113, + "endColumn": 25, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 22, + "endLine": 115, + "endColumn": 25, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 117, + "column": 26, + "endLine": 117, + "endColumn": 33, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 119, + "column": 26, + "endLine": 119, + "endColumn": 33, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json index f32d5755fd..c53b7da247 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json @@ -748,6 +748,56 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 111, + "column": 22, + "endLine": 111, + "endColumn": 27, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 113, + "column": 22, + "endLine": 113, + "endColumn": 25, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 115, + "column": 22, + "endLine": 115, + "endColumn": 25, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 117, + "column": 26, + "endLine": 117, + "endColumn": 33, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 119, + "column": 26, + "endLine": 119, + "endColumn": 33, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets index 92362e1c98..12acc316b7 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets @@ -114,4 +114,14 @@ class A { } else { } } -} \ No newline at end of file +} +class SubArr extends Array {} +let subArr = new SubArr(); +class SubSet extends Set{} +let subSet = new SubSet(); +class SubMap extends Map{} +let subMap = new SubMap(); +class SubWeakMap extends WeakMap{} +let subWeakMap = new SubWeakMap(); +class SubWeakSet extends WeakSet{} +let subWeakSet = new SubWeakSet(); diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json index e45393b94a..0b10990af1 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json @@ -244,6 +244,56 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 118, + "column": 22, + "endLine": 118, + "endColumn": 27, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 120, + "column": 22, + "endLine": 120, + "endColumn": 25, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 122, + "column": 22, + "endLine": 122, + "endColumn": 25, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 124, + "column": 26, + "endLine": 124, + "endColumn": 33, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 126, + "column": 26, + "endLine": 126, + "endColumn": 33, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 110, "column": 22, diff --git a/ets2panda/linter/test/ohmurl/ohmurl_import.ets.arkts2.json b/ets2panda/linter/test/ohmurl/ohmurl_import.ets.arkts2.json index 04102fd8c9..38bbc17073 100644 --- a/ets2panda/linter/test/ohmurl/ohmurl_import.ets.arkts2.json +++ b/ets2panda/linter/test/ohmurl/ohmurl_import.ets.arkts2.json @@ -21,7 +21,7 @@ "endColumn": 60, "problem": "OhmUrlFullPath", "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -31,7 +31,7 @@ "endColumn": 56, "problem": "OhmUrlFullPath", "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -41,7 +41,7 @@ "endColumn": 45, "problem": "OhmUrlFullPath", "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -51,7 +51,7 @@ "endColumn": 52, "problem": "OhmUrlFullPath", "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -61,7 +61,7 @@ "endColumn": 48, "problem": "OhmUrlFullPath", "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" } ] diff --git a/ets2panda/linter/test/ohmurl/ohmurl_import.ets.autofix.json b/ets2panda/linter/test/ohmurl/ohmurl_import.ets.autofix.json index dee154796f..c81032fb95 100644 --- a/ets2panda/linter/test/ohmurl/ohmurl_import.ets.autofix.json +++ b/ets2panda/linter/test/ohmurl/ohmurl_import.ets.autofix.json @@ -28,7 +28,7 @@ } ], "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -45,7 +45,7 @@ } ], "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -62,7 +62,7 @@ } ], "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -79,7 +79,7 @@ } ], "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" }, { @@ -96,7 +96,7 @@ } ], "suggest": "", - "rule": "Importing from \"oh module\" requires specifying full path (arkts-ohmurl-full-path)", + "rule": "Importing from \"oh module\" requires specifying full path (arkts-require-fullpath-name)", "severity": "ERROR" } ] -- Gitee