fix overload

Issue: https://gitee.com/openharmony/third_party_typescript/issues/IATX2I
Signed-off-by: azwenqiang <dengwenqiang5@huawei.com>
Change-Id: I4e560a76eb7827bb988589ef1998412d497b5577
This commit is contained in:
azwenqiang 2024-09-26 17:21:46 +08:00
parent da9425d36a
commit 9e752fa9eb
10 changed files with 202 additions and 22 deletions

View File

@ -194706,6 +194706,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
var _a;
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
@ -194725,7 +194726,22 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
if (!((_a = chain.next) === null || _a === void 0 ? void 0 : _a.length)) {
return ErrorType.NO_ERROR;
}
// 'No_overrload...' error need to check each sub-error message, others only check the first one
if (chain.code !== LibraryTypeCallDiagnosticCheckerNamespace.NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE) {
return LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
}
var result = ErrorType.NO_ERROR;
for (var _i = 0, _b = chain.next; _i < _b.length; _i++) {
var child = _b[_i];
result = LibraryTypeCallDiagnosticChecker.checkMessageChain(child, inLibCall);
if (result !== ErrorType.NO_ERROR) {
break;
}
}
return result;
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -198430,7 +198446,7 @@ var ts;
if (!checkInRange) {
return true;
}
if (val.start === undefined || checkInRange(val.start)) {
if (val.start === undefined || checkInRange(val.start, val.length)) {
return true;
}
if (TypeScriptLinter.unknowDiagnosticCache.has(val)) {
@ -199463,8 +199479,9 @@ var ts;
_a[ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
},
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos, length) {
// The 'No-overload...' error is in some cases mounted on the callExpression node rather than a argument node
return _this.checkInRange(rangesToFilter, pos) && !(length && callExpr.end === pos + length);
},
_a[TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);

View File

@ -194451,6 +194451,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
var _a;
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
@ -194470,7 +194471,22 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
if (!((_a = chain.next) === null || _a === void 0 ? void 0 : _a.length)) {
return ErrorType.NO_ERROR;
}
// 'No_overrload...' error need to check each sub-error message, others only check the first one
if (chain.code !== LibraryTypeCallDiagnosticCheckerNamespace.NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE) {
return LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
}
var result = ErrorType.NO_ERROR;
for (var _i = 0, _b = chain.next; _i < _b.length; _i++) {
var child = _b[_i];
result = LibraryTypeCallDiagnosticChecker.checkMessageChain(child, inLibCall);
if (result !== ErrorType.NO_ERROR) {
break;
}
}
return result;
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -198175,7 +198191,7 @@ var ts;
if (!checkInRange) {
return true;
}
if (val.start === undefined || checkInRange(val.start)) {
if (val.start === undefined || checkInRange(val.start, val.length)) {
return true;
}
if (TypeScriptLinter.unknowDiagnosticCache.has(val)) {
@ -199208,8 +199224,9 @@ var ts;
_a[ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
},
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos, length) {
// The 'No-overload...' error is in some cases mounted on the callExpression node rather than a argument node
return _this.checkInRange(rangesToFilter, pos) && !(length && callExpr.end === pos + length);
},
_a[TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);

View File

@ -183545,6 +183545,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
var _a;
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
@ -183564,7 +183565,22 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
if (!((_a = chain.next) === null || _a === void 0 ? void 0 : _a.length)) {
return ErrorType.NO_ERROR;
}
// 'No_overrload...' error need to check each sub-error message, others only check the first one
if (chain.code !== LibraryTypeCallDiagnosticCheckerNamespace.NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE) {
return LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
}
var result = ErrorType.NO_ERROR;
for (var _i = 0, _b = chain.next; _i < _b.length; _i++) {
var child = _b[_i];
result = LibraryTypeCallDiagnosticChecker.checkMessageChain(child, inLibCall);
if (result !== ErrorType.NO_ERROR) {
break;
}
}
return result;
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -187269,7 +187285,7 @@ var ts;
if (!checkInRange) {
return true;
}
if (val.start === undefined || checkInRange(val.start)) {
if (val.start === undefined || checkInRange(val.start, val.length)) {
return true;
}
if (TypeScriptLinter.unknowDiagnosticCache.has(val)) {
@ -188302,8 +188318,9 @@ var ts;
_a[ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
},
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos, length) {
// The 'No-overload...' error is in some cases mounted on the callExpression node rather than a argument node
return _this.checkInRange(rangesToFilter, pos) && !(length && callExpr.end === pos + length);
},
_a[TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);

View File

@ -183545,6 +183545,7 @@ var ts;
return true;
};
LibraryTypeCallDiagnosticChecker.checkMessageChain = function (chain, inLibCall) {
var _a;
if (chain.code === LibraryTypeCallDiagnosticCheckerNamespace.TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE) {
if (chain.messageText.match(LibraryTypeCallDiagnosticCheckerNamespace.TYPE_UNKNOWN_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE)) {
return ErrorType.UNKNOW;
@ -183564,7 +183565,22 @@ var ts;
return ErrorType.NULL;
}
}
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
if (!((_a = chain.next) === null || _a === void 0 ? void 0 : _a.length)) {
return ErrorType.NO_ERROR;
}
// 'No_overrload...' error need to check each sub-error message, others only check the first one
if (chain.code !== LibraryTypeCallDiagnosticCheckerNamespace.NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE) {
return LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
}
var result = ErrorType.NO_ERROR;
for (var _i = 0, _b = chain.next; _i < _b.length; _i++) {
var child = _b[_i];
result = LibraryTypeCallDiagnosticChecker.checkMessageChain(child, inLibCall);
if (result !== ErrorType.NO_ERROR) {
break;
}
}
return result;
};
;
LibraryTypeCallDiagnosticChecker.prototype.checkFilteredDiagnosticMessages = function (msgText) {
@ -187269,7 +187285,7 @@ var ts;
if (!checkInRange) {
return true;
}
if (val.start === undefined || checkInRange(val.start)) {
if (val.start === undefined || checkInRange(val.start, val.length)) {
return true;
}
if (TypeScriptLinter.unknowDiagnosticCache.has(val)) {
@ -188302,8 +188318,9 @@ var ts;
_a[ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
},
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);
_a[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE] = function (pos, length) {
// The 'No-overload...' error is in some cases mounted on the callExpression node rather than a argument node
return _this.checkInRange(rangesToFilter, pos) && !(length && callExpr.end === pos + length);
},
_a[TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE] = function (pos) {
return _this.checkInRange(rangesToFilter, pos);

View File

@ -87,7 +87,22 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker {
return ErrorType.NULL;
}
}
return chain.next === undefined ? ErrorType.NO_ERROR : LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
if (!chain.next?.length) {
return ErrorType.NO_ERROR;
}
// 'No_overrload...' error need to check each sub-error message, others only check the first one
if (chain.code !== NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE) {
return LibraryTypeCallDiagnosticChecker.checkMessageChain(chain.next[0], inLibCall);
}
let result = ErrorType.NO_ERROR;
for (const child of chain.next) {
result = LibraryTypeCallDiagnosticChecker.checkMessageChain(child, inLibCall);
if (result !== ErrorType.NO_ERROR) {
break;
}
}
return result;
};
checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string) {

View File

@ -914,7 +914,7 @@ export class TypeScriptLinter {
return true;
}
private filterStrictDiagnostics(filters: { [code: number]: (pos: number) => boolean },
private filterStrictDiagnostics(filters: { [code: number]: (pos: number, length?: number) => boolean },
diagnosticChecker: DiagnosticChecker, inLibCall: boolean): boolean {
if (!this.tscStrictDiagnostics || !this.sourceFile) {
return false;
@ -930,7 +930,7 @@ export class TypeScriptLinter {
if (!checkInRange) {
return true;
}
if (val.start === undefined || checkInRange(val.start)) {
if (val.start === undefined || checkInRange(val.start, val.length)) {
return true;
}
if (TypeScriptLinter.unknowDiagnosticCache.has(val)) {
@ -2109,8 +2109,9 @@ export class TypeScriptLinter {
[ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE]: (pos: number) => {
return this.checkInRange(rangesToFilter, pos);
},
[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE]: (pos: number) => {
return this.checkInRange(rangesToFilter, pos);
[NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE]: (pos: number, length?: number) => {
// The 'No-overload...' error is in some cases mounted on the callExpression node rather than a argument node
return this.checkInRange(rangesToFilter, pos) && !(length && callExpr.end === pos + length);
},
[TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE]: (pos: number) => {
return this.checkInRange(rangesToFilter, pos);

View File

@ -25,7 +25,8 @@
"testcase/arkts-sendable-generic-types/@arkts.lang.d.ets",
"testcase/arkts-sendable-obj-init/@arkts.lang.d.ets",
"testcase/arkts-no-structural-typing/@arkts.lang.d.ets",
"testcase/common-lib/@arkts.lang.d.ets"],
"testcase/common-lib/@arkts.lang.d.ets",
"testcase/arkts-strict/oh_modules/ohos_lib.ts"],
"beta2":["testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.ets",
"testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.ets"],
"beta3":["testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.ets",

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 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.
*/
import { foo_lib } from './oh_modules/ohos_lib';
export declare class ClassA {
foo(p1: number, p2: string): void;
foo(p1: number, p2: number): void;
}
export declare function foo_local(p11: number, p22: string): undefined;
export declare function foo_local(p11: string, p21: number): undefined;
foo_lib(1, undefined);
foo_lib(undefined, 1);
new ClassA().foo(1, foo_lib(1, undefined)); // there is excessive relaxation
new ClassA().foo(1, undefined);
new ClassA().foo(1, foo_local(1, undefined));

View File

@ -0,0 +1,48 @@
{
"arktsVersion_1_0": [
{
"messageText": "No overload matches this call.",
"expectLineAndCharacter": {
"line": 29,
"character": 21
}
},
{
"messageText": "No overload matches this call.",
"expectLineAndCharacter": {
"line": 30,
"character": 21
}
},
{
"messageText": "No overload matches this call.",
"expectLineAndCharacter": {
"line": 30,
"character": 21
}
}
],
"arktsVersion_1_1": [
{
"messageText": "No overload matches this call.",
"expectLineAndCharacter": {
"line": 29,
"character": 21
}
},
{
"messageText": "No overload matches this call.",
"expectLineAndCharacter": {
"line": 30,
"character": 21
}
},
{
"messageText": "No overload matches this call.",
"expectLineAndCharacter": {
"line": 30,
"character": 21
}
}
]
}

View File

@ -0,0 +1,17 @@
/*
* Copyright (c) 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.
*/
export declare function foo_lib(p1: number, p2: string): undefined;
export declare function foo_lib(p1: string, p2: number): undefined;