@zzzen/pyright-internal 1.2.0-dev.20230402 → 1.2.0-dev.20230416
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/binder.d.ts +8 -0
- package/dist/analyzer/binder.js +46 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +14 -0
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +5 -0
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +112 -49
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +2 -1
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +114 -55
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +9 -4
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -0
- package/dist/analyzer/program.js +104 -17
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/service.js +5 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +1 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +1 -1
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.js +25 -1
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +197 -119
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +4 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +21 -18
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +11 -0
- package/dist/analyzer/typeUtils.js +129 -59
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +40 -6
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -1
- package/dist/analyzer/types.js +20 -2
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -1
- package/dist/common/configOptions.js +4 -4
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/fullAccessHost.d.ts +2 -1
- package/dist/common/fullAccessHost.js +11 -1
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.d.ts +3 -2
- package/dist/common/host.js +1 -1
- package/dist/common/host.js.map +1 -1
- package/dist/common/positionUtils.d.ts +2 -1
- package/dist/common/positionUtils.js +18 -12
- package/dist/common/positionUtils.js.map +1 -1
- package/dist/languageServerBase.js +1 -1
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +1 -1
- package/dist/languageService/autoImporter.js +2 -4
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +144 -87
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +11 -3
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +5 -2
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -0
- package/dist/languageService/hoverProvider.js +66 -45
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.js +8 -3
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/insertionPointUtils.js +4 -3
- package/dist/languageService/insertionPointUtils.js.map +1 -1
- package/dist/pyright.js +1 -2
- package/dist/pyright.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +27 -0
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/completions.test.js +241 -3
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/testHost.js +1 -1
- package/dist/tests/harness/testHost.js.map +1 -1
- package/dist/tests/harness/vfs/factory.js +2 -2
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +26 -25
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +6 -0
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/indentationUtils.reindent.test.js +19 -0
- package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
- package/dist/tests/insertionPointUtils.test.js +13 -0
- package/dist/tests/insertionPointUtils.test.js.map +1 -1
- package/dist/tests/moveSymbol.insertion.test.js +45 -3
- package/dist/tests/moveSymbol.insertion.test.js.map +1 -1
- package/dist/tests/positionUtils.test.d.ts +1 -0
- package/dist/tests/positionUtils.test.js +48 -0
- package/dist/tests/positionUtils.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +14 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +20 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +9 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +5 -0
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/workspaceFactory.js +5 -5
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -254,6 +254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
254
254
|
let dictClassType;
|
255
255
|
let typedDictClassType;
|
256
256
|
let typedDictPrivateClassType;
|
257
|
+
let mappingType;
|
257
258
|
let printExpressionSpaceCount = 0;
|
258
259
|
let incompleteGenerationCount = 0;
|
259
260
|
const returnTypeInferenceContextStack = [];
|
@@ -503,6 +504,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
503
504
|
dictClassType = getBuiltInType(node, 'dict');
|
504
505
|
typedDictClassType = getTypingType(node, 'TypedDict');
|
505
506
|
typedDictPrivateClassType = getTypingType(node, '_TypedDict');
|
507
|
+
mappingType = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
508
|
+
if (!mappingType) {
|
509
|
+
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
510
|
+
mappingType = getTypingType(node, 'Mapping');
|
511
|
+
}
|
506
512
|
}
|
507
513
|
}
|
508
514
|
function getTypeOfExpression(node, flags = 0 /* None */, inferenceContext) {
|
@@ -2272,11 +2278,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2272
2278
|
const sourceEntryTypes = tupleType.tupleTypeArguments.map((t) => (0, typeUtils_1.addConditionToType)(t.type, (0, typeUtils_1.getTypeCondition)(subtype)));
|
2273
2279
|
const unboundedIndex = tupleType.tupleTypeArguments.findIndex((t) => t.isUnbounded);
|
2274
2280
|
if (unboundedIndex >= 0) {
|
2275
|
-
if (sourceEntryTypes.length
|
2276
|
-
// Splice out the unbounded since it might be zero length.
|
2277
|
-
sourceEntryTypes.splice(unboundedIndex, 1);
|
2278
|
-
}
|
2279
|
-
else if (sourceEntryTypes.length < targetTypes.length) {
|
2281
|
+
if (sourceEntryTypes.length < targetTypes.length) {
|
2280
2282
|
const typeToReplicate = sourceEntryTypes.length > 0 ? sourceEntryTypes[unboundedIndex] : types_1.AnyType.create();
|
2281
2283
|
// Add elements to make the count match the target count.
|
2282
2284
|
while (sourceEntryTypes.length < targetTypes.length) {
|
@@ -5293,7 +5295,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5293
5295
|
}
|
5294
5296
|
function getTypeOfCall(node, inferenceContext, flags) {
|
5295
5297
|
var _a;
|
5296
|
-
|
5298
|
+
let baseTypeResult;
|
5299
|
+
// Handle immediate calls of lambdas specially.
|
5300
|
+
if (node.leftExpression.nodeType === 30 /* Lambda */) {
|
5301
|
+
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5302
|
+
}
|
5303
|
+
else {
|
5304
|
+
baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
5305
|
+
}
|
5297
5306
|
const argList = node.arguments.map((arg) => {
|
5298
5307
|
const functionArg = {
|
5299
5308
|
valueExpression: arg.valueExpression,
|
@@ -5384,6 +5393,57 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5384
5393
|
}
|
5385
5394
|
return typeResult;
|
5386
5395
|
}
|
5396
|
+
// This function is used in cases where a lambda is defined and immediately
|
5397
|
+
// called. In this case, we can't use normal bidirectional type inference
|
5398
|
+
// to determine the lambda's type. It needs to be inferred from the argument
|
5399
|
+
// types instead.
|
5400
|
+
function getTypeOfLambdaForCall(node, inferenceContext) {
|
5401
|
+
(0, debug_1.assert)(node.leftExpression.nodeType === 30 /* Lambda */);
|
5402
|
+
const expectedType = types_1.FunctionType.createSynthesizedInstance('');
|
5403
|
+
expectedType.details.declaredReturnType = inferenceContext
|
5404
|
+
? inferenceContext.expectedType
|
5405
|
+
: types_1.UnknownType.create();
|
5406
|
+
let isArgTypeIncomplete = false;
|
5407
|
+
node.arguments.forEach((arg, index) => {
|
5408
|
+
const argTypeResult = getTypeOfExpression(arg.valueExpression);
|
5409
|
+
if (argTypeResult.isIncomplete) {
|
5410
|
+
isArgTypeIncomplete = true;
|
5411
|
+
}
|
5412
|
+
types_1.FunctionType.addParameter(expectedType, {
|
5413
|
+
category: 0 /* Simple */,
|
5414
|
+
name: `p${index.toString()}`,
|
5415
|
+
type: argTypeResult.type,
|
5416
|
+
hasDeclaredType: true,
|
5417
|
+
});
|
5418
|
+
});
|
5419
|
+
// If the lambda's param list ends with a "/" positional parameter separator,
|
5420
|
+
// add a corresponding separator to the expected type.
|
5421
|
+
const lambdaParams = node.leftExpression.parameters;
|
5422
|
+
if (lambdaParams.length > 0) {
|
5423
|
+
const lastParam = lambdaParams[lambdaParams.length - 1];
|
5424
|
+
if (lastParam.category === 0 /* Simple */ && !lastParam.name) {
|
5425
|
+
types_1.FunctionType.addParameter(expectedType, {
|
5426
|
+
category: 0 /* Simple */,
|
5427
|
+
name: '',
|
5428
|
+
type: types_1.UnknownType.create(),
|
5429
|
+
});
|
5430
|
+
}
|
5431
|
+
}
|
5432
|
+
function getLambdaType() {
|
5433
|
+
return getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5434
|
+
}
|
5435
|
+
// If one or more of the arguments are incomplete, use speculative mode
|
5436
|
+
// for the lambda evaluation because it may need to be reevaluated once
|
5437
|
+
// the arg types are complete.
|
5438
|
+
let typeResult = isArgTypeIncomplete || speculativeTypeTracker.isSpeculative(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
|
5439
|
+
? useSpeculativeMode(node.leftExpression, getLambdaType)
|
5440
|
+
: getLambdaType();
|
5441
|
+
// If bidirectional type inference failed, use normal type inference instead.
|
5442
|
+
if (typeResult.typeErrors) {
|
5443
|
+
typeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
5444
|
+
}
|
5445
|
+
return typeResult;
|
5446
|
+
}
|
5387
5447
|
function getTypeOfAssertType(node, inferenceContext) {
|
5388
5448
|
if (node.arguments.length !== 2 ||
|
5389
5449
|
node.arguments[0].argumentCategory !== 0 /* Simple */ ||
|
@@ -5660,6 +5720,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5660
5720
|
const argTypeOverride = expandedArgTypes[expandedTypesIndex];
|
5661
5721
|
const hasArgTypeOverride = argTypeOverride.some((a) => a !== undefined);
|
5662
5722
|
let possibleMatchResults = [];
|
5723
|
+
let possibleMatchInvolvesIncompleteUnknown = false;
|
5663
5724
|
isDefinitiveMatchFound = false;
|
5664
5725
|
for (let overloadIndex = 0; overloadIndex < argParamMatches.length; overloadIndex++) {
|
5665
5726
|
const overload = argParamMatches[overloadIndex].overload;
|
@@ -5707,8 +5768,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5707
5768
|
argResults: (_b = callResult.argResults) !== null && _b !== void 0 ? _b : [],
|
5708
5769
|
};
|
5709
5770
|
matchedOverloads.push(matchedOverloadInfo);
|
5710
|
-
if (callResult.
|
5771
|
+
if (callResult.anyOrUnknownArgument) {
|
5711
5772
|
possibleMatchResults.push(matchedOverloadInfo);
|
5773
|
+
if ((0, typeUtils_1.isIncompleteUnknown)(callResult.anyOrUnknownArgument)) {
|
5774
|
+
possibleMatchInvolvesIncompleteUnknown = true;
|
5775
|
+
}
|
5712
5776
|
}
|
5713
5777
|
else {
|
5714
5778
|
returnTypes.push(callResult.returnType);
|
@@ -5750,7 +5814,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5750
5814
|
});
|
5751
5815
|
dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
|
5752
5816
|
const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
|
5753
|
-
returnTypes.push(dedupedMatchResults.length > 1
|
5817
|
+
returnTypes.push(dedupedMatchResults.length > 1
|
5818
|
+
? types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown)
|
5819
|
+
: combinedTypes);
|
5754
5820
|
}
|
5755
5821
|
}
|
5756
5822
|
if (!matchedOverload) {
|
@@ -5775,7 +5841,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5775
5841
|
}
|
5776
5842
|
return {
|
5777
5843
|
argumentErrors: finalCallResult.argumentErrors,
|
5778
|
-
|
5844
|
+
anyOrUnknownArgument: finalCallResult.anyOrUnknownArgument,
|
5779
5845
|
returnType: (0, types_1.combineTypes)(returnTypes),
|
5780
5846
|
isTypeIncomplete,
|
5781
5847
|
specializedInitSelfType: finalCallResult.specializedInitSelfType,
|
@@ -6031,7 +6097,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6031
6097
|
// one or more analyzes with no errors, use those results.
|
6032
6098
|
if (inferenceContext) {
|
6033
6099
|
const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
|
6034
|
-
if (expectedCallResult) {
|
6100
|
+
if (expectedCallResult && !expectedCallResult.argumentErrors) {
|
6035
6101
|
returnType = expectedCallResult.returnType;
|
6036
6102
|
if (expectedCallResult.isTypeIncomplete) {
|
6037
6103
|
isTypeIncomplete = true;
|
@@ -6093,12 +6159,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6093
6159
|
}
|
6094
6160
|
if (constructorMethodInfo && !skipConstructorCheck(constructorMethodInfo.type)) {
|
6095
6161
|
const constructorMethodType = constructorMethodInfo.type;
|
6162
|
+
let newReturnType;
|
6096
6163
|
// If there is an expected type that was not applied above when
|
6097
6164
|
// handling the __init__ method, try to apply it with the __new__ method.
|
6098
6165
|
if (inferenceContext && !returnType) {
|
6099
6166
|
const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
|
6100
|
-
if (expectedCallResult) {
|
6101
|
-
|
6167
|
+
if (expectedCallResult && !expectedCallResult.argumentErrors) {
|
6168
|
+
newReturnType = expectedCallResult.returnType;
|
6169
|
+
returnType = newReturnType;
|
6102
6170
|
if (expectedCallResult.isTypeIncomplete) {
|
6103
6171
|
isTypeIncomplete = true;
|
6104
6172
|
}
|
@@ -6128,8 +6196,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6128
6196
|
if (callResult.argumentErrors) {
|
6129
6197
|
reportedErrors = true;
|
6130
6198
|
}
|
6131
|
-
else {
|
6132
|
-
|
6199
|
+
else if (!newReturnType) {
|
6200
|
+
newReturnType = callResult.returnType;
|
6133
6201
|
// If the constructor returned an object whose type matches the class of
|
6134
6202
|
// the original type being constructed, use the return type in case it was
|
6135
6203
|
// specialized. If it doesn't match, we'll fall back on the assumption that
|
@@ -6524,7 +6592,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6524
6592
|
return types_1.AnyType.create();
|
6525
6593
|
}
|
6526
6594
|
if ((0, types_1.isClass)(unexpandedSubtype) && (0, enums_1.isKnownEnumType)(className)) {
|
6527
|
-
return (_d = (0, enums_1.createEnumType)(errorNode, expandedSubtype, argList)) !== null && _d !== void 0 ? _d : types_1.UnknownType.create();
|
6595
|
+
return ((_d = (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedSubtype, argList)) !== null && _d !== void 0 ? _d : types_1.UnknownType.create());
|
6528
6596
|
}
|
6529
6597
|
if (className === 'TypedDict') {
|
6530
6598
|
return (0, typedDicts_1.createTypedDictType)(evaluatorInterface, errorNode, expandedSubtype, argList);
|
@@ -7194,10 +7262,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7194
7262
|
}
|
7195
7263
|
}
|
7196
7264
|
else {
|
7197
|
-
let mappingType = getTypeshedType(errorNode, 'SupportsKeysAndGetItem');
|
7198
|
-
if (!mappingType) {
|
7199
|
-
mappingType = getTypingType(errorNode, 'Mapping');
|
7200
|
-
}
|
7201
7265
|
const strObjType = getBuiltInObject(errorNode, 'str');
|
7202
7266
|
if (mappingType &&
|
7203
7267
|
(0, types_1.isInstantiableClass)(mappingType) &&
|
@@ -7575,7 +7639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7575
7639
|
let isTypeIncomplete = matchResults.isTypeIncomplete;
|
7576
7640
|
let argumentErrors = false;
|
7577
7641
|
let specializedInitSelfType;
|
7578
|
-
let
|
7642
|
+
let anyOrUnknownArgument;
|
7579
7643
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
7580
7644
|
if (type.boundTypeVarScopeId) {
|
7581
7645
|
// If the function was bound to a class or object and was a constructor, a
|
@@ -7632,28 +7696,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7632
7696
|
// where more than two passes are needed.
|
7633
7697
|
let passCount = Math.min(typeVarMatchingCount, 2);
|
7634
7698
|
for (let i = 0; i < passCount; i++) {
|
7699
|
+
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7635
7700
|
useSpeculativeMode(errorNode, () => {
|
7636
7701
|
matchResults.argParams.forEach((argParam) => {
|
7637
|
-
if (argParam.requiresTypeVarMatching) {
|
7638
|
-
|
7639
|
-
|
7640
|
-
|
7641
|
-
|
7642
|
-
|
7643
|
-
|
7644
|
-
|
7645
|
-
|
7646
|
-
|
7647
|
-
|
7648
|
-
|
7649
|
-
|
7650
|
-
|
7651
|
-
|
7652
|
-
|
7653
|
-
|
7654
|
-
|
7655
|
-
|
7656
|
-
|
7702
|
+
if (!argParam.requiresTypeVarMatching) {
|
7703
|
+
return;
|
7704
|
+
}
|
7705
|
+
// Populate the typeVarContext for the argument. If the argument
|
7706
|
+
// is an overload function, skip it during the first pass
|
7707
|
+
// because the selection of the proper overload may depend
|
7708
|
+
// on type arguments supplied by other function arguments.
|
7709
|
+
// Set useNarrowBoundOnly to true the first time through
|
7710
|
+
// the loop if we're going to go through the loop multiple
|
7711
|
+
// times.
|
7712
|
+
const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
|
7713
|
+
/* skipOverloadArg */ i === 0,
|
7714
|
+
/* isFirstPass */ passCount > 1 && i === 0, typeCondition);
|
7715
|
+
if (argResult.isTypeIncomplete) {
|
7716
|
+
isTypeIncomplete = true;
|
7717
|
+
}
|
7718
|
+
// If we skipped a overload arg during the first pass,
|
7719
|
+
// add another pass to ensure that we handle all of the
|
7720
|
+
// type variables.
|
7721
|
+
if (i === 0 && argResult.skippedOverloadArg) {
|
7722
|
+
passCount++;
|
7657
7723
|
}
|
7658
7724
|
});
|
7659
7725
|
});
|
@@ -7666,11 +7732,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7666
7732
|
let sawParamSpecKwargs = false;
|
7667
7733
|
let condition = [];
|
7668
7734
|
const argResults = [];
|
7735
|
+
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7669
7736
|
matchResults.argParams.forEach((argParam) => {
|
7670
7737
|
var _a;
|
7671
|
-
const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
|
7738
|
+
const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
|
7672
7739
|
/* skipOverloadArg */ false,
|
7673
|
-
/*
|
7740
|
+
/* isFirstPass */ false, typeCondition);
|
7674
7741
|
argResults.push(argResult);
|
7675
7742
|
if (!argResult.isCompatible) {
|
7676
7743
|
argumentErrors = true;
|
@@ -7682,7 +7749,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7682
7749
|
condition = (_a = types_1.TypeCondition.combine(condition, argResult.condition)) !== null && _a !== void 0 ? _a : [];
|
7683
7750
|
}
|
7684
7751
|
if ((0, types_1.isAnyOrUnknown)(argResult.argType)) {
|
7685
|
-
|
7752
|
+
anyOrUnknownArgument = anyOrUnknownArgument
|
7753
|
+
? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArgument)
|
7754
|
+
: argResult.argType;
|
7686
7755
|
}
|
7687
7756
|
if (type.details.paramSpec) {
|
7688
7757
|
if (argParam.argument.argumentCategory === 1 /* UnpackedList */) {
|
@@ -7800,7 +7869,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7800
7869
|
return {
|
7801
7870
|
argumentErrors,
|
7802
7871
|
argResults,
|
7803
|
-
|
7872
|
+
anyOrUnknownArgument,
|
7804
7873
|
returnType: specializedReturnType,
|
7805
7874
|
isTypeIncomplete,
|
7806
7875
|
activeParam: matchResults.activeParam,
|
@@ -7808,19 +7877,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7808
7877
|
overloadsUsedForCall: argumentErrors ? [] : [type],
|
7809
7878
|
};
|
7810
7879
|
}
|
7811
|
-
function adjustCallableReturnType(
|
7880
|
+
function adjustCallableReturnType(returnType) {
|
7812
7881
|
// If the return type includes a generic Callable type, set the type var
|
7813
7882
|
// scope to a wildcard to allow these type vars to be solved. This won't
|
7814
7883
|
// work with overloads or unions of callables. It's intended for a
|
7815
7884
|
// specific use case. We may need to make this more sophisticated in
|
7816
7885
|
// the future.
|
7817
|
-
if ((0, types_1.isFunction)(
|
7818
|
-
|
7819
|
-
...type.details,
|
7820
|
-
typeVarScopeId: types_1.WildcardTypeVarScopeId,
|
7821
|
-
};
|
7886
|
+
if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
|
7887
|
+
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, types_1.WildcardTypeVarScopeId);
|
7822
7888
|
}
|
7823
|
-
return
|
7889
|
+
return returnType;
|
7824
7890
|
}
|
7825
7891
|
// Tries to assign the call arguments to the function parameter
|
7826
7892
|
// list and reports any mismatches in types or counts. Returns the
|
@@ -7891,6 +7957,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7891
7957
|
}
|
7892
7958
|
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* VarArgList */);
|
7893
7959
|
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* VarArgDictionary */);
|
7960
|
+
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7894
7961
|
argList.forEach((arg) => {
|
7895
7962
|
var _a;
|
7896
7963
|
if (arg.argumentCategory === 0 /* Simple */) {
|
@@ -7937,11 +8004,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7937
8004
|
requiresTypeVarMatching: false,
|
7938
8005
|
argument: arg,
|
7939
8006
|
errorNode: arg.valueExpression || errorNode,
|
7940
|
-
}, srcTypeVarContext,
|
8007
|
+
}, srcTypeVarContext, signatureTracker,
|
7941
8008
|
/* functionType */ undefined,
|
7942
8009
|
/* skipUnknownArgCheck */ false,
|
7943
8010
|
/* skipOverloadArg */ false,
|
7944
|
-
/*
|
8011
|
+
/* isFirstPass */ false, conditionFilter);
|
7945
8012
|
if (!argResult.isCompatible) {
|
7946
8013
|
reportedArgError = true;
|
7947
8014
|
}
|
@@ -7973,7 +8040,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7973
8040
|
}
|
7974
8041
|
return !reportedArgError;
|
7975
8042
|
}
|
7976
|
-
function validateArgType(argParam, typeVarContext, typeResult, skipUnknownCheck, skipOverloadArg,
|
8043
|
+
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, skipUnknownCheck, skipOverloadArg, isFirstPass, conditionFilter) {
|
7977
8044
|
var _a;
|
7978
8045
|
let argType;
|
7979
8046
|
let expectedTypeDiag;
|
@@ -7982,16 +8049,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7982
8049
|
const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
|
7983
8050
|
if (argParam.argument.valueExpression) {
|
7984
8051
|
// If the param type is a "bare" TypeVar, don't use it as an expected
|
7985
|
-
// type. This causes problems for cases where the the
|
7986
|
-
// result can influence the type of the TypeVar, such as in
|
8052
|
+
// type during the first pass. This causes problems for cases where the the
|
8053
|
+
// call expression result can influence the type of the TypeVar, such as in
|
7987
8054
|
// the expression "min(1, max(2, 0.5))". We set useNarrowBoundOnly
|
7988
8055
|
// to true if this is the first pass through the parameter list because
|
7989
8056
|
// a wide bound on a TypeVar (if a narrow bound has not yet been established)
|
7990
8057
|
// will unnecessarily constrain the expected type.
|
7991
8058
|
let expectedType;
|
7992
|
-
if (!
|
8059
|
+
if (!isFirstPass ||
|
8060
|
+
!(0, types_1.isTypeVar)(argParam.paramType) ||
|
7993
8061
|
argParam.paramType.scopeId !== (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId)) {
|
7994
|
-
expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, {
|
8062
|
+
expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, {
|
8063
|
+
useNarrowBoundOnly: isFirstPass,
|
8064
|
+
});
|
7995
8065
|
}
|
7996
8066
|
// If the expected type is unknown, don't use an expected type. Instead,
|
7997
8067
|
// use default rules for evaluating the expression type.
|
@@ -8046,6 +8116,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8046
8116
|
}
|
8047
8117
|
}
|
8048
8118
|
}
|
8119
|
+
// If the type includes multiple instances of a generic function
|
8120
|
+
// signature, force the type arguments for the duplicates to have
|
8121
|
+
// unique names.
|
8122
|
+
argType = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(argType, signatureTracker);
|
8049
8123
|
// If we're assigning to a var arg dictionary with a TypeVar type,
|
8050
8124
|
// strip literals before performing the assignment. This is used in
|
8051
8125
|
// places like a dict constructor.
|
@@ -9515,13 +9589,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9515
9589
|
addUnknown = false;
|
9516
9590
|
}
|
9517
9591
|
else if (entryNode.nodeType === 16 /* DictionaryExpandEntry */) {
|
9518
|
-
// Verify that the type supports the `keys` and `__getitem__` methods.
|
9519
|
-
// This protocol is defined in the _typeshed stub. If we can't find
|
9520
|
-
// it there, fall back on typing.Mapping.
|
9521
|
-
let mappingType = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
9522
|
-
if (!mappingType) {
|
9523
|
-
mappingType = getTypingType(node, 'Mapping');
|
9524
|
-
}
|
9525
9592
|
let expectedType;
|
9526
9593
|
if (expectedKeyType && expectedValueType) {
|
9527
9594
|
if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
|
@@ -9553,29 +9620,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9553
9620
|
addUnknown = false;
|
9554
9621
|
}
|
9555
9622
|
}
|
9556
|
-
else {
|
9557
|
-
|
9558
|
-
|
9559
|
-
|
9560
|
-
|
9561
|
-
|
9562
|
-
|
9563
|
-
|
9564
|
-
|
9565
|
-
|
9566
|
-
|
9567
|
-
if (
|
9568
|
-
|
9569
|
-
|
9570
|
-
valueTypes.push({ node: entryNode, type: typeArgs[1] });
|
9571
|
-
}
|
9572
|
-
addUnknown = false;
|
9623
|
+
else if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
|
9624
|
+
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingType));
|
9625
|
+
// Self-specialize the class.
|
9626
|
+
mappingType = types_1.ClassType.cloneForSpecialization(mappingType, mappingType.details.typeParameters,
|
9627
|
+
/* isTypeArgumentExplicit */ true);
|
9628
|
+
if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
|
9629
|
+
/* diag */ undefined, mappingTypeVarContext,
|
9630
|
+
/* srcTypeVarContext */ undefined, 128 /* RetainLiteralsForTypeVar */)) {
|
9631
|
+
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingType, mappingTypeVarContext);
|
9632
|
+
const typeArgs = specializedMapping.typeArguments;
|
9633
|
+
if (typeArgs && typeArgs.length >= 2) {
|
9634
|
+
if (forceStrictInference || index < maxEntriesToUseForInference) {
|
9635
|
+
keyTypes.push({ node: entryNode, type: typeArgs[0] });
|
9636
|
+
valueTypes.push({ node: entryNode, type: typeArgs[1] });
|
9573
9637
|
}
|
9638
|
+
addUnknown = false;
|
9574
9639
|
}
|
9575
|
-
|
9576
|
-
|
9577
|
-
|
9578
|
-
|
9640
|
+
}
|
9641
|
+
else {
|
9642
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
9643
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictUnpackIsNotMapping(), entryNode);
|
9579
9644
|
}
|
9580
9645
|
}
|
9581
9646
|
}
|
@@ -9924,8 +9989,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9924
9989
|
});
|
9925
9990
|
// Determine the minimum number of parameters that are required to
|
9926
9991
|
// satisfy the lambda.
|
9927
|
-
const minLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && param.defaultValue === undefined).length;
|
9928
|
-
const maxLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */).length;
|
9992
|
+
const minLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && !!param.name && param.defaultValue === undefined).length;
|
9993
|
+
const maxLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && !!param.name).length;
|
9929
9994
|
// Remove any expected subtypes that don't satisfy the minimum
|
9930
9995
|
// parameter count requirement.
|
9931
9996
|
expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
|
@@ -12161,6 +12226,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12161
12226
|
}
|
12162
12227
|
argList.forEach((arg) => {
|
12163
12228
|
var _a, _b, _c;
|
12229
|
+
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
12164
12230
|
if (arg.argumentCategory === 0 /* Simple */ && arg.name) {
|
12165
12231
|
const paramIndex = (_a = paramMap.get(arg.name.value)) !== null && _a !== void 0 ? _a : paramListDetails.kwargsIndex;
|
12166
12232
|
if (paramIndex !== undefined) {
|
@@ -12172,7 +12238,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12172
12238
|
argument: arg,
|
12173
12239
|
errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
|
12174
12240
|
};
|
12175
|
-
validateArgType(argParam, new typeVarContext_1.TypeVarContext(), { type: newMethodType },
|
12241
|
+
validateArgType(argParam, new typeVarContext_1.TypeVarContext(), signatureTracker, { type: newMethodType },
|
12176
12242
|
/* skipUnknownCheck */ true,
|
12177
12243
|
/* skipOverloadArg */ true,
|
12178
12244
|
/* useNarrowBoundOnly */ false,
|
@@ -13303,9 +13369,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13303
13369
|
}
|
13304
13370
|
return getExceptionType(subType, node.typeExpression);
|
13305
13371
|
});
|
13306
|
-
// If this is an except group, wrap the exception type in an
|
13372
|
+
// If this is an except group, wrap the exception type in an BaseExceptionGroup.
|
13307
13373
|
if (node.isExceptGroup) {
|
13308
|
-
targetType = getBuiltInObject(node, '
|
13374
|
+
targetType = getBuiltInObject(node, 'BaseExceptionGroup', [targetType]);
|
13309
13375
|
}
|
13310
13376
|
if (node.name) {
|
13311
13377
|
assignTypeToExpression(node.name, targetType, /* isIncomplete */ false, node.name);
|
@@ -13736,7 +13802,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13736
13802
|
nodeToEvaluate = parent;
|
13737
13803
|
continue;
|
13738
13804
|
}
|
13739
|
-
// The left expression of a call or member access expression is not contextual.
|
13805
|
+
// The left expression of a call or member access expression is not generally contextual.
|
13740
13806
|
if (parent.nodeType === 9 /* Call */ || parent.nodeType === 35 /* MemberAccess */) {
|
13741
13807
|
if (nodeToEvaluate === parent.leftExpression) {
|
13742
13808
|
// Handle the special case where the LHS is a call to super().
|
@@ -13746,6 +13812,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13746
13812
|
nodeToEvaluate = parent;
|
13747
13813
|
continue;
|
13748
13814
|
}
|
13815
|
+
// Handle the special case where the LHS is a call to a lambda.
|
13816
|
+
if (parent.nodeType === 9 /* Call */ && nodeToEvaluate.nodeType === 30 /* Lambda */) {
|
13817
|
+
nodeToEvaluate = parent;
|
13818
|
+
continue;
|
13819
|
+
}
|
13749
13820
|
flags = 2 /* DoNotSpecialize */;
|
13750
13821
|
break;
|
13751
13822
|
}
|
@@ -15497,33 +15568,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15497
15568
|
}
|
15498
15569
|
}
|
15499
15570
|
});
|
15571
|
+
// How many times have we already attempted to evaluate this declaration already?
|
15572
|
+
const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
|
15573
|
+
let resultType;
|
15500
15574
|
if (typesToCombine.length > 0) {
|
15501
|
-
// How many times have we already attempted to evaluate this declaration already?
|
15502
|
-
const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
|
15503
15575
|
// Ignore the pending evaluation flag if we've already attempted the
|
15504
15576
|
// type evaluation many times because this probably means there's a
|
15505
15577
|
// cyclical dependency that cannot be broken.
|
15506
15578
|
isIncomplete = sawPendingEvaluation && evaluationAttempts < maxEffectiveTypeEvaluationAttempts;
|
15507
|
-
|
15508
|
-
type: (0, types_1.combineTypes)(typesToCombine),
|
15509
|
-
isIncomplete,
|
15510
|
-
includesVariableDecl,
|
15511
|
-
includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
|
15512
|
-
isRecursiveDefinition: false,
|
15513
|
-
evaluationAttempts,
|
15514
|
-
};
|
15515
|
-
if (!includesSpeculativeResult) {
|
15516
|
-
addToEffectiveTypeCache(result);
|
15517
|
-
}
|
15518
|
-
return result;
|
15579
|
+
resultType = (0, types_1.combineTypes)(typesToCombine);
|
15519
15580
|
}
|
15520
|
-
|
15521
|
-
|
15581
|
+
else {
|
15582
|
+
resultType = types_1.UnboundType.create();
|
15583
|
+
}
|
15584
|
+
const result = {
|
15585
|
+
type: resultType,
|
15522
15586
|
isIncomplete,
|
15523
15587
|
includesVariableDecl,
|
15524
15588
|
includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
|
15525
15589
|
isRecursiveDefinition: false,
|
15590
|
+
evaluationAttempts,
|
15526
15591
|
};
|
15592
|
+
if (!includesSpeculativeResult) {
|
15593
|
+
addToEffectiveTypeCache(result);
|
15594
|
+
}
|
15595
|
+
return result;
|
15527
15596
|
function addToEffectiveTypeCache(result) {
|
15528
15597
|
// Add the entry to the cache so we don't need to compute it next time.
|
15529
15598
|
if (!cacheEntries) {
|
@@ -16059,7 +16128,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16059
16128
|
});
|
16060
16129
|
return isAssignable;
|
16061
16130
|
}
|
16062
|
-
function assignTupleTypeArgs(destType, srcType, diag,
|
16131
|
+
function assignTupleTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
16063
16132
|
var _a, _b;
|
16064
16133
|
const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
|
16065
16134
|
const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
|
@@ -16113,8 +16182,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16113
16182
|
if (srcTypeArgs.length === destTypeArgs.length) {
|
16114
16183
|
for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
|
16115
16184
|
const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
16116
|
-
if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(),
|
16117
|
-
/* srcTypeVarContext */ undefined, flags, recursionCount)) {
|
16185
|
+
if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16118
16186
|
if (entryDiag) {
|
16119
16187
|
entryDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleEntryTypeMismatch().format({
|
16120
16188
|
entry: argIndex + 1,
|
@@ -16173,7 +16241,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16173
16241
|
// Handle built-in types that support arbitrary numbers
|
16174
16242
|
// of type parameters like Tuple.
|
16175
16243
|
if (ancestorIndex === 0 && destType.tupleTypeArguments && curSrcType.tupleTypeArguments) {
|
16176
|
-
return assignTupleTypeArgs(destType, curSrcType, diag,
|
16244
|
+
return assignTupleTypeArgs(destType, curSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
16177
16245
|
}
|
16178
16246
|
// If there are no type parameters on this class, we're done.
|
16179
16247
|
const ancestorTypeParams = types_1.ClassType.getTypeParameters(ancestorType);
|
@@ -16248,6 +16316,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16248
16316
|
destTypeArgs = destType.typeArguments;
|
16249
16317
|
srcTypeArgs = srcType.typeArguments;
|
16250
16318
|
}
|
16319
|
+
let isCompatible = true;
|
16251
16320
|
if (srcTypeArgs) {
|
16252
16321
|
for (let srcArgIndex = 0; srcArgIndex < srcTypeArgs.length; srcArgIndex++) {
|
16253
16322
|
const srcTypeArg = srcTypeArgs[srcArgIndex];
|
@@ -16272,7 +16341,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16272
16341
|
diag.addAddendum(assignmentDiag);
|
16273
16342
|
}
|
16274
16343
|
}
|
16275
|
-
|
16344
|
+
isCompatible = false;
|
16276
16345
|
}
|
16277
16346
|
}
|
16278
16347
|
else if (types_1.TypeVarType.getVariance(destTypeParam) === 4 /* Contravariant */) {
|
@@ -16284,7 +16353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16284
16353
|
}));
|
16285
16354
|
childDiag.addAddendum(assignmentDiag);
|
16286
16355
|
}
|
16287
|
-
|
16356
|
+
isCompatible = false;
|
16288
16357
|
}
|
16289
16358
|
}
|
16290
16359
|
else {
|
@@ -16299,13 +16368,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16299
16368
|
}));
|
16300
16369
|
childDiag.addAddendum(assignmentDiag);
|
16301
16370
|
}
|
16302
|
-
|
16371
|
+
isCompatible = false;
|
16303
16372
|
}
|
16304
16373
|
}
|
16305
16374
|
}
|
16306
16375
|
}
|
16307
16376
|
}
|
16308
|
-
return
|
16377
|
+
return isCompatible;
|
16309
16378
|
}
|
16310
16379
|
// Determines if the source type can be assigned to the dest type.
|
16311
16380
|
// If typeVarContext is provided, type variables within the destType are
|
@@ -16513,6 +16582,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16513
16582
|
}
|
16514
16583
|
}
|
16515
16584
|
if ((0, types_1.isNever)(srcType)) {
|
16585
|
+
if ((flags & 1 /* EnforceInvariance */) !== 0) {
|
16586
|
+
return (0, types_1.isNever)(destType);
|
16587
|
+
}
|
16516
16588
|
const targetTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
|
16517
16589
|
if (targetTypeVarContext) {
|
16518
16590
|
(0, typeUtils_1.setTypeArgumentsRecursive)(destType, types_1.UnknownType.create(), targetTypeVarContext, recursionCount);
|
@@ -16694,9 +16766,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16694
16766
|
if (destCallbackType) {
|
16695
16767
|
return assignType(destCallbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
16696
16768
|
}
|
16697
|
-
// All functions are
|
16698
|
-
if (
|
16699
|
-
return assignType(destType,
|
16769
|
+
// All functions are considered instances of "builtins.function".
|
16770
|
+
if (functionObj && (0, types_1.isClassInstance)(functionObj)) {
|
16771
|
+
return assignType(destType, functionObj, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
16700
16772
|
}
|
16701
16773
|
}
|
16702
16774
|
else if ((0, types_1.isModule)(concreteSrcType)) {
|
@@ -18607,6 +18679,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18607
18679
|
if (options === null || options === void 0 ? void 0 : options.useTypingUnpack) {
|
18608
18680
|
flags |= 512 /* UseTypingUnpack */;
|
18609
18681
|
}
|
18682
|
+
if (options === null || options === void 0 ? void 0 : options.printUnknownWithAny) {
|
18683
|
+
flags |= 1 /* PrintUnknownWithAny */;
|
18684
|
+
}
|
18685
|
+
if (options === null || options === void 0 ? void 0 : options.omitTypeArgumentsIfUnknown) {
|
18686
|
+
flags |= 2 /* OmitTypeArgumentsIfUnknown */;
|
18687
|
+
}
|
18610
18688
|
return TypePrinter.printType(type, flags, getFunctionEffectiveReturnType);
|
18611
18689
|
}
|
18612
18690
|
// Calls back into the parser to parse the contents of a string literal.
|