diff --git a/ets2panda/linter/package.json b/ets2panda/linter/package.json index c31c058543a4800a94179be7fd3ff790f5a91b32..8005b794863ea5fcef055cbca09374af90ebd62a 100644 --- a/ets2panda/linter/package.json +++ b/ets2panda/linter/package.json @@ -20,12 +20,13 @@ "pack:linter": "rimraf bundle && mkdir bundle && npm pack && mv panda-tslinter-*.tgz bundle", "pretest": " npm run fix", "test": "npm run test_all && npm run test_ts_import_ets", - "test_all": "npm run testrunner -- -d test/main,test/rules,test/regression,test/extended_features,test/migration,test/ohmurl,test/interop,test/sdkwhite,test/concurrent,test/builtin,test/deprecatedapi,test/sdkcommonapi", + "test_all": "npm run testrunner -- -d test/main,test/rules,test/regression,test/extended_features,test/migration,test/ohmurl,test/interop,test/sdkwhite,test/concurrent,test/builtin,test/deprecatedapi, test/taskpool,test/sdkcommonapi", "test_main": "npm run testrunner -- -d test/main", "test_ohmurl": "npm run testrunner -- -d test/ohmurl", "test_interop": "npm run testrunner -- -d test/interop", "test_sdk": "npm run testrunner -- -d test/sdkwhite", "test_deprecatedapi": "npm run testrunner -- -d test/deprecatedapi", + "test_taskpool": "npm run testrunner -- -d test/taskpool", "test_sdkcommonapi": "npm run testrunner -- -d test/sdkcommonapi", "test_concurrent": "npm run testrunner -- -d test/concurrent", "test_rules": "npm run testrunner -- -d test/rules", @@ -38,7 +39,7 @@ "test_ts_import_ets": "npm run testrunner -- -d test/ts_import_ets/ts --sdk --interop-mode", "test_migration": "npm run testrunner -- -d test/migration", "testrunner": "npm run compile && node build/testRunner/TestRunner.js", - "update-tests": "node scripts/update-test-results.mjs test/main test/rules test/regression test/extended_features test/ts_import_ets/ts test/migration test/ohmurl test/interop test/sdkwhite test/concurrent test/builtin test/deprecatedapi test/sdkcommonapi", + "update-tests": "node scripts/update-test-results.mjs test/main test/rules test/regression test/extended_features test/ts_import_ets/ts test/migration test/ohmurl test/interop test/sdkwhite test/concurrent test/builtin test/deprecatedapi test/sdkcommonapi test/taskpool", "eslint-check": "npx eslint .", "eslint-fix": "npm run eslint-check -- --fix", "prettier-fix": "npx prettier --write .", diff --git a/ets2panda/linter/rule-config.json b/ets2panda/linter/rule-config.json index 2b93ff486977b125a56065753460e70bfed70b75..dc1ab4b18ff833330e09c4c6d8617fdeb143d3b5 100644 --- a/ets2panda/linter/rule-config.json +++ b/ets2panda/linter/rule-config.json @@ -65,6 +65,7 @@ "arkts-no-sparse-array", "arkts-no-enum-prop-as-type", "arkts-no-ts-like-smart-type", + "arkts-distinct-unsigned-right-shift-negative-number", "arkts-array-type-immutable", "arkts-primitive-type-normalization", "arkts-no-ts-like-catch-type", diff --git a/ets2panda/linter/src/lib/CookBookMsg.ts b/ets2panda/linter/src/lib/CookBookMsg.ts index 5a1f71ca6e5a8295412c4ed66c0778beb18e811a..4d5245cdc2f123c5db1c9c52c19bff2eaee7e1a9 100644 --- a/ets2panda/linter/src/lib/CookBookMsg.ts +++ b/ets2panda/linter/src/lib/CookBookMsg.ts @@ -302,6 +302,8 @@ cookBookTag[271] = 'After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)'; cookBookTag[272] = 'This API of process is obsolete in ArkTS 1.1. It\'s no longer supported in ArkTS 1.2 (arkts-concurrent-deprecated-apis)'; +cookBookTag[273] = + 'Unsigned right shift on negative number yields different results in ArkTS versions. (arkts-distinct-unsigned-right-shift-negative-number)'; cookBookTag[274] = 'The subclass constructor must call the parent class\'s parametered constructor (arkts-subclass-must-call-super-constructor-with-args)'; cookBookTag[275] = @@ -316,8 +318,7 @@ cookBookTag[284] = '"prop" function is not supported (arkui-no-prop-function)'; cookBookTag[285] = '"setAndProp" function is not supported (arkui-no-setandprop-function)'; 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[290] = - 'Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)'; +cookBookTag[290] = 'Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)'; 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-require-fullpath-name)'; cookBookTag[302] = diff --git a/ets2panda/linter/src/lib/FaultAttrs.ts b/ets2panda/linter/src/lib/FaultAttrs.ts index f5e7fd5c146f7ff4a61106cbaba134cd2711bcd0..d52e47f4756d9fdfe24a71db39b9d9170a58f06e 100644 --- a/ets2panda/linter/src/lib/FaultAttrs.ts +++ b/ets2panda/linter/src/lib/FaultAttrs.ts @@ -206,6 +206,7 @@ faultsAttrs[FaultID.InteropJsObjectExpandStaticInstance] = new FaultAttributes(2 faultsAttrs[FaultID.InteropJSFunctionInvoke] = new FaultAttributes(270); faultsAttrs[FaultID.VariableMissingInitializer] = new FaultAttributes(271); faultsAttrs[FaultID.DeprecatedProcessApi] = new FaultAttributes(272); +faultsAttrs[FaultID.NumericUnsignedShiftBehaviorChange] = new FaultAttributes(273); faultsAttrs[FaultID.MissingSuperCall] = new FaultAttributes(274); faultsAttrs[FaultID.CustomLayoutNeedAddDecorator] = new FaultAttributes(275); faultsAttrs[FaultID.InterfaceFieldNotImplemented] = new FaultAttributes(276); diff --git a/ets2panda/linter/src/lib/FaultDesc.ts b/ets2panda/linter/src/lib/FaultDesc.ts index 2de5c97f1fd54b493f83c4da75745245c4df4872..d2753c7fb5bb2837f6f6bcdb24b593be1c7bb459 100644 --- a/ets2panda/linter/src/lib/FaultDesc.ts +++ b/ets2panda/linter/src/lib/FaultDesc.ts @@ -174,8 +174,7 @@ faultDesc[FaultID.InteropJsObjectConditionJudgment] = 'Interop JS Object usage i faultDesc[FaultID.InteropJsObjectExpandStaticInstance] = 'Interop JS function usage'; faultDesc[FaultID.InteropJSFunctionInvoke] = 'Interop JS function invoke'; faultDesc[FaultID.VariableMissingInitializer] = 'Value must be assigned to variable'; -faultDesc[FaultID.NotSupportTupleGenericValidation] = - 'Tuple type cannot be used in generic type parameters of Promise static methods'; +faultDesc[FaultID.NotSupportTupleGenericValidation] = 'No Tuple type in Generic'; faultDesc[FaultID.DeprecatedProcessApi] = 'This process Api no longer supported in ArkTS 1.2'; faultDesc[FaultID.ExplicitFunctionType] = 'Not explicit function type'; faultDesc[FaultID.ClassstaticInitialization] = 'The static properties of a class need to have initial values'; @@ -266,6 +265,7 @@ faultDesc[FaultID.UnsupportOperator] = 'Unsupport operator'; faultDesc[FaultID.CustomLayoutNeedAddDecorator] = 'Custom layout need add decorator'; faultDesc[FaultID.InterfaceFieldNotImplemented] = 'All fields must be implemented'; faultDesc[FaultID.NoLocalClass] = 'No local classes'; +faultDesc[FaultID.NumericUnsignedShiftBehaviorChange] = 'No right shift on negative numbers'; faultDesc[FaultID.PropDecoratorNotSupported] = '"@Prop" decorator is not supported'; faultDesc[FaultID.StoragePropDecoratorNotSupported] = '"@StorageProp" decorator is not supported'; faultDesc[FaultID.LocalStoragePropDecoratorNotSupported] = '"@LocalStorageProp" decorator is not supported'; diff --git a/ets2panda/linter/src/lib/Problems.ts b/ets2panda/linter/src/lib/Problems.ts index f5767b4cb2b111c7a6348cc3f51fcb47bcd302e7..d607d731b137835c97f5cc8fd29fe9796cd46104 100644 --- a/ets2panda/linter/src/lib/Problems.ts +++ b/ets2panda/linter/src/lib/Problems.ts @@ -264,6 +264,7 @@ export enum FaultID { CustomLayoutNeedAddDecorator, InterfaceFieldNotImplemented, NoLocalClass, + NumericUnsignedShiftBehaviorChange, PropDecoratorNotSupported, StoragePropDecoratorNotSupported, LocalStoragePropDecoratorNotSupported, diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 96b6d40538c1acfb1fb3f4a4c2fadfb8d79b54c5..2658cb6a0d25c67bc325d128ec695ae4c4794efe 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -19,7 +19,13 @@ import { FaultID } from './Problems'; import { TypeScriptLinterConfig } from './TypeScriptLinterConfig'; import type { Autofix } from './autofixes/Autofixer'; import { Autofixer } from './autofixes/Autofixer'; -import { PROMISE_METHODS, PROMISE_METHODS_WITH_NO_TUPLE_SUPPORT, SYMBOL, SYMBOL_CONSTRUCTOR, TsUtils } from './utils/TsUtils'; +import { + PROMISE_METHODS, + PROMISE_METHODS_WITH_NO_TUPLE_SUPPORT, + SYMBOL, + SYMBOL_CONSTRUCTOR, + TsUtils +} from './utils/TsUtils'; import { FUNCTION_HAS_NO_RETURN_ERROR_CODE } from './utils/consts/FunctionHasNoReturnErrorCode'; import { LIMITED_STANDARD_UTILITY_TYPES, @@ -2448,6 +2454,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } break; default: + this.handleUnsignedShiftOnNegative(tsBinaryExpr); } this.checkInterOpImportJsDataCompare(tsBinaryExpr); this.checkInteropEqualityJudgment(tsBinaryExpr); @@ -3991,7 +3998,6 @@ 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; @@ -4006,6 +4012,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (allBaseTypes && allBaseTypes.length > 0) { this.checkMethodType(allBaseTypes, methodName, node, isStatic); } + this.checkIncompatibleFunctionTypes(node); } private checkMethodType( @@ -4047,7 +4054,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } private isSameDeclarationType(decl: ts.Node, type: ts.Type, isStatic: boolean): boolean { - if (isStatic && ts.isClassDeclaration(decl)) { + if (isStatic && ts.isClassDeclaration(decl) || ts.isInterfaceDeclaration(decl)) { const staticType = this.tsTypeChecker.getTypeAtLocation(decl); return this.isSameType(staticType, type); } @@ -4070,6 +4077,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (declaredReturnTypeStr === actualReturnTypeStr) { return; } + if (this.tsUtils.skipCheckForArrayBufferLike(declaredReturnTypeStr, actualReturnTypeStr)) { + return; + } if (actualReturnType.flags & ts.TypeFlags.Any || declaredReturnType.flags & ts.TypeFlags.Any) { return; } @@ -4262,7 +4272,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (!this.isTypeSameOrWider(baseParamType, derivedParamType)) { this.incrementCounters(derivedParams[i], FaultID.MethodInheritRule); - } + } } } @@ -4372,7 +4382,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return true; } - if (derivedType.flags & ts.TypeFlags.Any) { + if (derivedType.flags & ts.TypeFlags.Any || baseType.flags & ts.TypeFlags.Never) { return true; } @@ -4391,6 +4401,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return true; } + if (this.checkTypeInheritance(derivedType, baseType, false)) { + return true; + } + const baseTypeSet = new Set(this.flattenUnionTypes(baseType)); const derivedTypeSet = new Set(this.flattenUnionTypes(derivedType)); @@ -4424,6 +4438,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } + if(this.checkTypeInheritance(fromType, toType)) { + return true; + } + const fromTypes = this.flattenUnionTypes(fromType); const toTypes = new Set(this.flattenUnionTypes(toType)); @@ -4435,6 +4453,52 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { }); } + private checkTypeInheritance( + sourceType: ts.Type, + targetType: ts.Type, + isSouceTotaqrget: boolean = true + ): boolean { + // Early return if either type lacks symbol information + if (!sourceType.symbol || !targetType.symbol) { + return false; + } + + // Determine which type's inheritance chain to examine based on check direction + const typeToGetChain = isSouceTotaqrget ? sourceType : targetType; + const typeToCheck = isSouceTotaqrget ? targetType : sourceType; + + // Get inheritance chain and check for relationship + const inheritanceChain = this.getTypeInheritanceChain(typeToGetChain); + return inheritanceChain.some(t => { + return t.symbol === typeToCheck.symbol; + }); + } + + private getTypeInheritanceChain(type: ts.Type): ts.Type[] { + const chain: ts.Type[] = [type]; + const declarations = type.symbol?.getDeclarations() || []; + + for (const declaration of declarations) { + if ((!ts.isClassDeclaration(declaration) && !ts.isInterfaceDeclaration(declaration)) || + !declaration.heritageClauses) { + continue; + } + + const heritageClauses = declaration.heritageClauses.filter(clause => { + return clause.token === ts.SyntaxKind.ExtendsKeyword || clause.token === ts.SyntaxKind.ImplementsKeyword; + }); + + for (const clause of heritageClauses) { + for (const typeExpr of clause.types) { + const baseType = this.tsTypeChecker.getTypeAtLocation(typeExpr.expression); + chain.push(baseType, ...this.getTypeInheritanceChain(baseType)); + } + } + } + + return chain; + } + // Check if a type string has an equivalent primitive/wrapper type in a set private static areWrapperAndPrimitiveTypesEqual(typeStr: string, typeSet: Set): boolean { const typePairs = [ @@ -5428,6 +5492,37 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { this.handleNoDeprecatedApi(tsCallExpr); this.handleFunctionReturnThisCall(tsCallExpr); this.handlePromiseTupleGeneric(tsCallExpr); + this.handleTupleGeneric(tsCallExpr); + } + + private handleTupleGeneric(callExpr: ts.CallExpression): void { + if (!this.options.arkts2) { + return; + } + if (!ts.isPropertyAccessExpression(callExpr.expression)) { + return; + } + const accessedProperty = callExpr.expression; + + if (!ts.isIdentifier(accessedProperty.expression)) { + return; + } + + if (accessedProperty.expression.text !== TASKPOOL) { + return; + } + + if (!callExpr.typeArguments) { + return; + } + + if (callExpr.parent) { + callExpr.typeArguments.forEach((node) => { + if (ts.isTupleTypeNode(node)) { + this.incrementCounters(node, FaultID.NotSupportTupleGenericValidation); + } + }); + } } private handleCallExpressionForUI(node: ts.CallExpression): void { @@ -14301,4 +14396,39 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } return res; } + + private handleUnsignedShiftOnNegative(node: ts.BinaryExpression): void { + if (!this.options.arkts2) { + return; + } + + if (!TypeScriptLinter.isUnsignedShiftByZero(node)) { + return; + } + + if (TsUtils.isNegativeNumericLiteral(node.left)) { + this.incrementCounters(node, FaultID.NumericUnsignedShiftBehaviorChange); + } + + if (ts.isIdentifier(node.left)) { + const symbol = this.tsTypeChecker.getSymbolAtLocation(node.left); + const decl = symbol?.valueDeclaration; + if (!decl || !ts.isVariableDeclaration(decl)) { + return; + } + + const init = decl.initializer; + if (init && TsUtils.isNegativeNumericLiteral(init)) { + this.incrementCounters(node, FaultID.NumericUnsignedShiftBehaviorChange); + } + } + } + + private static isUnsignedShiftByZero(node: ts.BinaryExpression): boolean { + return ( + node.operatorToken.kind === ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken && + ts.isNumericLiteral(node.right) && + node.right.text === '0' + ); + } } diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 3789d7c2b9dd840664e9fbbf120de99affd56036..3ef2aba012eaa6e092826910b187dc0c631ba5fe 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -4971,6 +4971,7 @@ export class Autofixer { } return `<${typeArg. map((arg) => { + ts.setEmitFlags(arg, ts.EmitFlags.SingleLine); return this.nonCommentPrinter.printNode(ts.EmitHint.Unspecified, arg, sourceFile); }). join(', ')}>`; @@ -4978,7 +4979,7 @@ export class Autofixer { if (!typeArg || !this.isTypeArgumentAccessible(sourceFile, typeArg as ts.TypeNode)) { return undefined; } - + ts.setEmitFlags(typeArg as ts.TypeNode, ts.EmitFlags.SingleLine); return `<${this.nonCommentPrinter.printNode(ts.EmitHint.Unspecified, typeArg as ts.TypeNode, sourceFile)}>`; } diff --git a/ets2panda/linter/src/lib/utils/TsUtils.ts b/ets2panda/linter/src/lib/utils/TsUtils.ts index 6eafedeaf4deb15c6f33e0a35e074e5ceb926daf..fbc408c87e9af7c1444b9687e3de92829d240512 100644 --- a/ets2panda/linter/src/lib/utils/TsUtils.ts +++ b/ets2panda/linter/src/lib/utils/TsUtils.ts @@ -804,6 +804,9 @@ export class TsUtils { if (this.skipStructuralTypingCheckForFunctionals(lhsType, rhsType)) { return false; } + if (this.skipCheckForArrayBufferLike(lhsType, rhsType)) { + return false; + } if (rhsType.isUnion() || lhsType.isUnion()) { return this.needToDeduceStructuralIdentityHandleUnions(lhsType, rhsType, rhsExpr, isStrict); } @@ -900,6 +903,16 @@ export class TsUtils { return isStrictLhs && this.typeContainsNonSendableClassOrInterface(rhsType); } + skipCheckForArrayBufferLike(lhsType: string | ts.Type, rhsType: string | ts.Type): boolean { + const lhsIsArrayBufferLike = TsUtils.isArrayBufferType( + typeof lhsType === 'string' ? lhsType : this.tsTypeChecker.typeToString(lhsType) + ); + const rhsIsArrayBufferLike = TsUtils.isArrayBufferType( + typeof rhsType === 'string' ? rhsType : this.tsTypeChecker.typeToString(rhsType) + ); + return !!this.options.arkts2 && lhsIsArrayBufferLike && rhsIsArrayBufferLike; + } + private processExtendedParentTypes(typeA: ts.Type, typeB: ts.Type): boolean { /* @@ -2114,6 +2127,11 @@ export class TsUtils { return callSigns && callSigns.length > 0; } + static isArrayBufferType(typeStr: string): boolean { + const arrayBufferLikeArr = ['ArrayBuffer', 'ArrayBufferLike']; + return arrayBufferLikeArr.includes(typeStr); + } + static getFunctionalTypeSignature(type: ts.Type): ts.Signature | undefined { const callSigns = type.getCallSignatures(); if (callSigns.length > 0) { @@ -3879,6 +3897,14 @@ export class TsUtils { } } + static isNegativeNumericLiteral(expr: ts.Expression): boolean { + return ( + ts.isPrefixUnaryExpression(expr) && + expr.operator === ts.SyntaxKind.MinusToken && + ts.isNumericLiteral(expr.operand) + ); + } + isNumberArrayType(type: ts.Type): boolean { if (!type.symbol || !this.isGenericArrayType(type)) { return false; diff --git a/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json b/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json index 52c316a71650b0b49b2377f3c44136b01a1bbfae..e61aa4ff7a944b75ca9e52a984286f90f80315d4 100644 --- a/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json +++ b/ets2panda/linter/test/main/arkts-not-support-tuple-generic-validation.ets.arkts2.json @@ -41,7 +41,7 @@ "endColumn": 47, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" }, { @@ -51,7 +51,7 @@ "endColumn": 47, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" }, { @@ -61,7 +61,7 @@ "endColumn": 48, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" }, { @@ -71,7 +71,7 @@ "endColumn": 54, "problem": "NotSupportTupleGenericValidation", "suggest": "", - "rule": "Tuple type cannot be used in generic type parameters of Promise static methods (arkts-not-support-tuple-generic-validation)", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", "severity": "ERROR" } ] diff --git a/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets new file mode 100644 index 0000000000000000000000000000000000000000..2841e80f912c2d11041c2782305d6c250c523433 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let a = -123; +let b = 456; +let c = -789; + +let r1 = -123 >>> 0; // error +let r2 = a >>> 0; // error +let r3 = b >>> 0; // valid +let r4 = c >>> 0; // error + +let d = -1; +let r5 = d >>> 0; // error diff --git a/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.args.json b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..d8d3390ad9befeca9b595017d9eea0f5ada3d049 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.arkts2.json b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..3862e0bc0928be6ce993ce814a8bd801d7483b78 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.arkts2.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 20, + "column": 10, + "endLine": 20, + "endColumn": 20, + "problem": "NumericUnsignedShiftBehaviorChange", + "suggest": "", + "rule": "Unsigned right shift on negative number yields different results in ArkTS versions. (arkts-distinct-unsigned-right-shift-negative-number)", + "severity": "ERROR" + }, + { + "line": 21, + "column": 10, + "endLine": 21, + "endColumn": 17, + "problem": "NumericUnsignedShiftBehaviorChange", + "suggest": "", + "rule": "Unsigned right shift on negative number yields different results in ArkTS versions. (arkts-distinct-unsigned-right-shift-negative-number)", + "severity": "ERROR" + }, + { + "line": 23, + "column": 10, + "endLine": 23, + "endColumn": 17, + "problem": "NumericUnsignedShiftBehaviorChange", + "suggest": "", + "rule": "Unsigned right shift on negative number yields different results in ArkTS versions. (arkts-distinct-unsigned-right-shift-negative-number)", + "severity": "ERROR" + }, + { + "line": 26, + "column": 10, + "endLine": 26, + "endColumn": 17, + "problem": "NumericUnsignedShiftBehaviorChange", + "suggest": "", + "rule": "Unsigned right shift on negative number yields different results in ArkTS versions. (arkts-distinct-unsigned-right-shift-negative-number)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.json b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..895325b061c0fe9fa6b75bab6ed4259b5343c199 --- /dev/null +++ b/ets2panda/linter/test/main/arkts-unsigned-shift-on-negative.ets.json @@ -0,0 +1,18 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + ] +} \ No newline at end of file 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 80246fcd426b8a420c8426d571e3fae61894a087..43830e5da0bb5ebcc71a2d22a9aa1c7dbb308730 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets @@ -118,3 +118,7 @@ class SubWeakMap extends WeakMap{} let subWeakMap = new SubWeakMap(); class SubWeakSet extends WeakSet{} let subWeakSet = new SubWeakSet(); + +class C {} +class D {} +let a: D<[C]> = new D(); \ No newline at end of file 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 582bf2a4559d9df51f2db036dac4549bf261cb5a..788aaf8aaa07a8e20c9a9642e9ba0d7d01b0b6f0 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 @@ -524,6 +524,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 124, + "column": 17, + "endLine": 124, + "endColumn": 24, + "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 4b652fc080dde5a44cf28f5d391ed1e0893f25f6..6d8c8403ac0826036252dd6b0bec721f33a4fc57 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 @@ -766,6 +766,27 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 124, + "column": 17, + "endLine": 124, + "endColumn": 24, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3313, + "end": 3313, + "replacementText": "<[C]>", + "line": 124, + "column": 17, + "endLine": 124, + "endColumn": 24 + } + ], + "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 541aea73517adac61290685f05651901547e439c..3cfe89eaab8d03105a0c493fbe8b206f07520dff 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 @@ -125,3 +125,7 @@ class SubWeakMap extends WeakMap{} let subWeakMap = new SubWeakMap(); class SubWeakSet extends WeakSet{} let subWeakSet = new SubWeakSet(); + +class C {} +class D {} +let a: D<[C]> = new D<[C]>(); \ No newline at end of file diff --git a/ets2panda/linter/test/main/incompatible_function.ets b/ets2panda/linter/test/main/incompatible_function.ets index db3f4250b777e4141bd55293a133e44c7096f477..4330949c719a3717839e8f7a3f98bb4b417793b5 100644 --- a/ets2panda/linter/test/main/incompatible_function.ets +++ b/ets2panda/linter/test/main/incompatible_function.ets @@ -112,4 +112,26 @@ for (let i = 0; i < totalPromises; i++) { }, delay) ) ); +} + +class D { + fun(a: ArrayBufferLike): ArrayBuffer { + return a; + } +} + +class X { + n: number = 0 + s: string = '' +} + +class Y { + n: number = 0 + s: string = '' +} + +class E { + Dfun(a: X|Y): X { + return a; + } } \ No newline at end of file diff --git a/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json b/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json index 1a8bca46e8f7a8fb9a05e0a3c15bad19f819c366..31c19f7df35cda1cf1b42ca41cbba563768f8813 100644 --- a/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json +++ b/ets2panda/linter/test/main/incompatible_function.ets.arkts2.json @@ -84,16 +84,6 @@ "rule": "Stricter assignments into variables of function type (arkts-incompatible-function-types)", "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, @@ -123,6 +113,16 @@ "suggest": "", "rule": "Stricter assignments into variables of function type (arkts-incompatible-function-types)", "severity": "ERROR" + }, + { + "line": 135, + "column": 12, + "endLine": 135, + "endColumn": 13, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/indexable_type_string_element_access.ets.arkts2.json b/ets2panda/linter/test/main/indexable_type_string_element_access.ets.arkts2.json index 3ee4a5b916b47d5787d5176671a81ee4d5978def..ff51cef36a773f1b7d5fda1d53fa74e4fba2226a 100644 --- a/ets2panda/linter/test/main/indexable_type_string_element_access.ets.arkts2.json +++ b/ets2panda/linter/test/main/indexable_type_string_element_access.ets.arkts2.json @@ -1,17 +1,17 @@ { - "copyright": [ - "Copyright (c) 2023-2024 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "result": [] + "copyright": [ + "Copyright (c) 2023-2024 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance2.ets b/ets2panda/linter/test/main/method_inheritance2.ets index e4f9112258fabd281f9d907f4e5e68c16eaf32d2..1f8bd037830fa698d02226b8e241f6e39785e2ff 100755 --- a/ets2panda/linter/test/main/method_inheritance2.ets +++ b/ets2panda/linter/test/main/method_inheritance2.ets @@ -63,14 +63,14 @@ interface BaseI2 { // T implements class DerivedI2 implements BaseI2 { - foo(obj: A): void { - console.log("Drived"); // (arkts-method-inherit-rule) error + foo(obj: A): void { // (arkts-method-inherit-rule) error + console.log("Derived"); } - foo2(): void { - console.log("Drived"); // (arkts-method-inherit-rule) error + foo2(): void { // (arkts-method-inherit-rule) error + console.log("Derived"); } - foo3(obj: A | B): void { - console.log("Drived"); // (arkts-method-inherit-rule) error + foo3(obj: A | B): void { // (arkts-method-inherit-rule) error + console.log("Derived"); } } @@ -121,6 +121,233 @@ interface I{ } class J implements I{ - pp(key: string,value?:string):void { // 漏报arkts-method-inherit-rule + pp(key: string,value?:string):void { // arkts-method-inherit-rule } -} \ No newline at end of file +} + +interface BaseI { + foo(): A|B ; + foo2(): void; + foo3(): A; +} + +class Derived2 implements BaseI { + foo(): A|B|C{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + foo2(): A{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + foo3(): A|B { // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } +} + +let b2:BaseI = new Derived2(); +b2.foo(); +b2.foo2() +b2.foo3() + + +class Base32 { + foo(): A|B { + console.log("base") + return new A(); + } + foo2():void{ + console.log("base") + // return new A(); + } + foo3(): A { + console.log("base") + return new A(); + } + foo4(){ + console.log("base") + // return new A(); + } +} + +class Derived32 extends Base32 { + foo(): A|B|C{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + foo2(): A{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + foo3(): A|B { // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + foo4(): A{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } +} + +interface BaseI4 { + foo(): A|B ; + foo2(): void; + foo3(): A; +} + +class Derived4 implements BaseI4 { + foo(): A|B|C{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + foo2(): A{ // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } + + foo3(): A|B { // (arkts-method-inherit-rule) + console.log("Derived:") + return new A(); + } +} + +class Animal {} +class Dog extends Animal {} +class Base55 { + public foo(obj: Animal): void { + console.log("base") + } +} + +class Derived55 extends Base55 { + public foo(obj: Dog): void { // (arkts-method-inherit-rule) + console.log("Derived:") + } +} + +class Base6 { + public foo(): Dog { + console.log("base") + return new Dog(); + } +} + +class Derived6 extends Base6 { + public foo(): Animal { // (arkts-method-inherit-rule) + console.log("Derived:") + return new Animal() + } +} + +abstract class Base66{ + abstract foo(); + abstract foo1(); +} + +abstract class Derived66 extends Base66{ + async foo(){ // (arkts-method-inherit-rule) + + } + foo1(): number { // (arkts-method-inherit-rule)? + return 1 + } +} +class Base7{ + foo(){ + + } +} +class Derived7 extends Base7{ + foo(): number { // (arkts-method-inherit-rule) + return 12; + } +} +class Base44 { + public foo(obj: A | B): void { + console.log("base") + } + protected foo2(obj: A | B): void { + console.log("base") + } + async foo3(obj: A | B | C): Promise { + console.log("base") + } +} + +class Derived44 extends Base44 { + public foo(obj: A): void { // (arkts-method-inherit-rule) + console.log("Derived:" + obj.a) + } + protected foo2(): void { // (arkts-method-inherit-rule) + console.log("Derived:") + } + async foo3(obj: A | B): Promise { // (arkts-method-inherit-rule) + console.log("Derived:") + } +} +class Base { + foo(obj: A | B): void { + console.log("base") + } + foo2(obj: A | B): void { + console.log("base") + } + foo3(obj: A | B | C): void { + console.log("base") + } + foo4(obj: A): void { + console.log("base" ); + } +} +class Derived extends Base { + foo(obj: A): void { // (arkts-method-inherit-rule) + console.log("Derived:" + obj.a) + } + foo2(): void { // (arkts-method-inherit-rule) + console.log("Derived:") + } + foo3(obj: A | B): void { // (arkts-method-inherit-rule) + console.log("Derived:") + } + foo4(obj: D): void { // (arkts-method-inherit-rule) + console.log("Derived:" + obj.b) + } +} +class Derived_Derived extends Derived { + foo(): void { // (arkts-method-inherit-rule) + } + + foo3(obj: A): void { // (arkts-method-inherit-rule) + console.log("Derived:") + } +} + +let b:Base = new Derived(); +b.foo(new B()); +b.foo2(new B()) + +interface BaseI22 { + foo(obj: A | B):void; + foo2(obj: A ): void; + foo3(obj: A | B | C): void; +} + +class Derived22 implements BaseI22 { + foo(obj: A): void { // (arkts-method-inherit-rule) + console.log("Derived"); + } + foo2(): void { // (arkts-method-inherit-rule) + console.log("Derived"); + } + foo3(obj: A | B): void { // (arkts-method-inherit-rule) + console.log("Derived"); + } +} +let b22 :BaseI = new Derived2(); \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json b/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json index 54e9fda0ff04a60972f8a4f796a0ad6c7d269f3f..4e6f89111af0dc233834d35bbdbb22355714ab36 100755 --- a/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json +++ b/ets2panda/linter/test/main/method_inheritance2.ets.arkts2.json @@ -1,18 +1,4 @@ { - "copyright": [ - "Copyright (c) 2025 Huawei Device Co., Ltd.", - "Licensed under the Apache License, Version 2.0 (the 'License');", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - "", - "http://www.apache.org/licenses/LICENSE-2.0", - "", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an 'AS IS' BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], "result": [ { "line": 46, @@ -44,6 +30,36 @@ "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" }, + { + "line": 66, + "column": 10, + "endLine": 66, + "endColumn": 16, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 69, + "column": 3, + "endLine": 69, + "endColumn": 7, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 72, + "column": 11, + "endLine": 72, + "endColumn": 21, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, { "line": 98, "column": 17, @@ -93,6 +109,266 @@ "suggest": "", "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", "severity": "ERROR" + }, + { + "line": 135, + "column": 10, + "endLine": 135, + "endColumn": 15, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 140, + "column": 11, + "endLine": 140, + "endColumn": 12, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 145, + "column": 11, + "endLine": 145, + "endColumn": 14, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 177, + "column": 13, + "endLine": 177, + "endColumn": 18, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 182, + "column": 14, + "endLine": 182, + "endColumn": 15, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 187, + "column": 14, + "endLine": 187, + "endColumn": 17, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 192, + "column": 14, + "endLine": 192, + "endColumn": 15, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 205, + "column": 13, + "endLine": 205, + "endColumn": 18, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 210, + "column": 14, + "endLine": 210, + "endColumn": 15, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 215, + "column": 14, + "endLine": 215, + "endColumn": 17, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 230, + "column": 14, + "endLine": 230, + "endColumn": 22, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 243, + "column": 17, + "endLine": 243, + "endColumn": 23, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 255, + "column": 9, + "endLine": 255, + "endColumn": 12, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 268, + "column": 10, + "endLine": 268, + "endColumn": 16, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 285, + "column": 14, + "endLine": 285, + "endColumn": 20, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 288, + "column": 13, + "endLine": 288, + "endColumn": 17, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 291, + "column": 14, + "endLine": 291, + "endColumn": 24, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 310, + "column": 7, + "endLine": 310, + "endColumn": 13, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 313, + "column": 3, + "endLine": 313, + "endColumn": 7, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 316, + "column": 8, + "endLine": 316, + "endColumn": 18, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 319, + "column": 8, + "endLine": 319, + "endColumn": 14, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 324, + "column": 3, + "endLine": 324, + "endColumn": 6, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 327, + "column": 8, + "endLine": 327, + "endColumn": 14, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 343, + "column": 7, + "endLine": 343, + "endColumn": 13, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 346, + "column": 3, + "endLine": 346, + "endColumn": 7, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" + }, + { + "line": 349, + "column": 8, + "endLine": 349, + "endColumn": 18, + "problem": "MethodInheritRule", + "suggest": "", + "rule": "Overridden method parameters and return types must respect type inheritance principles (arkts-method-inherit-rule)", + "severity": "ERROR" } ] } \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance3.ets b/ets2panda/linter/test/main/method_inheritance3.ets index d31da9911bdba10fc816d7677500f8a4feae3ff1..d4b5b6b18efa1af9de3c9df43ee80ec2c259ff15 100755 --- a/ets2panda/linter/test/main/method_inheritance3.ets +++ b/ets2panda/linter/test/main/method_inheritance3.ets @@ -60,4 +60,84 @@ class EntryAbility extends UIAbility { } catch (e) { } } +} + +class TestA { + a: number = 0 +} + +class TestD extends TestA{ + a: number = 0; + b: number = 1; +} + +class TestE implements TestI{ + +} + +class TestF extends TestE{ + +} +interface TestI{ + +} + +interface TestI2 extends TestI{ + +} +class TestBase { + foo3(obj: TestD): void { + console.log("Derived:" + obj.b) + } + + foo4(obj: TestD): TestA { + console.log("base" ); + return new TestA() + } + + foo5():TestI{ + return {} + } + + foo12(obj:never){ + + } +} + +class TestDerived extends TestBase { + override foo3(obj: TestA): void { // no error + console.log("base" ); + } + + override foo4(obj: TestA): TestD { // no error + return new TestD(); + } + + override foo5(): TestI2 { // no error + return {} + } + + override foo12(obj:TestA){ // no error + + } +} + +class CC1 {} +class CC2 extends CC1 { + public static toString(result: number): string { // no error + return ''; + } +} + +class AA{ + getData(a:T):T{ + + return a; + } +} + +class BB extends AA{ + getData(a: number): number { // no error + return 123; + } } \ No newline at end of file diff --git a/ets2panda/linter/test/main/method_inheritance3.ets.arkts2.json b/ets2panda/linter/test/main/method_inheritance3.ets.arkts2.json index c163f337bfc31ba134bb01819736eac0a2b969a9..6fd8017e327821c67a10278cb6bbd9721ae86f29 100755 --- a/ets2panda/linter/test/main/method_inheritance3.ets.arkts2.json +++ b/ets2panda/linter/test/main/method_inheritance3.ets.arkts2.json @@ -34,6 +34,16 @@ "rule": "\"void\" operator is not supported (arkts-no-void-operator)", "severity": "ERROR" }, + { + "line": 127, + "column": 3, + "endLine": 129, + "endColumn": 4, + "problem": "NoSignatureDistinctWithObjectPublicApi", + "suggest": "", + "rule": "The signature of a method in a class/interface cannot be different from the public interface in an object. (arkts-class-no-signature-distinct-with-object-public-api)", + "severity": "ERROR" + }, { "line": 44, "column": 18, diff --git a/ets2panda/linter/test/taskpool/taskpool_execute.ets b/ets2panda/linter/test/taskpool/taskpool_execute.ets new file mode 100644 index 0000000000000000000000000000000000000000..f50a174b039814a7cd4ee8976a68b3c6c86e65aa --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function printArgs(args: number): number { + console.info(""printArgs: "" + args); + return args; +} + +taskpool.execute<[number], number>(printArgs, 100).then((value: number) => { + console.info(""taskpool result: "" + value); +}); + diff --git a/ets2panda/linter/test/taskpool/taskpool_execute.ets.args.json b/ets2panda/linter/test/taskpool/taskpool_execute.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..bc4d2071daf6e9354e711c3b74b6be2b56659066 --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.ets.args.json @@ -0,0 +1,19 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "" + } +} diff --git a/ets2panda/linter/test/taskpool/taskpool_execute.ets.arkts2.json b/ets2panda/linter/test/taskpool/taskpool_execute.ets.arkts2.json new file mode 100644 index 0000000000000000000000000000000000000000..2b96bc02fd880a506bdbccfeb52c134c4d985986 --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.ets.arkts2.json @@ -0,0 +1,28 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [ + { + "line": 21, + "column": 18, + "endLine": 21, + "endColumn": 26, + "problem": "NotSupportTupleGenericValidation", + "suggest": "", + "rule": "Tuple type cannot be used in generic type parameters (arkts-not-support-tuple-generic-validation)", + "severity": "ERROR" + } + ] +} \ No newline at end of file diff --git a/ets2panda/linter/test/taskpool/taskpool_execute.ets.json b/ets2panda/linter/test/taskpool/taskpool_execute.ets.json new file mode 100644 index 0000000000000000000000000000000000000000..9f305c86d7ff705098b1e480818e125d5e6e3a4a --- /dev/null +++ b/ets2panda/linter/test/taskpool/taskpool_execute.ets.json @@ -0,0 +1,17 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "result": [] +}