@zzzen/pyright-internal 1.2.0-dev.20230528 → 1.2.0-dev.20230604
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/constraintSolver.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +18 -6
- 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/patternMatching.js +2 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +9 -4
- package/dist/analyzer/program.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 +103 -46
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.js +1 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +5 -6
- package/dist/analyzer/typeUtils.js +126 -142
- 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 +4 -2
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -0
- package/dist/tests/service.test.js +10 -0
- package/dist/tests/service.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 +16 -0
- 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/package.json +1 -1
@@ -5170,7 +5170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5170
5170
|
}
|
5171
5171
|
else {
|
5172
5172
|
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))) {
|
5173
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
5174
5174
|
return undefined;
|
5175
5175
|
}
|
5176
5176
|
const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClassType, tupleTypeVarContext);
|
@@ -5685,7 +5685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5685
5685
|
// (one for each argument) will be undefined. On subsequent calls, this
|
5686
5686
|
// list will grow to include union expansions.
|
5687
5687
|
function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
5688
|
-
var _a, _b;
|
5688
|
+
var _a, _b, _c;
|
5689
5689
|
const returnTypes = [];
|
5690
5690
|
const matchedOverloads = [];
|
5691
5691
|
let isTypeIncomplete = false;
|
@@ -5774,19 +5774,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5774
5774
|
let isSubtypeSubsumed = false;
|
5775
5775
|
for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
|
5776
5776
|
if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
|
5777
|
-
|
5777
|
+
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(dedupedMatchResults[dedupedIndex],
|
5778
|
+
/* recurse */ false);
|
5779
|
+
if (!anyOrUnknown) {
|
5778
5780
|
isSubtypeSubsumed = true;
|
5779
5781
|
}
|
5780
|
-
else if (
|
5782
|
+
else if ((0, types_1.isAny)(anyOrUnknown)) {
|
5781
5783
|
dedupedResultsIncludeAny = true;
|
5782
5784
|
}
|
5783
5785
|
break;
|
5784
5786
|
}
|
5785
5787
|
else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
|
5786
|
-
|
5788
|
+
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(result.returnType, /* recurse */ false);
|
5789
|
+
if (!anyOrUnknown) {
|
5787
5790
|
dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
|
5788
5791
|
}
|
5789
|
-
else if (
|
5792
|
+
else if ((0, types_1.isAny)(anyOrUnknown)) {
|
5790
5793
|
dedupedResultsIncludeAny = true;
|
5791
5794
|
}
|
5792
5795
|
break;
|
@@ -5809,7 +5812,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5809
5812
|
effectiveReturnType = types_1.AnyType.create();
|
5810
5813
|
}
|
5811
5814
|
else {
|
5812
|
-
|
5815
|
+
// If all of the return types are the same generic class,
|
5816
|
+
// replace the type arguments with Unknown. Otherwise return
|
5817
|
+
// an Unknown type that has associated "possible types" to aid
|
5818
|
+
// with completion suggestions.
|
5819
|
+
effectiveReturnType =
|
5820
|
+
(_c = (0, typeUtils_1.getCommonErasedType)(dedupedMatchResults)) !== null && _c !== void 0 ? _c : types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown);
|
5813
5821
|
}
|
5814
5822
|
}
|
5815
5823
|
returnTypes.push(effectiveReturnType);
|
@@ -5850,6 +5858,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5850
5858
|
if (matches.length < 2) {
|
5851
5859
|
return matches;
|
5852
5860
|
}
|
5861
|
+
// If the relevance of some matches differs, filter out the ones that
|
5862
|
+
// are lower relevance. This favors *args parameters in cases where
|
5863
|
+
// a *args argument is used.
|
5864
|
+
if (matches[0].matchResults.relevance !== matches[matches.length - 1].matchResults.relevance) {
|
5865
|
+
matches = matches.filter((m) => m.matchResults.relevance === matches[0].matchResults.relevance);
|
5866
|
+
if (matches.length < 2) {
|
5867
|
+
return matches;
|
5868
|
+
}
|
5869
|
+
}
|
5853
5870
|
// If all of the return types match, select the first one.
|
5854
5871
|
if ((0, typeUtils_1.areTypesSame)(matches.map((match) => match.returnType), { treatAnySameAsUnknown: true })) {
|
5855
5872
|
return [matches[0]];
|
@@ -5859,9 +5876,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5859
5876
|
return matches;
|
5860
5877
|
}
|
5861
5878
|
for (let i = 0; i < firstArgResults.length; i++) {
|
5862
|
-
// If the arg
|
5879
|
+
// If the arg contains Any or Unknown, see if the corresponding
|
5863
5880
|
// parameter types differ in any way.
|
5864
|
-
|
5881
|
+
const anyOrUnknownInArg = (0, typeUtils_1.containsAnyOrUnknown)(firstArgResults[i].argType, /* recurse */ true);
|
5882
|
+
if (anyOrUnknownInArg) {
|
5865
5883
|
const paramTypes = matches.map((match) => i < match.matchResults.argParams.length
|
5866
5884
|
? match.matchResults.argParams[i].paramType
|
5867
5885
|
: types_1.UnknownType.create());
|
@@ -7319,7 +7337,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7319
7337
|
}
|
7320
7338
|
if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
|
7321
7339
|
const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
|
7322
|
-
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes);
|
7340
|
+
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start);
|
7323
7341
|
const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
|
7324
7342
|
/* typeArguments */ undefined,
|
7325
7343
|
/* isTypeArgumentExplicit */ false);
|
@@ -7335,7 +7353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7335
7353
|
});
|
7336
7354
|
}
|
7337
7355
|
}
|
7338
|
-
effectiveExpectedType = (0, typeUtils_1.transformExpectedType)(effectiveExpectedType, liveTypeVarScopes);
|
7356
|
+
effectiveExpectedType = (0, typeUtils_1.transformExpectedType)(effectiveExpectedType, liveTypeVarScopes, errorNode.start);
|
7339
7357
|
assignType(effectiveReturnType, effectiveExpectedType,
|
7340
7358
|
/* diag */ undefined, typeVarContext,
|
7341
7359
|
/* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
|
@@ -7347,7 +7365,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7347
7365
|
let isTypeIncomplete = matchResults.isTypeIncomplete;
|
7348
7366
|
let argumentErrors = false;
|
7349
7367
|
let specializedInitSelfType;
|
7350
|
-
let
|
7368
|
+
let accumulatedAnyOrUnknownArg;
|
7351
7369
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
7352
7370
|
if (type.boundTypeVarScopeId) {
|
7353
7371
|
// If the function was bound to a class or object and was a constructor, a
|
@@ -7400,11 +7418,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7400
7418
|
// example of this is the built-in "map" method whose first parameter is
|
7401
7419
|
// a lambda and second parameter indicates what type the lambda should accept.
|
7402
7420
|
// 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
|
7421
|
+
// very expensive to go beyond this, and we don't generally see cases
|
7404
7422
|
// where more than two passes are needed.
|
7405
7423
|
let passCount = Math.min(typeVarMatchingCount, 2);
|
7406
7424
|
for (let i = 0; i < passCount; i++) {
|
7407
7425
|
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7426
|
+
signatureTracker.addSignature(type);
|
7408
7427
|
useSpeculativeMode(errorNode, () => {
|
7409
7428
|
matchResults.argParams.forEach((argParam) => {
|
7410
7429
|
if (!argParam.requiresTypeVarMatching) {
|
@@ -7449,6 +7468,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7449
7468
|
let condition = [];
|
7450
7469
|
const argResults = [];
|
7451
7470
|
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7471
|
+
signatureTracker.addSignature(type);
|
7452
7472
|
matchResults.argParams.forEach((argParam) => {
|
7453
7473
|
var _a;
|
7454
7474
|
const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, {
|
@@ -7465,10 +7485,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7465
7485
|
if (argResult.condition) {
|
7466
7486
|
condition = (_a = types_1.TypeCondition.combine(condition, argResult.condition)) !== null && _a !== void 0 ? _a : [];
|
7467
7487
|
}
|
7468
|
-
if
|
7469
|
-
|
7470
|
-
|
7471
|
-
|
7488
|
+
// Determine if the argument type contains an Any or Unknown. Accumulate
|
7489
|
+
// these across all arguments.
|
7490
|
+
const anyOrUnknownInArg = (0, typeUtils_1.containsAnyOrUnknown)(argResult.argType, /* recurs */ true);
|
7491
|
+
if (anyOrUnknownInArg) {
|
7492
|
+
accumulatedAnyOrUnknownArg = accumulatedAnyOrUnknownArg
|
7493
|
+
? (0, typeUtils_1.preserveUnknown)(anyOrUnknownInArg, accumulatedAnyOrUnknownArg)
|
7494
|
+
: anyOrUnknownInArg;
|
7472
7495
|
}
|
7473
7496
|
if (type.details.paramSpec) {
|
7474
7497
|
if (argParam.argument.argumentCategory === 1 /* UnpackedList */) {
|
@@ -7579,7 +7602,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7579
7602
|
return {
|
7580
7603
|
argumentErrors,
|
7581
7604
|
argResults,
|
7582
|
-
anyOrUnknownArgument,
|
7605
|
+
anyOrUnknownArgument: accumulatedAnyOrUnknownArg,
|
7583
7606
|
returnType: specializedReturnType,
|
7584
7607
|
isTypeIncomplete,
|
7585
7608
|
activeParam: matchResults.activeParam,
|
@@ -7739,7 +7762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7739
7762
|
if (paramType) {
|
7740
7763
|
const argResult = validateArgType({
|
7741
7764
|
paramCategory: 0 /* Simple */,
|
7742
|
-
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes),
|
7765
|
+
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes, /* usageOffset */ undefined),
|
7743
7766
|
requiresTypeVarMatching: false,
|
7744
7767
|
argument: arg,
|
7745
7768
|
errorNode: arg.valueExpression || errorNode,
|
@@ -8017,7 +8040,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8017
8040
|
if (!options.skipUnknownArgCheck) {
|
8018
8041
|
const simplifiedType = (0, types_1.removeUnbound)(argType);
|
8019
8042
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
8020
|
-
|
8043
|
+
function getDiagAddendum() {
|
8021
8044
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
8022
8045
|
if (argParam.paramName) {
|
8023
8046
|
diagAddendum.addMessage((functionName
|
@@ -8029,7 +8052,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8029
8052
|
diagAddendum.getString());
|
8030
8053
|
}
|
8031
8054
|
return diagAddendum;
|
8032
|
-
}
|
8055
|
+
}
|
8033
8056
|
// Do not check for unknown types if the expected type is "Any".
|
8034
8057
|
// Don't print types if reportUnknownArgumentType is disabled for performance.
|
8035
8058
|
if (fileInfo.diagnosticRuleSet.reportUnknownArgumentType !== 'none' &&
|
@@ -8720,7 +8743,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8720
8743
|
return undefined;
|
8721
8744
|
}
|
8722
8745
|
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))) {
|
8746
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
8724
8747
|
return undefined;
|
8725
8748
|
}
|
8726
8749
|
const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
|
@@ -8982,7 +9005,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8982
9005
|
return undefined;
|
8983
9006
|
}
|
8984
9007
|
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))) {
|
9008
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
8986
9009
|
return undefined;
|
8987
9010
|
}
|
8988
9011
|
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInListOrSet), typeVarContext);
|
@@ -9203,7 +9226,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9203
9226
|
expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
|
9204
9227
|
const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
|
9205
9228
|
const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
|
9229
|
+
const hasParamSpec = !!functionType.details.paramSpec;
|
9206
9230
|
return (hasVarArgs ||
|
9231
|
+
hasParamSpec ||
|
9207
9232
|
(functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
|
9208
9233
|
});
|
9209
9234
|
}
|
@@ -9265,10 +9290,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9265
9290
|
type: types_1.UnknownType.create(),
|
9266
9291
|
});
|
9267
9292
|
}
|
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
9293
|
const expectedReturnType = expectedFunctionType
|
9273
9294
|
? getFunctionEffectiveReturnType(expectedFunctionType)
|
9274
9295
|
: undefined;
|
@@ -9742,7 +9763,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9742
9763
|
let isLiteralType = true;
|
9743
9764
|
(0, typeUtils_1.doForEachSubtype)(exprType.type, (subtype) => {
|
9744
9765
|
if (!(0, types_1.isInstantiableClass)(subtype) || subtype.literalValue === undefined) {
|
9745
|
-
|
9766
|
+
if (!(0, types_1.isNoneTypeClass)(subtype)) {
|
9767
|
+
isLiteralType = false;
|
9768
|
+
}
|
9746
9769
|
}
|
9747
9770
|
});
|
9748
9771
|
if (isLiteralType) {
|
@@ -11033,7 +11056,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11033
11056
|
for (let i = node.decorators.length - 1; i >= 0; i--) {
|
11034
11057
|
const decorator = node.decorators[i];
|
11035
11058
|
const newDecoratedType = applyClassDecorator(decoratedType, classType, decorator);
|
11036
|
-
|
11059
|
+
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
11060
|
+
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
11037
11061
|
// Report this error only on the first unknown type.
|
11038
11062
|
if (!foundUnknown) {
|
11039
11063
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedClassDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedClassDecorator, localize_1.Localizer.Diagnostic.classDecoratorTypeUnknown(), node.decorators[i].expression);
|
@@ -11867,7 +11891,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11867
11891
|
for (let i = node.decorators.length - 1; i >= 0; i--) {
|
11868
11892
|
const decorator = node.decorators[i];
|
11869
11893
|
const newDecoratedType = applyFunctionDecorator(decoratedType, functionType, decorator, node);
|
11870
|
-
|
11894
|
+
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
11895
|
+
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
11871
11896
|
// Report this error only on the first unknown type.
|
11872
11897
|
if (!foundUnknown) {
|
11873
11898
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
@@ -15034,6 +15059,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15034
15059
|
types_1.FunctionType.hasUnannotatedParams(type) &&
|
15035
15060
|
!types_1.FunctionType.isStubDefinition(type) &&
|
15036
15061
|
!types_1.FunctionType.isPyTypedDefinition(type) &&
|
15062
|
+
!types_1.FunctionType.isWrapReturnTypeInAwait(type) &&
|
15037
15063
|
args) {
|
15038
15064
|
const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, args);
|
15039
15065
|
if (contextualReturnType) {
|
@@ -15386,10 +15412,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15386
15412
|
});
|
15387
15413
|
return isAssignable;
|
15388
15414
|
}
|
15389
|
-
|
15390
|
-
|
15391
|
-
|
15392
|
-
|
15415
|
+
// Adjusts the source type arguments list to match the length of the
|
15416
|
+
// dest type arguments list if the dest list contains an unbounded
|
15417
|
+
// or variadic entry.
|
15418
|
+
function adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs) {
|
15393
15419
|
const destVariadicIndex = destTypeArgs.findIndex((t) => (0, types_1.isVariadicTypeVar)(t.type));
|
15394
15420
|
const destUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
|
15395
15421
|
const srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
|
@@ -15437,6 +15463,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15437
15463
|
}
|
15438
15464
|
}
|
15439
15465
|
}
|
15466
|
+
}
|
15467
|
+
function assignTupleTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
15468
|
+
var _a, _b;
|
15469
|
+
const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
|
15470
|
+
const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
|
15471
|
+
let srcUnboundedIndex;
|
15472
|
+
if (flags & 2 /* ReverseTypeVarMatching */) {
|
15473
|
+
adjustSourceTupleTypeArgs(srcTypeArgs, destTypeArgs);
|
15474
|
+
srcUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
|
15475
|
+
}
|
15476
|
+
else {
|
15477
|
+
adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs);
|
15478
|
+
srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
|
15479
|
+
}
|
15440
15480
|
if (srcTypeArgs.length === destTypeArgs.length) {
|
15441
15481
|
for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
|
15442
15482
|
const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
@@ -17170,7 +17210,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17170
17210
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
|
17171
17211
|
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
|
17172
17212
|
/* typeArguments */ undefined,
|
17173
|
-
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node));
|
17213
|
+
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start);
|
17174
17214
|
let replacedTypeArg = false;
|
17175
17215
|
const newTypeArgs = assignedType.typeArguments.map((typeArg, index) => {
|
17176
17216
|
const typeParam = assignedType.details.typeParameters[index];
|
@@ -17267,25 +17307,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17267
17307
|
return validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames);
|
17268
17308
|
}
|
17269
17309
|
// For an overload overriding a base method, at least one overload
|
17270
|
-
// must be compatible with the base method.
|
17271
|
-
if (
|
17310
|
+
// or the implementation must be compatible with the base method.
|
17311
|
+
if (overrideMethod.overloads.some((overrideOverload) => {
|
17272
17312
|
return validateOverrideMethodInternal(baseMethod, overrideOverload,
|
17273
17313
|
/* diag */ undefined, enforceParamNames);
|
17274
17314
|
})) {
|
17275
17315
|
return true;
|
17276
17316
|
}
|
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
17317
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNoOverloadMatches());
|
17286
17318
|
return false;
|
17287
17319
|
}
|
17288
|
-
//
|
17320
|
+
// For a non-overloaded method overriding an overloaded method, the
|
17321
|
+
// override must match all of the overloads.
|
17322
|
+
if ((0, types_1.isFunction)(overrideMethod)) {
|
17323
|
+
return types_1.OverloadedFunctionType.getOverloads(baseMethod).every((overload) => validateOverrideMethodInternal(overload, overrideMethod, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), enforceParamNames));
|
17324
|
+
}
|
17325
|
+
// For an overloaded method overriding an overloaded method, the overrides
|
17326
|
+
// must all match and be in the correct order. It is OK if the base method
|
17327
|
+
// has additional overloads that are not present in the override.
|
17328
|
+
let previousMatchIndex = -1;
|
17329
|
+
let overrideOverloadIndex = 0;
|
17330
|
+
for (const overrideOverload of types_1.OverloadedFunctionType.getOverloads(overrideMethod)) {
|
17331
|
+
const matchIndex = types_1.OverloadedFunctionType.getOverloads(baseMethod).findIndex((baseOverload) => {
|
17332
|
+
return validateOverrideMethodInternal(baseOverload, overrideOverload,
|
17333
|
+
/* diag */ undefined, enforceParamNames);
|
17334
|
+
});
|
17335
|
+
if (matchIndex < 0) {
|
17336
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex }));
|
17337
|
+
return false;
|
17338
|
+
}
|
17339
|
+
if (matchIndex < previousMatchIndex) {
|
17340
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadOrder());
|
17341
|
+
return false;
|
17342
|
+
}
|
17343
|
+
previousMatchIndex = matchIndex;
|
17344
|
+
overrideOverloadIndex++;
|
17345
|
+
}
|
17289
17346
|
return true;
|
17290
17347
|
}
|
17291
17348
|
function validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames) {
|