@zzzen/pyright-internal 1.2.0-dev.20230528 → 1.2.0-dev.20230611
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/checker.js +42 -29
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +31 -16
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +35 -10
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -0
- package/dist/analyzer/importResolver.js +57 -35
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +2 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/patternMatching.js +2 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +19 -12
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +182 -183
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +13 -0
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +204 -194
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +128 -70
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -0
- package/dist/analyzer/typeGuards.js +1 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +13 -14
- package/dist/analyzer/typeUtils.js +126 -100
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +12 -1
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.d.ts +22 -0
- package/dist/analyzer/typeWalker.js +164 -0
- package/dist/analyzer/typeWalker.js.map +1 -0
- package/dist/analyzer/types.d.ts +3 -2
- package/dist/analyzer/types.js +19 -12
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +5 -3
- package/dist/backgroundAnalysisBase.js +2 -2
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +12 -9
- package/dist/backgroundThreadBase.js +28 -20
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/charCodes.d.ts +147 -0
- package/dist/common/charCodes.js +164 -0
- package/dist/common/charCodes.js.map +1 -0
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +3 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageServerBase.d.ts +3 -3
- package/dist/languageServerBase.js +2 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -0
- package/dist/languageService/definitionProvider.js +82 -74
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +16 -8
- package/dist/languageService/hoverProvider.js +53 -53
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +10 -6
- package/dist/localization/localize.js +4 -3
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +4 -3
- package/dist/parser/characterStream.js.map +1 -1
- package/dist/parser/characters.js.map +1 -1
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.js +10 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -0
- package/dist/pyrightFileSystem.js +3 -0
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -0
- package/dist/readonlyAugmentedFileSystem.js +3 -0
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/checker.test.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +1 -0
- package/dist/tests/harness/fourslash/testLanguageService.js +3 -0
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +12 -1
- package/dist/tests/harness/vfs/filesystem.js +33 -6
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/service.test.js +10 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +13 -2
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +5 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +9 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +21 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +2 -0
- package/dist/workspaceFactory.js +11 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -2
@@ -651,6 +651,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
651
651
|
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
652
652
|
!(0, types_1.isNever)(inferenceContext.expectedType)) {
|
653
653
|
expectedTypeCache.set(node.id, inferenceContext.expectedType);
|
654
|
+
// If this is a generic function and there is a signature tracker,
|
655
|
+
// make sure the signature is unique.
|
656
|
+
if (inferenceContext.signatureTracker && (0, types_1.isFunction)(typeResult.type)) {
|
657
|
+
typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, inferenceContext.signatureTracker, node.start);
|
658
|
+
}
|
654
659
|
if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
|
655
660
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
656
661
|
// Make sure the resulting type is assignable to the expected type.
|
@@ -3093,10 +3098,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3093
3098
|
// Is this a generic class that needs to be specialized?
|
3094
3099
|
if ((0, types_1.isInstantiableClass)(type)) {
|
3095
3100
|
if ((flags & 128 /* ExpectingType */) !== 0) {
|
3096
|
-
if ((0, typeUtils_1.requiresTypeArguments)(type)
|
3097
|
-
|
3098
|
-
|
3099
|
-
|
3101
|
+
if (!type.typeAliasInfo && (0, typeUtils_1.requiresTypeArguments)(type)) {
|
3102
|
+
if (!type.typeArguments || !type.isTypeArgumentExplicit) {
|
3103
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportMissingTypeArgument, diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.Localizer.Diagnostic.typeArgsMissingForClass().format({
|
3104
|
+
name: type.aliasName || type.details.name,
|
3105
|
+
}), node);
|
3106
|
+
}
|
3100
3107
|
}
|
3101
3108
|
}
|
3102
3109
|
if (!type.typeArguments) {
|
@@ -5130,7 +5137,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5130
5137
|
}
|
5131
5138
|
let expectedTypeDiagAddendum;
|
5132
5139
|
if (effectiveExpectedType) {
|
5133
|
-
const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType
|
5140
|
+
const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType,
|
5141
|
+
/* isTypeIncomplete */ false, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker));
|
5134
5142
|
if (result && !result.typeErrors) {
|
5135
5143
|
return result;
|
5136
5144
|
}
|
@@ -5170,7 +5178,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5170
5178
|
}
|
5171
5179
|
else {
|
5172
5180
|
const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClassType));
|
5173
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node))) {
|
5181
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
5174
5182
|
return undefined;
|
5175
5183
|
}
|
5176
5184
|
const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClassType, tupleTypeVarContext);
|
@@ -5183,7 +5191,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5183
5191
|
}
|
5184
5192
|
}
|
5185
5193
|
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
|
5186
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined)));
|
5194
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete, inferenceContext.signatureTracker)));
|
5187
5195
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
5188
5196
|
const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults),
|
5189
5197
|
/* isTypeArgumentExplicit */ true));
|
@@ -5275,6 +5283,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5275
5283
|
return functionArg;
|
5276
5284
|
});
|
5277
5285
|
let typeResult = { type: types_1.UnknownType.create() };
|
5286
|
+
// If the inference context has an associated signature tracker, make sure
|
5287
|
+
// the base type of this call is not the same as one of the tracked signatures.
|
5288
|
+
// This is important for nested generic calls (e.g. "foo(foo(x))").
|
5289
|
+
if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) {
|
5290
|
+
baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, inferenceContext.signatureTracker, node.leftExpression.start);
|
5291
|
+
}
|
5278
5292
|
if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
5279
5293
|
if (node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === 'super') {
|
5280
5294
|
// Handle the built-in "super" call specially.
|
@@ -5774,19 +5788,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5774
5788
|
let isSubtypeSubsumed = false;
|
5775
5789
|
for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
|
5776
5790
|
if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
|
5777
|
-
|
5791
|
+
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(dedupedMatchResults[dedupedIndex],
|
5792
|
+
/* recurse */ false);
|
5793
|
+
if (!anyOrUnknown) {
|
5778
5794
|
isSubtypeSubsumed = true;
|
5779
5795
|
}
|
5780
|
-
else if (
|
5796
|
+
else if ((0, types_1.isAny)(anyOrUnknown)) {
|
5781
5797
|
dedupedResultsIncludeAny = true;
|
5782
5798
|
}
|
5783
5799
|
break;
|
5784
5800
|
}
|
5785
5801
|
else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
|
5786
|
-
|
5802
|
+
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(result.returnType, /* recurse */ false);
|
5803
|
+
if (!anyOrUnknown) {
|
5787
5804
|
dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
|
5788
5805
|
}
|
5789
|
-
else if (
|
5806
|
+
else if ((0, types_1.isAny)(anyOrUnknown)) {
|
5790
5807
|
dedupedResultsIncludeAny = true;
|
5791
5808
|
}
|
5792
5809
|
break;
|
@@ -5875,6 +5892,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5875
5892
|
function getBestOverloadForArguments(errorNode, typeResult, argList) {
|
5876
5893
|
let overloadIndex = 0;
|
5877
5894
|
let matches = [];
|
5895
|
+
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
5878
5896
|
// Create a list of potential overload matches based on arguments.
|
5879
5897
|
types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
|
5880
5898
|
useSpeculativeMode(errorNode, () => {
|
@@ -5890,7 +5908,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5890
5908
|
matches.forEach((match, matchIndex) => {
|
5891
5909
|
if (winningOverloadIndex === undefined) {
|
5892
5910
|
useSpeculativeMode(errorNode, () => {
|
5893
|
-
const callResult = validateFunctionArgumentTypes(errorNode, match, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(match.overload)),
|
5911
|
+
const callResult = validateFunctionArgumentTypes(errorNode, match, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(match.overload)), signatureTracker,
|
5894
5912
|
/* skipUnknownArgCheck */ true);
|
5895
5913
|
if (callResult && !callResult.argumentErrors) {
|
5896
5914
|
winningOverloadIndex = matchIndex;
|
@@ -5945,9 +5963,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5945
5963
|
}
|
5946
5964
|
return { argumentErrors: true, isTypeIncomplete: false, overloadsUsedForCall: [] };
|
5947
5965
|
}
|
5948
|
-
// Create a helper
|
5966
|
+
// Create a helper function that evaluates the overload that matches
|
5949
5967
|
// the arg/param lists.
|
5950
|
-
|
5968
|
+
function evaluateUsingLastMatchingOverload(skipUnknownArgCheck) {
|
5951
5969
|
// Find the match with the largest overload index (i.e. the last overload
|
5952
5970
|
// that was in the overload list).
|
5953
5971
|
const lastMatch = filteredMatchResults.reduce((previous, current) => {
|
@@ -5957,7 +5975,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5957
5975
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(lastMatch.overload));
|
5958
5976
|
effectiveTypeVarContext.unlock();
|
5959
5977
|
return validateFunctionArgumentTypesWithContext(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
5960
|
-
}
|
5978
|
+
}
|
5961
5979
|
// If there is only one possible arg/param match among the overloads,
|
5962
5980
|
// use the normal type matching mechanism because it is faster and
|
5963
5981
|
// will provide a clearer error message.
|
@@ -6449,7 +6467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6449
6467
|
const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
|
6450
6468
|
if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
|
6451
6469
|
const tupleTypeArgs = (_a = combinedArgType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [];
|
6452
|
-
if (tupleTypeArgs.length !== 1) {
|
6470
|
+
if (tupleTypeArgs.length !== 1 || !tupleTypeArgs[0].isUnbounded) {
|
6453
6471
|
for (const tupleTypeArg of tupleTypeArgs) {
|
6454
6472
|
if (tupleTypeArg.isUnbounded) {
|
6455
6473
|
expandedArgList.push({
|
@@ -7092,7 +7110,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7092
7110
|
if (paramIndex >= paramDetails.firstPositionOrKeywordIndex &&
|
7093
7111
|
param.category === 0 /* Simple */ &&
|
7094
7112
|
param.name &&
|
7095
|
-
!param.hasDefault &&
|
7096
7113
|
paramMap.has(param.name) &&
|
7097
7114
|
paramMap.get(param.name).argsReceived === 0) {
|
7098
7115
|
const paramType = paramDetails.params[paramIndex].type;
|
@@ -7266,16 +7283,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7266
7283
|
// types of each argument expression and validates that the resulting type is
|
7267
7284
|
// compatible with the declared type of the corresponding parameter.
|
7268
7285
|
function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
|
7269
|
-
var _a;
|
7286
|
+
var _a, _b;
|
7270
7287
|
const type = matchResults.overload;
|
7288
|
+
const signatureTracker = (_a = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) !== null && _a !== void 0 ? _a : new typeUtils_1.UniqueSignatureTracker();
|
7289
|
+
matchResults.overload = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(matchResults.overload, signatureTracker, errorNode.start);
|
7271
7290
|
// Can we safely ignore the inference context (either because it's not provided
|
7272
7291
|
// or will have no effect)? If so, we can eliminate a bunch of extra work.
|
7273
7292
|
if (!inferenceContext ||
|
7274
7293
|
(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
|
7275
7294
|
(0, types_1.isNever)(inferenceContext.expectedType) ||
|
7276
7295
|
!type.details.declaredReturnType ||
|
7277
|
-
!(0, typeUtils_1.requiresSpecialization)((
|
7278
|
-
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck);
|
7296
|
+
!(0, typeUtils_1.requiresSpecialization)((_b = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create())) {
|
7297
|
+
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
|
7279
7298
|
}
|
7280
7299
|
const effectiveReturnType = getFunctionEffectiveReturnType(type);
|
7281
7300
|
let effectiveExpectedType = inferenceContext.expectedType;
|
@@ -7292,7 +7311,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7292
7311
|
assignType(effectiveReturnType, effectiveExpectedType,
|
7293
7312
|
/* diag */ undefined, typeVarContextCopy,
|
7294
7313
|
/* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
|
7295
|
-
const speculativeResults = validateFunctionArgumentTypes(errorNode, matchResults, typeVarContextCopy, skipUnknownArgCheck);
|
7314
|
+
const speculativeResults = validateFunctionArgumentTypes(errorNode, matchResults, typeVarContextCopy, signatureTracker, skipUnknownArgCheck);
|
7296
7315
|
if (speculativeResults === null || speculativeResults === void 0 ? void 0 : speculativeResults.argumentErrors) {
|
7297
7316
|
effectiveExpectedType = undefined;
|
7298
7317
|
}
|
@@ -7319,7 +7338,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7319
7338
|
}
|
7320
7339
|
if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
|
7321
7340
|
const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
|
7322
|
-
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes);
|
7341
|
+
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start);
|
7323
7342
|
const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
|
7324
7343
|
/* typeArguments */ undefined,
|
7325
7344
|
/* isTypeArgumentExplicit */ false);
|
@@ -7335,14 +7354,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7335
7354
|
});
|
7336
7355
|
}
|
7337
7356
|
}
|
7338
|
-
effectiveExpectedType = (0, typeUtils_1.transformExpectedType)(effectiveExpectedType, liveTypeVarScopes);
|
7357
|
+
effectiveExpectedType = (0, typeUtils_1.transformExpectedType)(effectiveExpectedType, liveTypeVarScopes, errorNode.start);
|
7339
7358
|
assignType(effectiveReturnType, effectiveExpectedType,
|
7340
7359
|
/* diag */ undefined, typeVarContext,
|
7341
7360
|
/* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
|
7342
7361
|
}
|
7343
|
-
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck);
|
7362
|
+
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
|
7344
7363
|
}
|
7345
|
-
function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false) {
|
7364
|
+
function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck = false) {
|
7346
7365
|
const type = matchResults.overload;
|
7347
7366
|
let isTypeIncomplete = matchResults.isTypeIncomplete;
|
7348
7367
|
let argumentErrors = false;
|
@@ -7400,11 +7419,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7400
7419
|
// example of this is the built-in "map" method whose first parameter is
|
7401
7420
|
// a lambda and second parameter indicates what type the lambda should accept.
|
7402
7421
|
// In practice, we will limit the number of passes to 2 because it can get
|
7403
|
-
// very expensive to go beyond this, and we don't
|
7422
|
+
// very expensive to go beyond this, and we don't generally see cases
|
7404
7423
|
// where more than two passes are needed.
|
7405
7424
|
let passCount = Math.min(typeVarMatchingCount, 2);
|
7406
7425
|
for (let i = 0; i < passCount; i++) {
|
7407
|
-
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7408
7426
|
useSpeculativeMode(errorNode, () => {
|
7409
7427
|
matchResults.argParams.forEach((argParam) => {
|
7410
7428
|
if (!argParam.requiresTypeVarMatching) {
|
@@ -7448,7 +7466,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7448
7466
|
let sawParamSpecKwargs = false;
|
7449
7467
|
let condition = [];
|
7450
7468
|
const argResults = [];
|
7451
|
-
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7452
7469
|
matchResults.argParams.forEach((argParam) => {
|
7453
7470
|
var _a;
|
7454
7471
|
const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, {
|
@@ -7739,7 +7756,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7739
7756
|
if (paramType) {
|
7740
7757
|
const argResult = validateArgType({
|
7741
7758
|
paramCategory: 0 /* Simple */,
|
7742
|
-
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes),
|
7759
|
+
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes, /* usageOffset */ undefined),
|
7743
7760
|
requiresTypeVarMatching: false,
|
7744
7761
|
argument: arg,
|
7745
7762
|
errorNode: arg.valueExpression || errorNode,
|
@@ -7837,12 +7854,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7837
7854
|
32 /* DisallowParamSpec */ |
|
7838
7855
|
64 /* DisallowTypeVarTuple */
|
7839
7856
|
: 0 /* None */;
|
7840
|
-
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)));
|
7857
|
+
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
|
7841
7858
|
argType = exprTypeResult.type;
|
7842
7859
|
// If the type includes multiple instances of a generic function
|
7843
7860
|
// signature, force the type arguments for the duplicates to have
|
7844
7861
|
// unique names.
|
7845
|
-
argType = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(argType, signatureTracker);
|
7862
|
+
argType = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(argType, signatureTracker, argParam.argument.valueExpression.start);
|
7846
7863
|
if (exprTypeResult.isIncomplete) {
|
7847
7864
|
isTypeIncomplete = true;
|
7848
7865
|
}
|
@@ -8017,7 +8034,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8017
8034
|
if (!options.skipUnknownArgCheck) {
|
8018
8035
|
const simplifiedType = (0, types_1.removeUnbound)(argType);
|
8019
8036
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
8020
|
-
|
8037
|
+
function getDiagAddendum() {
|
8021
8038
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
8022
8039
|
if (argParam.paramName) {
|
8023
8040
|
diagAddendum.addMessage((functionName
|
@@ -8029,7 +8046,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8029
8046
|
diagAddendum.getString());
|
8030
8047
|
}
|
8031
8048
|
return diagAddendum;
|
8032
|
-
}
|
8049
|
+
}
|
8033
8050
|
// Do not check for unknown types if the expected type is "Any".
|
8034
8051
|
// Don't print types if reportUnknownArgumentType is disabled for performance.
|
8035
8052
|
if (fileInfo.diagnosticRuleSet.reportUnknownArgumentType !== 'none' &&
|
@@ -8720,7 +8737,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8720
8737
|
return undefined;
|
8721
8738
|
}
|
8722
8739
|
const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
|
8723
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node))) {
|
8740
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
8724
8741
|
return undefined;
|
8725
8742
|
}
|
8726
8743
|
const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
|
@@ -8982,7 +8999,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8982
8999
|
return undefined;
|
8983
9000
|
}
|
8984
9001
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInListOrSet));
|
8985
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node))) {
|
9002
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
8986
9003
|
return undefined;
|
8987
9004
|
}
|
8988
9005
|
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInListOrSet), typeVarContext);
|
@@ -9203,7 +9220,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9203
9220
|
expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
|
9204
9221
|
const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
|
9205
9222
|
const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
|
9223
|
+
const hasParamSpec = !!functionType.details.paramSpec;
|
9206
9224
|
return (hasVarArgs ||
|
9225
|
+
hasParamSpec ||
|
9207
9226
|
(functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
|
9208
9227
|
});
|
9209
9228
|
}
|
@@ -9265,10 +9284,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9265
9284
|
type: types_1.UnknownType.create(),
|
9266
9285
|
});
|
9267
9286
|
}
|
9268
|
-
// Handle the case where the expected type contains a ParamSpec.
|
9269
|
-
if (expectedFunctionType === null || expectedFunctionType === void 0 ? void 0 : expectedFunctionType.details.paramSpec) {
|
9270
|
-
functionType.details.paramSpec = expectedFunctionType.details.paramSpec;
|
9271
|
-
}
|
9272
9287
|
const expectedReturnType = expectedFunctionType
|
9273
9288
|
? getFunctionEffectiveReturnType(expectedFunctionType)
|
9274
9289
|
: undefined;
|
@@ -9742,7 +9757,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9742
9757
|
let isLiteralType = true;
|
9743
9758
|
(0, typeUtils_1.doForEachSubtype)(exprType.type, (subtype) => {
|
9744
9759
|
if (!(0, types_1.isInstantiableClass)(subtype) || subtype.literalValue === undefined) {
|
9745
|
-
|
9760
|
+
if (!(0, types_1.isNoneTypeClass)(subtype)) {
|
9761
|
+
isLiteralType = false;
|
9762
|
+
}
|
9746
9763
|
}
|
9747
9764
|
});
|
9748
9765
|
if (isLiteralType) {
|
@@ -10695,7 +10712,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10695
10712
|
let protocolTypeParameters;
|
10696
10713
|
const initSubclassArgs = [];
|
10697
10714
|
let metaclassNode;
|
10698
|
-
let isMetaclassDeferred = false;
|
10699
10715
|
let exprFlags = 128 /* ExpectingType */ |
|
10700
10716
|
1024 /* AllowGenericClassType */ |
|
10701
10717
|
262144 /* DisallowNakedGeneric */ |
|
@@ -10750,7 +10766,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10750
10766
|
dependency: argType,
|
10751
10767
|
callback: () => completeClassTypeDeferred(classType, node, node.name),
|
10752
10768
|
});
|
10753
|
-
isMetaclassDeferred = true;
|
10754
10769
|
}
|
10755
10770
|
if (types_1.ClassType.isBuiltIn(argType, 'Protocol')) {
|
10756
10771
|
if (!fileInfo.isStubFile &&
|
@@ -11033,7 +11048,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11033
11048
|
for (let i = node.decorators.length - 1; i >= 0; i--) {
|
11034
11049
|
const decorator = node.decorators[i];
|
11035
11050
|
const newDecoratedType = applyClassDecorator(decoratedType, classType, decorator);
|
11036
|
-
|
11051
|
+
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
11052
|
+
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
11037
11053
|
// Report this error only on the first unknown type.
|
11038
11054
|
if (!foundUnknown) {
|
11039
11055
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedClassDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedClassDecorator, localize_1.Localizer.Diagnostic.classDecoratorTypeUnknown(), node.decorators[i].expression);
|
@@ -11120,11 +11136,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11120
11136
|
writeTypeCache(node.name, { type: classType }, 0 /* None */);
|
11121
11137
|
// Update the decorated class type.
|
11122
11138
|
writeTypeCache(node, { type: decoratedType }, 0 /* None */);
|
11123
|
-
// Validate that arguments passed to `__init_subclass__` are of the correct type.
|
11124
|
-
// Defer this if the metaclass calculation is deferred.
|
11125
|
-
if (!isMetaclassDeferred) {
|
11126
|
-
validateInitSubclassArgs(node, classType);
|
11127
|
-
}
|
11128
11139
|
return { classType, decoratedType };
|
11129
11140
|
}
|
11130
11141
|
// Determines whether the type parameters has a default that refers to another
|
@@ -11414,7 +11425,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11414
11425
|
}
|
11415
11426
|
// Recompute the effective metaclass.
|
11416
11427
|
computeEffectiveMetaclass(type, errorNode);
|
11417
|
-
validateInitSubclassArgs(node, type);
|
11418
11428
|
}
|
11419
11429
|
function validateInitSubclassArgs(node, classType) {
|
11420
11430
|
// Collect arguments that will be passed to the `__init_subclass__`
|
@@ -11867,7 +11877,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11867
11877
|
for (let i = node.decorators.length - 1; i >= 0; i--) {
|
11868
11878
|
const decorator = node.decorators[i];
|
11869
11879
|
const newDecoratedType = applyFunctionDecorator(decoratedType, functionType, decorator, node);
|
11870
|
-
|
11880
|
+
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
11881
|
+
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
11871
11882
|
// Report this error only on the first unknown type.
|
11872
11883
|
if (!foundUnknown) {
|
11873
11884
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
@@ -14000,7 +14011,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14000
14011
|
return undefined;
|
14001
14012
|
}
|
14002
14013
|
function getDeclarationsForNameNode(node, skipUnreachableCode = true) {
|
14003
|
-
var _a;
|
14014
|
+
var _a, _b, _c;
|
14004
14015
|
if (skipUnreachableCode && AnalyzerNodeInfo.isCodeUnreachable(node)) {
|
14005
14016
|
return undefined;
|
14006
14017
|
}
|
@@ -14101,7 +14112,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14101
14112
|
// the corresponding named parameter can be determined from the context.
|
14102
14113
|
const argNode = node.parent;
|
14103
14114
|
const paramName = node.value;
|
14104
|
-
if (argNode.parent
|
14115
|
+
if (((_a = argNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
14105
14116
|
const baseType = getType(argNode.parent.leftExpression);
|
14106
14117
|
if (baseType) {
|
14107
14118
|
if ((0, types_1.isFunction)(baseType) && baseType.details.declaration) {
|
@@ -14119,8 +14130,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14119
14130
|
});
|
14120
14131
|
}
|
14121
14132
|
else if ((0, types_1.isInstantiableClass)(baseType)) {
|
14122
|
-
const initMethodType = (
|
14123
|
-
/* diag */ undefined, 4 /* SkipObjectBaseClass */)) === null ||
|
14133
|
+
const initMethodType = (_b = getTypeOfObjectMember(argNode.parent.leftExpression, types_1.ClassType.cloneAsInstance(baseType), '__init__', { method: 'get' },
|
14134
|
+
/* diag */ undefined, 4 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
|
14124
14135
|
if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
|
14125
14136
|
const paramDecl = getDeclarationFromFunctionNamedParameter(initMethodType, paramName);
|
14126
14137
|
if (paramDecl) {
|
@@ -14136,6 +14147,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14136
14147
|
}
|
14137
14148
|
}
|
14138
14149
|
}
|
14150
|
+
else if (((_c = argNode.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 10 /* Class */) {
|
14151
|
+
const classTypeResult = getTypeOfClass(argNode.parent);
|
14152
|
+
// Validate the init subclass args for this class so we can properly
|
14153
|
+
// evaluate its custom keyword parameters.
|
14154
|
+
if (classTypeResult) {
|
14155
|
+
validateInitSubclassArgs(argNode.parent, classTypeResult.classType);
|
14156
|
+
}
|
14157
|
+
}
|
14139
14158
|
}
|
14140
14159
|
else {
|
14141
14160
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -15034,6 +15053,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15034
15053
|
types_1.FunctionType.hasUnannotatedParams(type) &&
|
15035
15054
|
!types_1.FunctionType.isStubDefinition(type) &&
|
15036
15055
|
!types_1.FunctionType.isPyTypedDefinition(type) &&
|
15056
|
+
!types_1.FunctionType.isWrapReturnTypeInAwait(type) &&
|
15037
15057
|
args) {
|
15038
15058
|
const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, args);
|
15039
15059
|
if (contextualReturnType) {
|
@@ -15386,10 +15406,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15386
15406
|
});
|
15387
15407
|
return isAssignable;
|
15388
15408
|
}
|
15389
|
-
|
15390
|
-
|
15391
|
-
|
15392
|
-
|
15409
|
+
// Adjusts the source type arguments list to match the length of the
|
15410
|
+
// dest type arguments list if the dest list contains an unbounded
|
15411
|
+
// or variadic entry.
|
15412
|
+
function adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs) {
|
15393
15413
|
const destVariadicIndex = destTypeArgs.findIndex((t) => (0, types_1.isVariadicTypeVar)(t.type));
|
15394
15414
|
const destUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
|
15395
15415
|
const srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
|
@@ -15437,6 +15457,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15437
15457
|
}
|
15438
15458
|
}
|
15439
15459
|
}
|
15460
|
+
}
|
15461
|
+
function assignTupleTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
15462
|
+
var _a, _b;
|
15463
|
+
const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
|
15464
|
+
const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
|
15465
|
+
let srcUnboundedIndex;
|
15466
|
+
if (flags & 2 /* ReverseTypeVarMatching */) {
|
15467
|
+
adjustSourceTupleTypeArgs(srcTypeArgs, destTypeArgs);
|
15468
|
+
srcUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
|
15469
|
+
}
|
15470
|
+
else {
|
15471
|
+
adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs);
|
15472
|
+
srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
|
15473
|
+
}
|
15440
15474
|
if (srcTypeArgs.length === destTypeArgs.length) {
|
15441
15475
|
for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
|
15442
15476
|
const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
@@ -15703,6 +15737,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15703
15737
|
(transformedSrcType !== srcType && (0, types_1.isUnion)(transformedSrcType))) {
|
15704
15738
|
// Use a smaller recursive limit in this case to prevent runaway recursion.
|
15705
15739
|
if (recursionCount > maxRecursiveTypeAliasRecursionCount) {
|
15740
|
+
// Add a special case for when the source is a str, which is itself
|
15741
|
+
// a recursive type (since it derives from Sequence[str]).
|
15742
|
+
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'str') && (0, types_1.isUnion)(transformedDestType)) {
|
15743
|
+
return transformedDestType.subtypes.some((subtype) => (0, types_1.isClassInstance)(subtype) && types_1.ClassType.isBuiltIn(subtype, ['object', 'str']));
|
15744
|
+
}
|
15706
15745
|
return true;
|
15707
15746
|
}
|
15708
15747
|
}
|
@@ -17170,7 +17209,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17170
17209
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
|
17171
17210
|
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
|
17172
17211
|
/* typeArguments */ undefined,
|
17173
|
-
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node));
|
17212
|
+
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start);
|
17174
17213
|
let replacedTypeArg = false;
|
17175
17214
|
const newTypeArgs = assignedType.typeArguments.map((typeArg, index) => {
|
17176
17215
|
const typeParam = assignedType.details.typeParameters[index];
|
@@ -17267,25 +17306,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17267
17306
|
return validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames);
|
17268
17307
|
}
|
17269
17308
|
// For an overload overriding a base method, at least one overload
|
17270
|
-
// must be compatible with the base method.
|
17271
|
-
if (
|
17309
|
+
// or the implementation must be compatible with the base method.
|
17310
|
+
if (overrideMethod.overloads.some((overrideOverload) => {
|
17272
17311
|
return validateOverrideMethodInternal(baseMethod, overrideOverload,
|
17273
17312
|
/* diag */ undefined, enforceParamNames);
|
17274
17313
|
})) {
|
17275
17314
|
return true;
|
17276
17315
|
}
|
17277
|
-
// Or the implementation must be compatible.
|
17278
|
-
const overrideImplementation = types_1.OverloadedFunctionType.getImplementation(overrideMethod);
|
17279
|
-
if (overrideImplementation) {
|
17280
|
-
if (validateOverrideMethodInternal(baseMethod, overrideImplementation,
|
17281
|
-
/* diag */ undefined, enforceParamNames)) {
|
17282
|
-
return true;
|
17283
|
-
}
|
17284
|
-
}
|
17285
17316
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNoOverloadMatches());
|
17286
17317
|
return false;
|
17287
17318
|
}
|
17288
|
-
//
|
17319
|
+
// For a non-overloaded method overriding an overloaded method, the
|
17320
|
+
// override must match all of the overloads.
|
17321
|
+
if ((0, types_1.isFunction)(overrideMethod)) {
|
17322
|
+
return types_1.OverloadedFunctionType.getOverloads(baseMethod).every((overload) => validateOverrideMethodInternal(overload, overrideMethod, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), enforceParamNames));
|
17323
|
+
}
|
17324
|
+
// For an overloaded method overriding an overloaded method, the overrides
|
17325
|
+
// must all match and be in the correct order. It is OK if the base method
|
17326
|
+
// has additional overloads that are not present in the override.
|
17327
|
+
let previousMatchIndex = -1;
|
17328
|
+
let overrideOverloadIndex = 0;
|
17329
|
+
for (const overrideOverload of types_1.OverloadedFunctionType.getOverloads(overrideMethod)) {
|
17330
|
+
const matchIndex = types_1.OverloadedFunctionType.getOverloads(baseMethod).findIndex((baseOverload) => {
|
17331
|
+
return validateOverrideMethodInternal(baseOverload, overrideOverload,
|
17332
|
+
/* diag */ undefined, enforceParamNames);
|
17333
|
+
});
|
17334
|
+
if (matchIndex < 0) {
|
17335
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex }));
|
17336
|
+
return false;
|
17337
|
+
}
|
17338
|
+
if (matchIndex < previousMatchIndex) {
|
17339
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadOrder());
|
17340
|
+
return false;
|
17341
|
+
}
|
17342
|
+
previousMatchIndex = matchIndex;
|
17343
|
+
overrideOverloadIndex++;
|
17344
|
+
}
|
17289
17345
|
return true;
|
17290
17346
|
}
|
17291
17347
|
function validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames) {
|
@@ -17971,6 +18027,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17971
18027
|
verifyRaiseExceptionType,
|
17972
18028
|
verifyDeleteExpression,
|
17973
18029
|
validateOverloadedFunctionArguments,
|
18030
|
+
validateInitSubclassArgs,
|
17974
18031
|
isAfterNodeReachable,
|
17975
18032
|
isNodeReachable,
|
17976
18033
|
isAsymmetricDescriptorAssignment: isAsymmetricAccessorAssignment,
|
@@ -18018,6 +18075,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18018
18075
|
getBuiltInObject,
|
18019
18076
|
getTypingType,
|
18020
18077
|
verifyTypeArgumentsAssignable,
|
18078
|
+
reportMissingTypeArguments,
|
18021
18079
|
inferReturnTypeIfNecessary,
|
18022
18080
|
inferTypeParameterVarianceForClass,
|
18023
18081
|
isFinalVariable,
|