@zzzen/pyright-internal 1.2.0-dev.20260906 → 1.2.0-dev.20260920
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.d.ts +2 -1
- package/dist/analyzer/checker.js +80 -5
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +10 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +7 -18
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/decorators.js +45 -2
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/program.js +1 -0
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.d.ts +0 -1
- package/dist/analyzer/sourceFileInfo.js +0 -3
- package/dist/analyzer/sourceFileInfo.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.d.ts +1 -0
- package/dist/analyzer/typeCacheUtils.js +28 -1
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +1 -1
- package/dist/analyzer/typeEvaluator.js +63 -389
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typedDicts.js +3 -7
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.js +7 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +16 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/envVarUtils.js +3 -3
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +0 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +12 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/fileSystemMapping.d.ts +1 -1
- package/dist/fileSystemMapping.js +3 -0
- package/dist/fileSystemMapping.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -1
- package/dist/languageService/completionProvider.js +4 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -0
- package/dist/localization/package.nls.de.json +1 -0
- package/dist/localization/package.nls.es.json +1 -0
- package/dist/localization/package.nls.fr.json +1 -0
- package/dist/localization/package.nls.it.json +1 -0
- package/dist/localization/package.nls.ja.json +1 -0
- package/dist/localization/package.nls.ko.json +1 -0
- package/dist/localization/package.nls.pl.json +1 -0
- package/dist/localization/package.nls.pt-br.json +1 -0
- package/dist/localization/package.nls.qps-ploc.json +1 -0
- package/dist/localization/package.nls.ru.json +1 -0
- package/dist/localization/package.nls.tr.json +1 -0
- package/dist/localization/package.nls.zh-cn.json +1 -0
- package/dist/localization/package.nls.zh-tw.json +1 -0
- 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 +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/envVarUtils.test.js +16 -0
- package/dist/tests/envVarUtils.test.js.map +1 -1
- package/dist/tests/evaluationTrace.integration.test.d.ts +1 -0
- package/dist/tests/evaluationTrace.integration.test.js +266 -0
- package/dist/tests/evaluationTrace.integration.test.js.map +1 -0
- package/dist/tests/evaluationTrace.test.d.ts +1 -0
- package/dist/tests/evaluationTrace.test.js +422 -0
- package/dist/tests/evaluationTrace.test.js.map +1 -0
- package/dist/tests/evaluationTrace.viewer.test.d.ts +1 -0
- package/dist/tests/evaluationTrace.viewer.test.js +529 -0
- package/dist/tests/evaluationTrace.viewer.test.js.map +1 -0
- package/dist/tests/fileSystemMapping.test.js +3 -0
- package/dist/tests/fileSystemMapping.test.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +1 -0
- package/dist/tests/harness/vfs/filesystem.js +3 -0
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +5 -0
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/mypyPrimerAnalysis.test.d.ts +1 -0
- package/dist/tests/mypyPrimerAnalysis.test.js +1779 -0
- package/dist/tests/mypyPrimerAnalysis.test.js.map +1 -0
- package/dist/tests/mypyPrimerMcp.test.d.ts +1 -0
- package/dist/tests/mypyPrimerMcp.test.js +186 -0
- package/dist/tests/mypyPrimerMcp.test.js.map +1 -0
- package/dist/tests/typeCacheUtils.test.js +15 -0
- package/dist/tests/typeCacheUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +2 -2
- package/dist/tests/typeEvaluator6.test.js +155 -3
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +4 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeUtils.test.js +15 -0
- package/dist/tests/typeUtils.test.js.map +1 -1
- package/dist/trace/capture.d.ts +31 -0
- package/dist/trace/capture.js +272 -0
- package/dist/trace/capture.js.map +1 -0
- package/dist/trace/cli.d.ts +1 -0
- package/dist/trace/cli.js +196 -0
- package/dist/trace/cli.js.map +1 -0
- package/dist/trace/nativeAdapter.d.ts +16 -0
- package/dist/trace/nativeAdapter.js +422 -0
- package/dist/trace/nativeAdapter.js.map +1 -0
- package/dist/trace/nativeBridge.d.ts +46 -0
- package/dist/trace/nativeBridge.js +416 -0
- package/dist/trace/nativeBridge.js.map +1 -0
- package/dist/trace/reader.d.ts +83 -0
- package/dist/trace/reader.js +296 -0
- package/dist/trace/reader.js.map +1 -0
- package/dist/trace/recorder.d.ts +59 -0
- package/dist/trace/recorder.js +303 -0
- package/dist/trace/recorder.js.map +1 -0
- package/dist/trace/runtimeLoader.d.ts +23 -0
- package/dist/trace/runtimeLoader.js +172 -0
- package/dist/trace/runtimeLoader.js.map +1 -0
- package/dist/trace/viewerAssets.d.ts +2 -0
- package/dist/trace/viewerAssets.js +76 -0
- package/dist/trace/viewerAssets.js.map +1 -0
- package/dist/trace/viewerClient.d.ts +1 -0
- package/dist/trace/viewerClient.js +485 -0
- package/dist/trace/viewerClient.js.map +1 -0
- package/dist/trace/viewerModel.d.ts +308 -0
- package/dist/trace/viewerModel.js +524 -0
- package/dist/trace/viewerModel.js.map +1 -0
- package/dist/trace/viewerServer.d.ts +7 -0
- package/dist/trace/viewerServer.js +185 -0
- package/dist/trace/viewerServer.js.map +1 -0
- package/dist/typeServer/typeServerFileSystem.d.ts +1 -0
- package/dist/typeServer/typeServerFileSystem.js +3 -0
- package/dist/typeServer/typeServerFileSystem.js.map +1 -1
- package/dist/typeServer/virtualFileOverlayFileSystem.d.ts +1 -0
- package/dist/typeServer/virtualFileOverlayFileSystem.js +3 -0
- package/dist/typeServer/virtualFileOverlayFileSystem.js.map +1 -1
- package/package.json +4 -2
|
@@ -48,7 +48,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
48
48
|
};
|
|
49
49
|
})();
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.maxCodeComplexity = void 0;
|
|
52
51
|
exports.createTypeEvaluator = createTypeEvaluator;
|
|
53
52
|
const cancellationUtils_1 = require("../common/cancellationUtils");
|
|
54
53
|
const collectionUtils_1 = require("../common/collectionUtils");
|
|
@@ -190,13 +189,9 @@ const maxTypedDeclsPerSymbol = 16;
|
|
|
190
189
|
const verifyTypeCacheEvaluatorFlags = false;
|
|
191
190
|
// This debugging option prints each expression and its evaluated type.
|
|
192
191
|
const printExpressionTypes = false;
|
|
193
|
-
// The following number is chosen somewhat arbitrarily. We need to cut
|
|
194
|
-
// off code flow analysis at some point for code flow graphs that are too
|
|
195
|
-
// complex. Otherwise we risk overflowing the stack or incurring extremely
|
|
196
|
-
// long analysis times. This number has been tuned empirically.
|
|
197
|
-
exports.maxCodeComplexity = 768;
|
|
198
192
|
function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
199
193
|
const nodeInfo = AnalyzerNodeInfo.createAnalyzerNodeInfoAccessor(evaluatorOptions.nodeInfoReader);
|
|
194
|
+
const maxCodeComplexity = evaluatorOptions.maxCodeComplexity;
|
|
200
195
|
const symbolResolutionStack = [];
|
|
201
196
|
const speculativeTypeTracker = new typeCacheUtils_1.SpeculativeTypeTracker();
|
|
202
197
|
const suppressedNodeStack = [];
|
|
@@ -292,9 +287,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
292
287
|
return typeFormTypeCache;
|
|
293
288
|
}
|
|
294
289
|
function readTypeFormTypeCacheEntry(node, expectedType) {
|
|
295
|
-
return getTypeFormTypeCache(node)
|
|
296
|
-
.get(node.id)
|
|
297
|
-
?.find((entry) => (0, typeCacheUtils_1.contextualTypeCacheEntryMatches)(entry, expectedType));
|
|
290
|
+
return (0, typeCacheUtils_1.findContextualTypeCacheEntry)(getTypeFormTypeCache(node).get(node.id), expectedType);
|
|
298
291
|
}
|
|
299
292
|
// Contextual reads consult expectedTypeCache and prefer a matching TypeForm result.
|
|
300
293
|
// Runtime-only consumers must use readTypeCacheEntry so this precedence is not
|
|
@@ -399,6 +392,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
399
392
|
function setTypeResultForNode(node, typeResult, flags = 0 /* EvalFlags.None */) {
|
|
400
393
|
writeTypeCache(node, typeResult, flags);
|
|
401
394
|
}
|
|
395
|
+
function getMaxCodeComplexity() {
|
|
396
|
+
return maxCodeComplexity;
|
|
397
|
+
}
|
|
402
398
|
function setAsymmetricDescriptorAssignment(node) {
|
|
403
399
|
if (isSpeculativeModeInUse(/* node */ undefined)) {
|
|
404
400
|
return;
|
|
@@ -2458,7 +2454,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2458
2454
|
function checkCodeFlowTooComplex(node) {
|
|
2459
2455
|
const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
2460
2456
|
const codeComplexity = nodeInfo.getCodeFlowComplexity(scopeNode);
|
|
2461
|
-
if (codeComplexity >
|
|
2457
|
+
if (codeComplexity > maxCodeComplexity) {
|
|
2462
2458
|
let errorRange = scopeNode;
|
|
2463
2459
|
if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
|
2464
2460
|
errorRange = scopeNode.d.name;
|
|
@@ -4151,7 +4147,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4151
4147
|
writeTypeCache(node.d.member, typeResult, flags);
|
|
4152
4148
|
return typeResult;
|
|
4153
4149
|
}
|
|
4154
|
-
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
|
|
4150
|
+
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags, allowFunctionSignatureAssignment = true) {
|
|
4155
4151
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
|
4156
4152
|
const memberName = node.d.member.d.value;
|
|
4157
4153
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
|
@@ -4413,6 +4409,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4413
4409
|
case 4 /* TypeCategory.Function */:
|
|
4414
4410
|
case 5 /* TypeCategory.Overloaded */: {
|
|
4415
4411
|
const hasSelf = (0, types_1.isMethodType)(baseType);
|
|
4412
|
+
const functionTypes = (0, types_1.isFunction)(baseType) ? [baseType] : types_1.OverloadedType.getOverloads(baseType);
|
|
4413
|
+
const isBuiltinsFunction = functionTypes.some((functionType) => types_1.FunctionType.isBuiltIn(functionType) && functionType.shared.moduleName === 'builtins');
|
|
4416
4414
|
if (memberName === '__self__' && hasSelf) {
|
|
4417
4415
|
// Handle "__self__" specially because MethodType defines
|
|
4418
4416
|
// it simply as "object". We can do better here.
|
|
@@ -4430,7 +4428,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4430
4428
|
}
|
|
4431
4429
|
else {
|
|
4432
4430
|
const altType = hasSelf ? prefetched?.methodClass : prefetched?.functionClass;
|
|
4433
|
-
type = getTypeOfMemberAccessWithBaseType(node, { type: altType ? (0, typeUtils_1.convertToInstance)(altType) : types_1.UnknownType.create() }, usage, flags).type;
|
|
4431
|
+
type = getTypeOfMemberAccessWithBaseType(node, { type: altType ? (0, typeUtils_1.convertToInstance)(altType) : types_1.UnknownType.create() }, usage, flags, !hasSelf && !isBuiltinsFunction).type;
|
|
4434
4432
|
}
|
|
4435
4433
|
break;
|
|
4436
4434
|
}
|
|
@@ -4442,7 +4440,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4442
4440
|
if (!type) {
|
|
4443
4441
|
const isFunctionRule = (0, types_1.isFunctionOrOverloaded)(baseType) ||
|
|
4444
4442
|
((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isBuiltIn(baseType, ['function', 'FunctionType']));
|
|
4445
|
-
|
|
4443
|
+
// These signature metadata attributes can be assigned on function objects at runtime.
|
|
4444
|
+
const isFunctionSignatureAssignment = allowFunctionSignatureAssignment &&
|
|
4445
|
+
usage.method === 'set' &&
|
|
4446
|
+
(memberName === '__signature__' || memberName === '__text_signature__') &&
|
|
4447
|
+
(0, types_1.isClassInstance)(baseType) &&
|
|
4448
|
+
types_1.ClassType.isBuiltIn(baseType, ['function', 'FunctionType']);
|
|
4449
|
+
if (!baseTypeResult.isIncomplete && !isFunctionSignatureAssignment) {
|
|
4446
4450
|
let diagMessage = localize_1.LocMessage.memberAccess();
|
|
4447
4451
|
if (usage.method === 'set') {
|
|
4448
4452
|
diagMessage = localize_1.LocMessage.memberSet();
|
|
@@ -7018,15 +7022,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7018
7022
|
const specializedInitSelfTypes = [];
|
|
7019
7023
|
let matchedOverloads = [];
|
|
7020
7024
|
let isTypeIncomplete = false;
|
|
7021
|
-
|
|
7025
|
+
let overloadsUsedForCall = [];
|
|
7022
7026
|
let isDefinitiveMatchFound = false;
|
|
7023
|
-
let hasInitSelfMaterializationAmbiguity = false;
|
|
7024
|
-
let hasEffectiveInitSelfType = false;
|
|
7025
7027
|
const speculativeNode = getSpeculativeNodeForCall(errorNode);
|
|
7026
7028
|
for (let expandedTypesIndex = 0; expandedTypesIndex < expandedArgTypes.length; expandedTypesIndex++) {
|
|
7027
|
-
const overloadsUsedStartIndex = overloadsUsedForCall.length;
|
|
7028
7029
|
let matchedOverload;
|
|
7029
|
-
let effectiveInitSelfType;
|
|
7030
7030
|
const argTypeOverride = expandedArgTypes[expandedTypesIndex];
|
|
7031
7031
|
const hasArgTypeOverride = argTypeOverride.some((a) => a !== undefined);
|
|
7032
7032
|
let possibleMatchResults = [];
|
|
@@ -7066,12 +7066,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7066
7066
|
constraints: effectiveConstraints,
|
|
7067
7067
|
returnType: callResult.returnType,
|
|
7068
7068
|
argResults: callResult.argResults ?? [],
|
|
7069
|
-
specializedInitSelfType: callResult.specializedInitSelfType,
|
|
7070
7069
|
};
|
|
7071
7070
|
matchedOverloads.push(matchedOverloadInfo);
|
|
7072
|
-
if (callResult.anyOrUnknownArg ||
|
|
7073
|
-
matchResults.unpackedArgOfUnknownLength ||
|
|
7074
|
-
possibleMatchResults.length > 0) {
|
|
7071
|
+
if (callResult.anyOrUnknownArg || matchResults.unpackedArgOfUnknownLength) {
|
|
7075
7072
|
possibleMatchResults.push(matchedOverloadInfo);
|
|
7076
7073
|
if (callResult.anyOrUnknownArg) {
|
|
7077
7074
|
if ((0, typeUtils_1.isIncompleteUnknown)(callResult.anyOrUnknownArg)) {
|
|
@@ -7081,7 +7078,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7081
7078
|
}
|
|
7082
7079
|
else {
|
|
7083
7080
|
returnTypes.push(callResult.returnType);
|
|
7084
|
-
|
|
7081
|
+
// Each definitive union branch needs its own constructed type;
|
|
7082
|
+
// __init__ return types alone cannot represent the specialization.
|
|
7083
|
+
const boundToType = overload.priv.boundToType;
|
|
7084
|
+
if (expandedArgTypes.length > 1 &&
|
|
7085
|
+
overload.shared.name === '__init__' &&
|
|
7086
|
+
boundToType &&
|
|
7087
|
+
(0, types_1.isClassInstance)(boundToType)) {
|
|
7088
|
+
specializedInitSelfTypes.push(callResult.specializedInitSelfType ??
|
|
7089
|
+
solveAndApplyConstraints(boundToType, effectiveConstraints, {
|
|
7090
|
+
replaceUnsolved: {
|
|
7091
|
+
scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(boundToType),
|
|
7092
|
+
tupleClassType: getTupleClassType(),
|
|
7093
|
+
},
|
|
7094
|
+
}));
|
|
7095
|
+
}
|
|
7085
7096
|
isDefinitiveMatchFound = true;
|
|
7086
7097
|
break;
|
|
7087
7098
|
}
|
|
@@ -7095,53 +7106,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7095
7106
|
if (!isDefinitiveMatchFound && possibleMatchResults.length > 0) {
|
|
7096
7107
|
possibleMatchResults = filterOverloadMatchesForUnpackedArgs(possibleMatchResults);
|
|
7097
7108
|
possibleMatchResults = filterOverloadMatchesForAnyArgs(possibleMatchResults);
|
|
7098
|
-
// Keep diagnostic bookkeeping aligned with the candidates that remain possible.
|
|
7099
|
-
// This applies to both top-level gradual arguments and nested materialization,
|
|
7100
|
-
// so deprecation diagnostics are reported only for retained overloads.
|
|
7101
|
-
overloadsUsedForCall.splice(overloadsUsedStartIndex, overloadsUsedForCall.length - overloadsUsedStartIndex, ...possibleMatchResults.map((result) => result.overload));
|
|
7102
7109
|
// Did the filtering produce a single result? If so, we're done.
|
|
7103
7110
|
if (possibleMatchResults.length === 1) {
|
|
7111
|
+
overloadsUsedForCall = [possibleMatchResults[0].overload];
|
|
7104
7112
|
returnTypes.push(possibleMatchResults[0].returnType);
|
|
7105
|
-
effectiveInitSelfType = getEffectiveInitSelfType(possibleMatchResults[0]);
|
|
7106
7113
|
matchedOverloads = [possibleMatchResults[0]];
|
|
7107
7114
|
}
|
|
7108
7115
|
else {
|
|
7109
|
-
const firstArgParamPairs = getOverloadArgParamPairs(possibleMatchResults[0]);
|
|
7110
|
-
let ambiguousMatchIncludesNestedAny = false;
|
|
7111
|
-
let ambiguousMatchIncludesNestedUnknown = false;
|
|
7112
|
-
let ambiguousMatchIncludesTopLevelAnyOrUnknown = false;
|
|
7113
|
-
firstArgParamPairs.forEach((pair, index) => {
|
|
7114
|
-
const paramTypes = possibleMatchResults.map((match) => {
|
|
7115
|
-
const argParamPairs = getOverloadArgParamPairs(match);
|
|
7116
|
-
return index < argParamPairs.length ? argParamPairs[index].paramType : types_1.UnknownType.create();
|
|
7117
|
-
});
|
|
7118
|
-
if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
|
|
7119
|
-
if ((0, types_1.isAnyOrUnknown)(pair.argType)) {
|
|
7120
|
-
ambiguousMatchIncludesTopLevelAnyOrUnknown = true;
|
|
7121
|
-
}
|
|
7122
|
-
else {
|
|
7123
|
-
const anyOrUnknown = getAnyOrUnknownInInvariantPosition(pair.argType);
|
|
7124
|
-
if (anyOrUnknown && (0, types_1.isAny)(anyOrUnknown)) {
|
|
7125
|
-
ambiguousMatchIncludesNestedAny = true;
|
|
7126
|
-
}
|
|
7127
|
-
else if (anyOrUnknown && (0, types_1.isUnknown)(anyOrUnknown)) {
|
|
7128
|
-
ambiguousMatchIncludesNestedUnknown = true;
|
|
7129
|
-
}
|
|
7130
|
-
}
|
|
7131
|
-
}
|
|
7132
|
-
});
|
|
7133
7116
|
// Eliminate any return types that are subsumed by other return types.
|
|
7134
7117
|
let dedupedMatchResults = [];
|
|
7135
7118
|
let dedupedResultsIncludeAny = false;
|
|
7136
|
-
const isInitSelfMaterializationAmbiguity = (ambiguousMatchIncludesNestedAny || ambiguousMatchIncludesNestedUnknown) &&
|
|
7137
|
-
possibleMatchResults.some((result) => !!result.specializedInitSelfType);
|
|
7138
7119
|
possibleMatchResults.forEach((result) => {
|
|
7139
|
-
const resultType = isInitSelfMaterializationAmbiguity
|
|
7140
|
-
? getEffectiveOverloadReturnType(result)
|
|
7141
|
-
: result.returnType;
|
|
7142
7120
|
let isSubtypeSubsumed = false;
|
|
7143
7121
|
for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
|
|
7144
|
-
if (assignType(dedupedMatchResults[dedupedIndex],
|
|
7122
|
+
if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
|
|
7145
7123
|
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(dedupedMatchResults[dedupedIndex],
|
|
7146
7124
|
/* recurse */ false);
|
|
7147
7125
|
if (!anyOrUnknown) {
|
|
@@ -7152,8 +7130,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7152
7130
|
}
|
|
7153
7131
|
break;
|
|
7154
7132
|
}
|
|
7155
|
-
else if (assignType(
|
|
7156
|
-
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(
|
|
7133
|
+
else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
|
|
7134
|
+
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(result.returnType, /* recurse */ false);
|
|
7157
7135
|
if (!anyOrUnknown) {
|
|
7158
7136
|
dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
|
|
7159
7137
|
}
|
|
@@ -7164,19 +7142,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7164
7142
|
}
|
|
7165
7143
|
}
|
|
7166
7144
|
if (!isSubtypeSubsumed) {
|
|
7167
|
-
dedupedMatchResults.push(
|
|
7145
|
+
dedupedMatchResults.push(result.returnType);
|
|
7168
7146
|
}
|
|
7169
7147
|
});
|
|
7170
7148
|
dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
|
|
7171
7149
|
const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
|
|
7172
7150
|
let returnType = combinedTypes;
|
|
7173
|
-
if (
|
|
7174
|
-
returnType = types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown);
|
|
7175
|
-
}
|
|
7176
|
-
else if (ambiguousMatchIncludesNestedAny && !ambiguousMatchIncludesTopLevelAnyOrUnknown) {
|
|
7177
|
-
returnType = types_1.AnyType.create();
|
|
7178
|
-
}
|
|
7179
|
-
else if (dedupedMatchResults.length > 1) {
|
|
7151
|
+
if (dedupedMatchResults.length > 1) {
|
|
7180
7152
|
// If one or more of the deduped types is Any or contains Any,
|
|
7181
7153
|
// we will assume that the person who defined the overload really
|
|
7182
7154
|
// wanted Any rather than Unknown. In cases where the deduped types
|
|
@@ -7189,43 +7161,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7189
7161
|
returnType = types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown);
|
|
7190
7162
|
}
|
|
7191
7163
|
}
|
|
7192
|
-
|
|
7193
|
-
// Overloaded __init__ methods normally return None. Preserve that
|
|
7194
|
-
// ordinary return as a placeholder while union-expanded calls are
|
|
7195
|
-
// combined, and carry the effective constructed types separately.
|
|
7196
|
-
// validateInitMethod consumes specializedInitSelfType to reconstruct
|
|
7197
|
-
// the constructor result after call validation is complete.
|
|
7198
|
-
effectiveInitSelfType = returnType;
|
|
7199
|
-
hasInitSelfMaterializationAmbiguity = true;
|
|
7200
|
-
returnTypes.push(possibleMatchResults[0].returnType);
|
|
7201
|
-
}
|
|
7202
|
-
else {
|
|
7203
|
-
returnTypes.push(returnType);
|
|
7204
|
-
}
|
|
7164
|
+
returnTypes.push(returnType);
|
|
7205
7165
|
}
|
|
7206
7166
|
}
|
|
7207
|
-
if (effectiveInitSelfType) {
|
|
7208
|
-
specializedInitSelfTypes.push(effectiveInitSelfType);
|
|
7209
|
-
hasEffectiveInitSelfType = true;
|
|
7210
|
-
}
|
|
7211
7167
|
if (!matchedOverload) {
|
|
7212
7168
|
return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall };
|
|
7213
7169
|
}
|
|
7214
7170
|
}
|
|
7215
|
-
// Union expansion requires one constructor handoff per expanded argument list.
|
|
7216
|
-
// Materialization ambiguity requires a combined handoff even when there is only
|
|
7217
|
-
// one argument list because multiple overload candidates contribute to its result.
|
|
7218
|
-
const shouldCombineInitSelfTypes = hasInitSelfMaterializationAmbiguity || (expandedArgTypes.length > 1 && hasEffectiveInitSelfType);
|
|
7219
7171
|
// We found a match for all of the expanded argument lists. Copy the
|
|
7220
7172
|
// resulting type var context back into the caller's type var context.
|
|
7221
|
-
//
|
|
7222
|
-
//
|
|
7173
|
+
// Constructor results for separate union branches are carried through
|
|
7174
|
+
// specializedInitSelfTypes rather than the last branch's constraints.
|
|
7223
7175
|
if (constraints && isDefinitiveMatchFound) {
|
|
7224
7176
|
constraints.copyFromClone(matchedOverloads[matchedOverloads.length - 1].constraints);
|
|
7225
7177
|
}
|
|
7226
7178
|
// And run through the first expanded argument list one more time to
|
|
7227
|
-
// populate the type cache.
|
|
7228
|
-
const finalConstraints =
|
|
7179
|
+
// populate the type cache, without applying a different branch's constraints.
|
|
7180
|
+
const finalConstraints = expandedArgTypes.length > 1
|
|
7229
7181
|
? matchedOverloads[0].constraints
|
|
7230
7182
|
: constraints ?? matchedOverloads[0].constraints;
|
|
7231
7183
|
const finalCallResult = validateArgTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalConstraints, skipUnknownArgCheck, inferenceContext);
|
|
@@ -7237,7 +7189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7237
7189
|
anyOrUnknownArg: finalCallResult.anyOrUnknownArg,
|
|
7238
7190
|
returnType: (0, types_1.combineTypes)(returnTypes),
|
|
7239
7191
|
isTypeIncomplete,
|
|
7240
|
-
specializedInitSelfType: specializedInitSelfTypes.length
|
|
7192
|
+
specializedInitSelfType: specializedInitSelfTypes.length === expandedArgTypes.length
|
|
7241
7193
|
? (0, types_1.combineTypes)(specializedInitSelfTypes)
|
|
7242
7194
|
: finalCallResult.specializedInitSelfType,
|
|
7243
7195
|
overloadsUsedForCall,
|
|
@@ -7257,303 +7209,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7257
7209
|
}
|
|
7258
7210
|
return unpackedArgsOverloads;
|
|
7259
7211
|
}
|
|
7260
|
-
// assignType cannot be used for this detection because it accepts Any and Unknown
|
|
7261
|
-
// without exposing whether acceptance depends on a gradual invariant type argument.
|
|
7262
|
-
function getAnyOrUnknownInInvariantPosition(type, recursionCount = 0) {
|
|
7263
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
7264
|
-
return undefined;
|
|
7265
|
-
}
|
|
7266
|
-
recursionCount++;
|
|
7267
|
-
let result;
|
|
7268
|
-
const addResult = (newResult) => {
|
|
7269
|
-
if (newResult) {
|
|
7270
|
-
result = result ? (0, typeUtils_1.preserveUnknown)(result, newResult) : newResult;
|
|
7271
|
-
}
|
|
7272
|
-
};
|
|
7273
|
-
if ((0, types_1.isUnion)(type)) {
|
|
7274
|
-
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
|
7275
|
-
addResult(getAnyOrUnknownInInvariantPosition(subtype, recursionCount));
|
|
7276
|
-
});
|
|
7277
|
-
return result;
|
|
7278
|
-
}
|
|
7279
|
-
if (!(0, types_1.isClass)(type)) {
|
|
7280
|
-
return undefined;
|
|
7281
|
-
}
|
|
7282
|
-
// Tuple entries are covariant, but they can contain an invariant type.
|
|
7283
|
-
if (type.priv.tupleTypeArgs) {
|
|
7284
|
-
type.priv.tupleTypeArgs.forEach((typeArg) => {
|
|
7285
|
-
addResult(getAnyOrUnknownInInvariantPosition(typeArg.type, recursionCount));
|
|
7286
|
-
});
|
|
7287
|
-
return result;
|
|
7288
|
-
}
|
|
7289
|
-
if (!type.priv.typeArgs) {
|
|
7290
|
-
return undefined;
|
|
7291
|
-
}
|
|
7292
|
-
inferVarianceForClass(type);
|
|
7293
|
-
const typeParams = types_1.ClassType.getTypeParams(type);
|
|
7294
|
-
type.priv.typeArgs.forEach((typeArg, index) => {
|
|
7295
|
-
const typeParam = index < typeParams.length ? typeParams[index] : undefined;
|
|
7296
|
-
const variance = typeParam ? types_1.TypeVarType.getVariance(typeParam) : 2 /* Variance.Invariant */;
|
|
7297
|
-
if (variance === 2 /* Variance.Invariant */) {
|
|
7298
|
-
addResult((0, typeUtils_1.containsAnyOrUnknown)(typeArg, /* recurse */ true));
|
|
7299
|
-
}
|
|
7300
|
-
else {
|
|
7301
|
-
addResult(getAnyOrUnknownInInvariantPosition(typeArg, recursionCount));
|
|
7302
|
-
}
|
|
7303
|
-
});
|
|
7304
|
-
return result;
|
|
7305
|
-
}
|
|
7306
|
-
function getEffectiveOverloadReturnType(match) {
|
|
7307
|
-
return getEffectiveInitSelfType(match) ?? match.returnType;
|
|
7308
|
-
}
|
|
7309
|
-
function getEffectiveInitSelfType(match) {
|
|
7310
|
-
if (match.specializedInitSelfType) {
|
|
7311
|
-
return match.specializedInitSelfType;
|
|
7312
|
-
}
|
|
7313
|
-
const boundToType = match.overload.priv.boundToType;
|
|
7314
|
-
if (match.overload.shared.name === '__init__' && boundToType && (0, types_1.isClassInstance)(boundToType)) {
|
|
7315
|
-
return solveAndApplyConstraints(boundToType, match.constraints, {
|
|
7316
|
-
replaceUnsolved: {
|
|
7317
|
-
scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(boundToType),
|
|
7318
|
-
tupleClassType: getTupleClassType(),
|
|
7319
|
-
},
|
|
7320
|
-
});
|
|
7321
|
-
}
|
|
7322
|
-
return undefined;
|
|
7323
|
-
}
|
|
7324
|
-
function getOverloadArgParamPairs(match) {
|
|
7325
|
-
const pairs = [];
|
|
7326
|
-
// argResults and argParams share validation order: supplied arguments in caller
|
|
7327
|
-
// order, followed by synthesized defaults. Preserve that order so the same index
|
|
7328
|
-
// across overloads represents the same supplied argument, even for keyword calls.
|
|
7329
|
-
match.argResults.forEach((argResult, index) => {
|
|
7330
|
-
const argParam = index < match.matchResults.argParams.length ? match.matchResults.argParams[index] : undefined;
|
|
7331
|
-
if (!argParam?.isDefaultArg) {
|
|
7332
|
-
pairs.push({
|
|
7333
|
-
argType: argResult.argType,
|
|
7334
|
-
paramType: argParam?.paramType ?? types_1.UnknownType.create(),
|
|
7335
|
-
});
|
|
7336
|
-
}
|
|
7337
|
-
});
|
|
7338
|
-
if (match.overload.priv.boundToType && match.overload.priv.strippedFirstParamType) {
|
|
7339
|
-
pairs.unshift({
|
|
7340
|
-
argType: match.overload.priv.boundToType,
|
|
7341
|
-
paramType: match.overload.priv.strippedFirstParamType,
|
|
7342
|
-
});
|
|
7343
|
-
}
|
|
7344
|
-
return pairs;
|
|
7345
|
-
}
|
|
7346
|
-
function combineMaterializationCoverage(results) {
|
|
7347
|
-
if (results.some((result) => result === false)) {
|
|
7348
|
-
return false;
|
|
7349
|
-
}
|
|
7350
|
-
return results.some((result) => result === undefined) ? undefined : true;
|
|
7351
|
-
}
|
|
7352
|
-
function areAllMaterializationsEquivalent(destType, srcType, recursionCount = 0) {
|
|
7353
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
7354
|
-
return undefined;
|
|
7355
|
-
}
|
|
7356
|
-
recursionCount++;
|
|
7357
|
-
if (!(0, typeUtils_1.containsAnyOrUnknown)(srcType, /* recurse */ true)) {
|
|
7358
|
-
return (0, types_1.isTypeSame)(destType, srcType, { treatAnySameAsUnknown: true });
|
|
7359
|
-
}
|
|
7360
|
-
if ((0, types_1.isAnyOrUnknown)(destType)) {
|
|
7361
|
-
return true;
|
|
7362
|
-
}
|
|
7363
|
-
if ((0, types_1.isTypeSame)(destType, srcType, { treatAnySameAsUnknown: true })) {
|
|
7364
|
-
return true;
|
|
7365
|
-
}
|
|
7366
|
-
if ((0, types_1.isTypeVar)(destType) ||
|
|
7367
|
-
(0, types_1.isUnion)(destType) ||
|
|
7368
|
-
(0, types_1.isFunction)(destType) ||
|
|
7369
|
-
(0, types_1.isOverloaded)(destType) ||
|
|
7370
|
-
((0, types_1.isClass)(destType) && types_1.ClassType.isProtocolClass(destType))) {
|
|
7371
|
-
return undefined;
|
|
7372
|
-
}
|
|
7373
|
-
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
|
7374
|
-
return false;
|
|
7375
|
-
}
|
|
7376
|
-
if ((0, types_1.isUnion)(srcType) || (0, types_1.isUnion)(destType) || (0, types_1.isFunction)(srcType) || (0, types_1.isFunction)(destType)) {
|
|
7377
|
-
return undefined;
|
|
7378
|
-
}
|
|
7379
|
-
if (!(0, types_1.isClass)(destType) || !(0, types_1.isClass)(srcType)) {
|
|
7380
|
-
return false;
|
|
7381
|
-
}
|
|
7382
|
-
if (!types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
|
7383
|
-
return false;
|
|
7384
|
-
}
|
|
7385
|
-
if (destType.priv.tupleTypeArgs || srcType.priv.tupleTypeArgs) {
|
|
7386
|
-
const destTupleTypeArgs = destType.priv.tupleTypeArgs;
|
|
7387
|
-
const srcTupleTypeArgs = srcType.priv.tupleTypeArgs;
|
|
7388
|
-
if (!destTupleTypeArgs ||
|
|
7389
|
-
!srcTupleTypeArgs ||
|
|
7390
|
-
destTupleTypeArgs.length !== srcTupleTypeArgs.length ||
|
|
7391
|
-
destTupleTypeArgs.some((destTypeArg, index) => destTypeArg.isUnbounded !== srcTupleTypeArgs[index].isUnbounded)) {
|
|
7392
|
-
return false;
|
|
7393
|
-
}
|
|
7394
|
-
return combineMaterializationCoverage(srcTupleTypeArgs.map((srcTypeArg, index) => areAllMaterializationsEquivalent(destTupleTypeArgs[index].type, srcTypeArg.type, recursionCount)));
|
|
7395
|
-
}
|
|
7396
|
-
const destTypeArgs = destType.priv.typeArgs;
|
|
7397
|
-
const srcTypeArgs = srcType.priv.typeArgs;
|
|
7398
|
-
if (!destTypeArgs || !srcTypeArgs || destTypeArgs.length !== srcTypeArgs.length) {
|
|
7399
|
-
return false;
|
|
7400
|
-
}
|
|
7401
|
-
return combineMaterializationCoverage(srcTypeArgs.map((srcTypeArg, index) => areAllMaterializationsEquivalent(destTypeArgs[index], srcTypeArg, recursionCount)));
|
|
7402
|
-
}
|
|
7403
|
-
function areAllMaterializationsAssignable(destType, srcType, recursionCount = 0) {
|
|
7404
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
7405
|
-
return undefined;
|
|
7406
|
-
}
|
|
7407
|
-
recursionCount++;
|
|
7408
|
-
if (!(0, typeUtils_1.containsAnyOrUnknown)(srcType, /* recurse */ true)) {
|
|
7409
|
-
return assignType(destType, srcType);
|
|
7410
|
-
}
|
|
7411
|
-
if ((0, types_1.isAnyOrUnknown)(destType)) {
|
|
7412
|
-
return true;
|
|
7413
|
-
}
|
|
7414
|
-
if ((0, types_1.isTypeSame)(destType, srcType, { treatAnySameAsUnknown: true })) {
|
|
7415
|
-
return true;
|
|
7416
|
-
}
|
|
7417
|
-
if ((0, types_1.isTypeVar)(destType) ||
|
|
7418
|
-
(0, types_1.isUnion)(destType) ||
|
|
7419
|
-
(0, types_1.isFunction)(destType) ||
|
|
7420
|
-
(0, types_1.isOverloaded)(destType) ||
|
|
7421
|
-
((0, types_1.isClass)(destType) && types_1.ClassType.isProtocolClass(destType))) {
|
|
7422
|
-
return undefined;
|
|
7423
|
-
}
|
|
7424
|
-
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
|
7425
|
-
return assignType(destType, getObjectType());
|
|
7426
|
-
}
|
|
7427
|
-
if ((0, types_1.isUnion)(srcType) ||
|
|
7428
|
-
(0, types_1.isUnion)(destType) ||
|
|
7429
|
-
(0, types_1.isFunction)(srcType) ||
|
|
7430
|
-
(0, types_1.isFunction)(destType) ||
|
|
7431
|
-
(0, types_1.isOverloaded)(srcType) ||
|
|
7432
|
-
(0, types_1.isOverloaded)(destType)) {
|
|
7433
|
-
return undefined;
|
|
7434
|
-
}
|
|
7435
|
-
if (!(0, types_1.isClass)(destType) || !(0, types_1.isClass)(srcType)) {
|
|
7436
|
-
return false;
|
|
7437
|
-
}
|
|
7438
|
-
if ((0, typeUtils_1.isTupleClass)(destType) && (0, typeUtils_1.isTupleClass)(srcType)) {
|
|
7439
|
-
const destTupleTypeArgs = destType.priv.tupleTypeArgs;
|
|
7440
|
-
const srcTupleTypeArgs = srcType.priv.tupleTypeArgs;
|
|
7441
|
-
if (!destTupleTypeArgs || !srcTupleTypeArgs) {
|
|
7442
|
-
return undefined;
|
|
7443
|
-
}
|
|
7444
|
-
if (destTupleTypeArgs.length === 1 && destTupleTypeArgs[0].isUnbounded) {
|
|
7445
|
-
return combineMaterializationCoverage(srcTupleTypeArgs.map((srcTypeArg) => areAllMaterializationsAssignable(destTupleTypeArgs[0].type, srcTypeArg.type, recursionCount)));
|
|
7446
|
-
}
|
|
7447
|
-
if (destTupleTypeArgs.length !== srcTupleTypeArgs.length ||
|
|
7448
|
-
destTupleTypeArgs.some((destTypeArg, index) => destTypeArg.isUnbounded !== srcTupleTypeArgs[index].isUnbounded)) {
|
|
7449
|
-
return false;
|
|
7450
|
-
}
|
|
7451
|
-
return combineMaterializationCoverage(srcTupleTypeArgs.map((srcTypeArg, index) => areAllMaterializationsAssignable(destTupleTypeArgs[index].type, srcTypeArg.type, recursionCount)));
|
|
7452
|
-
}
|
|
7453
|
-
let specializedSrcType;
|
|
7454
|
-
if (types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
|
7455
|
-
specializedSrcType = srcType;
|
|
7456
|
-
}
|
|
7457
|
-
else {
|
|
7458
|
-
const instantiableDestType = (0, types_1.isClassInstance)(destType) ? types_1.ClassType.cloneAsInstantiable(destType) : destType;
|
|
7459
|
-
const baseClass = srcType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(instantiableDestType, mroClass));
|
|
7460
|
-
if (baseClass && (0, types_1.isClass)(baseClass)) {
|
|
7461
|
-
specializedSrcType = (0, typeUtils_1.specializeForBaseClass)(srcType, baseClass);
|
|
7462
|
-
}
|
|
7463
|
-
}
|
|
7464
|
-
if (!specializedSrcType) {
|
|
7465
|
-
return types_1.ClassType.isBuiltIn(destType, 'object') ? true : undefined;
|
|
7466
|
-
}
|
|
7467
|
-
const typeParams = types_1.ClassType.getTypeParams(destType);
|
|
7468
|
-
if (typeParams.length === 0) {
|
|
7469
|
-
return true;
|
|
7470
|
-
}
|
|
7471
|
-
const destTypeArgs = destType.priv.typeArgs;
|
|
7472
|
-
const srcTypeArgs = specializedSrcType.priv.typeArgs;
|
|
7473
|
-
if (!destTypeArgs) {
|
|
7474
|
-
return true;
|
|
7475
|
-
}
|
|
7476
|
-
if (!srcTypeArgs) {
|
|
7477
|
-
return false;
|
|
7478
|
-
}
|
|
7479
|
-
inferVarianceForClass(destType);
|
|
7480
|
-
return combineMaterializationCoverage(srcTypeArgs.map((srcTypeArg, index) => {
|
|
7481
|
-
const destTypeArg = index < destTypeArgs.length ? destTypeArgs[index] : types_1.UnknownType.create();
|
|
7482
|
-
const typeParam = index < typeParams.length ? typeParams[index] : undefined;
|
|
7483
|
-
const variance = typeParam ? types_1.TypeVarType.getVariance(typeParam) : 2 /* Variance.Invariant */;
|
|
7484
|
-
if (variance === 3 /* Variance.Covariant */) {
|
|
7485
|
-
return areAllMaterializationsAssignable(destTypeArg, srcTypeArg, recursionCount);
|
|
7486
|
-
}
|
|
7487
|
-
if (variance === 2 /* Variance.Invariant */) {
|
|
7488
|
-
return areAllMaterializationsEquivalent(destTypeArg, srcTypeArg, recursionCount);
|
|
7489
|
-
}
|
|
7490
|
-
return undefined;
|
|
7491
|
-
}));
|
|
7492
|
-
}
|
|
7493
7212
|
// Determines whether multiple incompatible overloads match
|
|
7494
7213
|
// due to an Any or Unknown argument type.
|
|
7495
7214
|
function filterOverloadMatchesForAnyArgs(matches) {
|
|
7496
7215
|
if (matches.length < 2) {
|
|
7497
7216
|
return matches;
|
|
7498
7217
|
}
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
// If all of the effective return types match, select the first one.
|
|
7502
|
-
if ((0, typeUtils_1.areTypesSame)(matches.map((match) => hasInvariantAnyOrUnknownArg ? getEffectiveOverloadReturnType(match) : match.returnType), { treatAnySameAsUnknown: true })) {
|
|
7218
|
+
// If all of the return types match, select the first one.
|
|
7219
|
+
if ((0, typeUtils_1.areTypesSame)(matches.map((match) => match.returnType), { treatAnySameAsUnknown: true })) {
|
|
7503
7220
|
return [matches[0]];
|
|
7504
7221
|
}
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
if (hasInvariantAnyOrUnknownArg) {
|
|
7509
|
-
let materializationCheckSupported = true;
|
|
7510
|
-
for (let matchIndex = 0; matchIndex < matches.length; matchIndex++) {
|
|
7511
|
-
const argParamPairs = getOverloadArgParamPairs(matches[matchIndex]);
|
|
7512
|
-
const coverage = argParamPairs.length === firstArgParamPairs.length
|
|
7513
|
-
? combineMaterializationCoverage(argParamPairs.map((pair, index) => {
|
|
7514
|
-
const argType = firstArgParamPairs[index].argType;
|
|
7515
|
-
return areAllMaterializationsAssignable(pair.paramType, argType);
|
|
7516
|
-
}))
|
|
7517
|
-
: false;
|
|
7518
|
-
if (coverage === undefined) {
|
|
7519
|
-
materializationCheckSupported = false;
|
|
7520
|
-
break;
|
|
7521
|
-
}
|
|
7522
|
-
if (coverage) {
|
|
7523
|
-
matches = matches.slice(0, matchIndex + 1);
|
|
7524
|
-
break;
|
|
7525
|
-
}
|
|
7526
|
-
}
|
|
7527
|
-
if (materializationCheckSupported) {
|
|
7528
|
-
if (matches.length < 2) {
|
|
7529
|
-
return matches;
|
|
7530
|
-
}
|
|
7531
|
-
if ((0, typeUtils_1.areTypesSame)(matches.map((match) => getEffectiveOverloadReturnType(match)), { treatAnySameAsUnknown: true })) {
|
|
7532
|
-
return [matches[0]];
|
|
7533
|
-
}
|
|
7534
|
-
firstArgParamPairs = getOverloadArgParamPairs(matches[0]);
|
|
7535
|
-
for (let i = 0; i < firstArgParamPairs.length; i++) {
|
|
7536
|
-
if (getAnyOrUnknownInInvariantPosition(firstArgParamPairs[i].argType)) {
|
|
7537
|
-
const paramTypes = matches.map((match) => {
|
|
7538
|
-
const argParamPairs = getOverloadArgParamPairs(match);
|
|
7539
|
-
return i < argParamPairs.length ? argParamPairs[i].paramType : types_1.UnknownType.create();
|
|
7540
|
-
});
|
|
7541
|
-
if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
|
|
7542
|
-
return matches;
|
|
7543
|
-
}
|
|
7544
|
-
}
|
|
7545
|
-
}
|
|
7546
|
-
}
|
|
7222
|
+
const firstArgResults = matches[0].argResults;
|
|
7223
|
+
if (!firstArgResults) {
|
|
7224
|
+
return matches;
|
|
7547
7225
|
}
|
|
7548
7226
|
let foundAmbiguousAnyArg = false;
|
|
7549
|
-
for (let i = 0; i <
|
|
7227
|
+
for (let i = 0; i < firstArgResults.length; i++) {
|
|
7550
7228
|
// If the arg is Any or Unknown, see if the corresponding
|
|
7551
7229
|
// parameter types differ in any way.
|
|
7552
|
-
if ((0, types_1.isAnyOrUnknown)(
|
|
7553
|
-
const paramTypes = matches.map((match) =>
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
});
|
|
7230
|
+
if ((0, types_1.isAnyOrUnknown)(firstArgResults[i].argType)) {
|
|
7231
|
+
const paramTypes = matches.map((match) => i < match.matchResults.argParams.length
|
|
7232
|
+
? match.matchResults.argParams[i].paramType
|
|
7233
|
+
: types_1.UnknownType.create());
|
|
7557
7234
|
if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
|
|
7558
7235
|
foundAmbiguousAnyArg = true;
|
|
7559
7236
|
}
|
|
@@ -7564,8 +7241,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7564
7241
|
// that one of the arguments is an unpacked iterator, and it maps to
|
|
7565
7242
|
// an indeterminate number of parameters, which means that the overload
|
|
7566
7243
|
// selection is ambiguous.
|
|
7567
|
-
if (foundAmbiguousAnyArg ||
|
|
7568
|
-
matches.some((match) => getOverloadArgParamPairs(match).length !== firstArgParamPairs.length)) {
|
|
7244
|
+
if (foundAmbiguousAnyArg || matches.some((match) => match.argResults.length !== firstArgResults.length)) {
|
|
7569
7245
|
return matches;
|
|
7570
7246
|
}
|
|
7571
7247
|
return [matches[0]];
|
|
@@ -9341,9 +9017,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9341
9017
|
let argumentErrors = false;
|
|
9342
9018
|
let argumentMatchScore = 0;
|
|
9343
9019
|
let specializedInitSelfType;
|
|
9344
|
-
let anyOrUnknownArg
|
|
9345
|
-
? getAnyOrUnknownInInvariantPosition(type.priv.boundToType)
|
|
9346
|
-
: undefined;
|
|
9020
|
+
let anyOrUnknownArg;
|
|
9347
9021
|
const speculativeNode = getSpeculativeNodeForCall(errorNode);
|
|
9348
9022
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
|
9349
9023
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
|
@@ -9441,11 +9115,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9441
9115
|
if (argResult.condition) {
|
|
9442
9116
|
condition = types_1.TypeCondition.combine(condition, argResult.condition) ?? [];
|
|
9443
9117
|
}
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
anyOrUnknownArg = anyOrUnknownArg ? (0, typeUtils_1.preserveUnknown)(argAnyOrUnknown, anyOrUnknownArg) : argAnyOrUnknown;
|
|
9118
|
+
if ((0, types_1.isAnyOrUnknown)(argResult.argType)) {
|
|
9119
|
+
anyOrUnknownArg = anyOrUnknownArg
|
|
9120
|
+
? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArg)
|
|
9121
|
+
: argResult.argType;
|
|
9449
9122
|
}
|
|
9450
9123
|
if (paramSpec) {
|
|
9451
9124
|
if (argParam.argument.argCategory === 1 /* ArgCategory.UnpackedList */) {
|
|
@@ -21746,6 +21419,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21746
21419
|
useSpeculativeMode,
|
|
21747
21420
|
isSpeculativeModeInUse,
|
|
21748
21421
|
setTypeResultForNode,
|
|
21422
|
+
getMaxCodeComplexity,
|
|
21749
21423
|
checkForCancellation,
|
|
21750
21424
|
printControlFlowGraph,
|
|
21751
21425
|
};
|