From 449e21533935d572e34434b1ae62eafd8cbf0a0f Mon Sep 17 00:00:00 2001 From: zhongning Date: Tue, 24 Jun 2025 10:47:25 +0800 Subject: [PATCH] fix bug for arrayindextype Signed-off-by: zhongning --- ets2panda/linter/src/lib/TypeScriptLinter.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 6bb631d6bb..ae2004cddc 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -4034,7 +4034,13 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } private checkArrayIndexType(exprType: ts.Type, argType: ts.Type, expr: ts.ElementAccessExpression): void { + console.error("SJY expr = " +expr.getText()) + console.error("SJY argType = " + this.tsTypeChecker.typeToString(argType)) + console.error("SJY exprType = " + this.tsTypeChecker.typeToString(exprType)) + console.error("SJY isOrDerivedFrom = " +this.tsUtils.isOrDerivedFrom(exprType, this.tsUtils.isIndexableArray)) + console.error("SJY isIndexableArray = " + this.tsUtils.isIndexableArray(exprType)) if (!this.options.arkts2 || !this.tsUtils.isOrDerivedFrom(exprType, this.tsUtils.isIndexableArray)) { + console.error("SJY return") return; } @@ -4046,7 +4052,6 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { STRINGLITERAL_CHAR ]; const argTypeString = this.tsTypeChecker.typeToString(argType); - if (this.tsUtils.isNumberLikeType(argType)) { this.handleNumericArgument(expr.argumentExpression, argType); } else if (!validStringLiteralTypes.includes(argTypeString)) { @@ -4068,9 +4073,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.incrementCounters(argExpr, FaultID.ArrayIndexExprType, autofix); } } else if (this.tsTypeChecker.typeToString(argType) === 'number') { - if (this.isArrayIndexValidNumber(argExpr)) { - return; - } + // if (this.isArrayIndexValidNumber(argExpr)) { + // return; + // } const autofix = this.autofixer?.fixArrayIndexExprType(argExpr); this.incrementCounters(argExpr, FaultID.ArrayIndexExprType, autofix); } else { -- Gitee