@zzzen/pyright-internal 1.2.0-dev.20230402 → 1.2.0-dev.20230409

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.
Files changed (69) hide show
  1. package/dist/analyzer/binder.d.ts +8 -0
  2. package/dist/analyzer/binder.js +46 -1
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.js +14 -0
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/patternMatching.js +2 -0
  7. package/dist/analyzer/patternMatching.js.map +1 -1
  8. package/dist/analyzer/program.d.ts +2 -0
  9. package/dist/analyzer/program.js +60 -28
  10. package/dist/analyzer/program.js.map +1 -1
  11. package/dist/analyzer/service.js +4 -0
  12. package/dist/analyzer/service.js.map +1 -1
  13. package/dist/analyzer/sourceFile.js +1 -1
  14. package/dist/analyzer/sourceFile.js.map +1 -1
  15. package/dist/analyzer/typeCacheUtils.js +25 -1
  16. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  17. package/dist/analyzer/typeEvaluator.js +96 -95
  18. package/dist/analyzer/typeEvaluator.js.map +1 -1
  19. package/dist/analyzer/typeUtils.d.ts +11 -0
  20. package/dist/analyzer/typeUtils.js +125 -55
  21. package/dist/analyzer/typeUtils.js.map +1 -1
  22. package/dist/analyzer/typedDicts.js +40 -6
  23. package/dist/analyzer/typedDicts.js.map +1 -1
  24. package/dist/analyzer/types.d.ts +1 -0
  25. package/dist/analyzer/types.js +10 -0
  26. package/dist/analyzer/types.js.map +1 -1
  27. package/dist/common/configOptions.js +1 -1
  28. package/dist/common/configOptions.js.map +1 -1
  29. package/dist/common/positionUtils.d.ts +2 -1
  30. package/dist/common/positionUtils.js +18 -12
  31. package/dist/common/positionUtils.js.map +1 -1
  32. package/dist/languageServerBase.js +1 -1
  33. package/dist/languageServerBase.js.map +1 -1
  34. package/dist/languageService/autoImporter.d.ts +1 -1
  35. package/dist/languageService/autoImporter.js +3 -5
  36. package/dist/languageService/autoImporter.js.map +1 -1
  37. package/dist/languageService/documentSymbolCollector.js +4 -1
  38. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  39. package/dist/languageService/hoverProvider.d.ts +2 -0
  40. package/dist/languageService/hoverProvider.js +53 -43
  41. package/dist/languageService/hoverProvider.js.map +1 -1
  42. package/dist/languageService/indentationUtils.js +5 -0
  43. package/dist/languageService/indentationUtils.js.map +1 -1
  44. package/dist/languageService/insertionPointUtils.js +2 -1
  45. package/dist/languageService/insertionPointUtils.js.map +1 -1
  46. package/dist/pyright.js +1 -2
  47. package/dist/pyright.js.map +1 -1
  48. package/dist/tests/chainedSourceFiles.test.js +27 -0
  49. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  50. package/dist/tests/completions.test.js +2 -3
  51. package/dist/tests/completions.test.js.map +1 -1
  52. package/dist/tests/indentationUtils.reindent.test.js +19 -0
  53. package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
  54. package/dist/tests/insertionPointUtils.test.js +13 -0
  55. package/dist/tests/insertionPointUtils.test.js.map +1 -1
  56. package/dist/tests/moveSymbol.insertion.test.js +21 -0
  57. package/dist/tests/moveSymbol.insertion.test.js.map +1 -1
  58. package/dist/tests/positionUtils.test.d.ts +1 -0
  59. package/dist/tests/positionUtils.test.js +48 -0
  60. package/dist/tests/positionUtils.test.js.map +1 -0
  61. package/dist/tests/typeEvaluator1.test.js +6 -0
  62. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  63. package/dist/tests/typeEvaluator2.test.js +16 -0
  64. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  65. package/dist/tests/typeEvaluator3.test.js +5 -1
  66. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  67. package/dist/workspaceFactory.js +4 -4
  68. package/dist/workspaceFactory.js.map +1 -1
  69. 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 > targetTypes.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) {
@@ -6031,7 +6033,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6031
6033
  // one or more analyzes with no errors, use those results.
6032
6034
  if (inferenceContext) {
6033
6035
  const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
6034
- if (expectedCallResult) {
6036
+ if (expectedCallResult && !expectedCallResult.argumentErrors) {
6035
6037
  returnType = expectedCallResult.returnType;
6036
6038
  if (expectedCallResult.isTypeIncomplete) {
6037
6039
  isTypeIncomplete = true;
@@ -6093,12 +6095,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6093
6095
  }
6094
6096
  if (constructorMethodInfo && !skipConstructorCheck(constructorMethodInfo.type)) {
6095
6097
  const constructorMethodType = constructorMethodInfo.type;
6098
+ let newReturnType;
6096
6099
  // If there is an expected type that was not applied above when
6097
6100
  // handling the __init__ method, try to apply it with the __new__ method.
6098
6101
  if (inferenceContext && !returnType) {
6099
6102
  const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
6100
- if (expectedCallResult) {
6101
- returnType = expectedCallResult.returnType;
6103
+ if (expectedCallResult && !expectedCallResult.argumentErrors) {
6104
+ newReturnType = expectedCallResult.returnType;
6105
+ returnType = newReturnType;
6102
6106
  if (expectedCallResult.isTypeIncomplete) {
6103
6107
  isTypeIncomplete = true;
6104
6108
  }
@@ -6128,8 +6132,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6128
6132
  if (callResult.argumentErrors) {
6129
6133
  reportedErrors = true;
6130
6134
  }
6131
- else {
6132
- let newReturnType = callResult.returnType;
6135
+ else if (!newReturnType) {
6136
+ newReturnType = callResult.returnType;
6133
6137
  // If the constructor returned an object whose type matches the class of
6134
6138
  // the original type being constructed, use the return type in case it was
6135
6139
  // specialized. If it doesn't match, we'll fall back on the assumption that
@@ -7194,10 +7198,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7194
7198
  }
7195
7199
  }
7196
7200
  else {
7197
- let mappingType = getTypeshedType(errorNode, 'SupportsKeysAndGetItem');
7198
- if (!mappingType) {
7199
- mappingType = getTypingType(errorNode, 'Mapping');
7200
- }
7201
7201
  const strObjType = getBuiltInObject(errorNode, 'str');
7202
7202
  if (mappingType &&
7203
7203
  (0, types_1.isInstantiableClass)(mappingType) &&
@@ -7632,28 +7632,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7632
7632
  // where more than two passes are needed.
7633
7633
  let passCount = Math.min(typeVarMatchingCount, 2);
7634
7634
  for (let i = 0; i < passCount; i++) {
7635
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7635
7636
  useSpeculativeMode(errorNode, () => {
7636
7637
  matchResults.argParams.forEach((argParam) => {
7637
- if (argParam.requiresTypeVarMatching) {
7638
- // Populate the typeVarContext for the argument. If the argument
7639
- // is an overload function, skip it during the first pass
7640
- // because the selection of the proper overload may depend
7641
- // on type arguments supplied by other function arguments.
7642
- // Set useNarrowBoundOnly to true the first time through
7643
- // the loop if we're going to go through the loop multiple
7644
- // times.
7645
- const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7646
- /* skipOverloadArg */ i === 0,
7647
- /* useNarrowBoundOnly */ passCount > 1 && i === 0, typeCondition);
7648
- if (argResult.isTypeIncomplete) {
7649
- isTypeIncomplete = true;
7650
- }
7651
- // If we skipped a overload arg during the first pass,
7652
- // add another pass to ensure that we handle all of the
7653
- // type variables.
7654
- if (i === 0 && argResult.skippedOverloadArg) {
7655
- passCount++;
7656
- }
7638
+ if (!argParam.requiresTypeVarMatching) {
7639
+ return;
7640
+ }
7641
+ // Populate the typeVarContext for the argument. If the argument
7642
+ // is an overload function, skip it during the first pass
7643
+ // because the selection of the proper overload may depend
7644
+ // on type arguments supplied by other function arguments.
7645
+ // Set useNarrowBoundOnly to true the first time through
7646
+ // the loop if we're going to go through the loop multiple
7647
+ // times.
7648
+ const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7649
+ /* skipOverloadArg */ i === 0,
7650
+ /* useNarrowBoundOnly */ passCount > 1 && i === 0, typeCondition);
7651
+ if (argResult.isTypeIncomplete) {
7652
+ isTypeIncomplete = true;
7653
+ }
7654
+ // If we skipped a overload arg during the first pass,
7655
+ // add another pass to ensure that we handle all of the
7656
+ // type variables.
7657
+ if (i === 0 && argResult.skippedOverloadArg) {
7658
+ passCount++;
7657
7659
  }
7658
7660
  });
7659
7661
  });
@@ -7666,9 +7668,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7666
7668
  let sawParamSpecKwargs = false;
7667
7669
  let condition = [];
7668
7670
  const argResults = [];
7671
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7669
7672
  matchResults.argParams.forEach((argParam) => {
7670
7673
  var _a;
7671
- const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7674
+ const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7672
7675
  /* skipOverloadArg */ false,
7673
7676
  /* useNarrowBoundOnly */ false, typeCondition);
7674
7677
  argResults.push(argResult);
@@ -7891,6 +7894,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7891
7894
  }
7892
7895
  const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* VarArgList */);
7893
7896
  const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* VarArgDictionary */);
7897
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7894
7898
  argList.forEach((arg) => {
7895
7899
  var _a;
7896
7900
  if (arg.argumentCategory === 0 /* Simple */) {
@@ -7937,7 +7941,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7937
7941
  requiresTypeVarMatching: false,
7938
7942
  argument: arg,
7939
7943
  errorNode: arg.valueExpression || errorNode,
7940
- }, srcTypeVarContext,
7944
+ }, srcTypeVarContext, signatureTracker,
7941
7945
  /* functionType */ undefined,
7942
7946
  /* skipUnknownArgCheck */ false,
7943
7947
  /* skipOverloadArg */ false,
@@ -7973,7 +7977,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7973
7977
  }
7974
7978
  return !reportedArgError;
7975
7979
  }
7976
- function validateArgType(argParam, typeVarContext, typeResult, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7980
+ function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7977
7981
  var _a;
7978
7982
  let argType;
7979
7983
  let expectedTypeDiag;
@@ -8046,6 +8050,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8046
8050
  }
8047
8051
  }
8048
8052
  }
8053
+ // If the type includes multiple instances of a generic function
8054
+ // signature, force the type arguments for the duplicates to have
8055
+ // unique names.
8056
+ argType = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(argType, signatureTracker);
8049
8057
  // If we're assigning to a var arg dictionary with a TypeVar type,
8050
8058
  // strip literals before performing the assignment. This is used in
8051
8059
  // places like a dict constructor.
@@ -9515,13 +9523,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9515
9523
  addUnknown = false;
9516
9524
  }
9517
9525
  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
9526
  let expectedType;
9526
9527
  if (expectedKeyType && expectedValueType) {
9527
9528
  if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
@@ -9553,29 +9554,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9553
9554
  addUnknown = false;
9554
9555
  }
9555
9556
  }
9556
- else {
9557
- if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
9558
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingType));
9559
- // Self-specialize the class.
9560
- mappingType = types_1.ClassType.cloneForSpecialization(mappingType, mappingType.details.typeParameters,
9561
- /* isTypeArgumentExplicit */ true);
9562
- if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
9563
- /* diag */ undefined, mappingTypeVarContext,
9564
- /* srcTypeVarContext */ undefined, 128 /* RetainLiteralsForTypeVar */)) {
9565
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingType, mappingTypeVarContext);
9566
- const typeArgs = specializedMapping.typeArguments;
9567
- if (typeArgs && typeArgs.length >= 2) {
9568
- if (forceStrictInference || index < maxEntriesToUseForInference) {
9569
- keyTypes.push({ node: entryNode, type: typeArgs[0] });
9570
- valueTypes.push({ node: entryNode, type: typeArgs[1] });
9571
- }
9572
- addUnknown = false;
9557
+ else if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
9558
+ const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingType));
9559
+ // Self-specialize the class.
9560
+ mappingType = types_1.ClassType.cloneForSpecialization(mappingType, mappingType.details.typeParameters,
9561
+ /* isTypeArgumentExplicit */ true);
9562
+ if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
9563
+ /* diag */ undefined, mappingTypeVarContext,
9564
+ /* srcTypeVarContext */ undefined, 128 /* RetainLiteralsForTypeVar */)) {
9565
+ const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingType, mappingTypeVarContext);
9566
+ const typeArgs = specializedMapping.typeArguments;
9567
+ if (typeArgs && typeArgs.length >= 2) {
9568
+ if (forceStrictInference || index < maxEntriesToUseForInference) {
9569
+ keyTypes.push({ node: entryNode, type: typeArgs[0] });
9570
+ valueTypes.push({ node: entryNode, type: typeArgs[1] });
9573
9571
  }
9572
+ addUnknown = false;
9574
9573
  }
9575
- else {
9576
- const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
9577
- addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictUnpackIsNotMapping(), entryNode);
9578
- }
9574
+ }
9575
+ else {
9576
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
9577
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.dictUnpackIsNotMapping(), entryNode);
9579
9578
  }
9580
9579
  }
9581
9580
  }
@@ -12161,6 +12160,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12161
12160
  }
12162
12161
  argList.forEach((arg) => {
12163
12162
  var _a, _b, _c;
12163
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
12164
12164
  if (arg.argumentCategory === 0 /* Simple */ && arg.name) {
12165
12165
  const paramIndex = (_a = paramMap.get(arg.name.value)) !== null && _a !== void 0 ? _a : paramListDetails.kwargsIndex;
12166
12166
  if (paramIndex !== undefined) {
@@ -12172,7 +12172,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12172
12172
  argument: arg,
12173
12173
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
12174
12174
  };
12175
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), { type: newMethodType },
12175
+ validateArgType(argParam, new typeVarContext_1.TypeVarContext(), signatureTracker, { type: newMethodType },
12176
12176
  /* skipUnknownCheck */ true,
12177
12177
  /* skipOverloadArg */ true,
12178
12178
  /* useNarrowBoundOnly */ false,
@@ -13303,9 +13303,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13303
13303
  }
13304
13304
  return getExceptionType(subType, node.typeExpression);
13305
13305
  });
13306
- // If this is an except group, wrap the exception type in an ExceptionGroup.
13306
+ // If this is an except group, wrap the exception type in an BaseExceptionGroup.
13307
13307
  if (node.isExceptGroup) {
13308
- targetType = getBuiltInObject(node, 'ExceptionGroup', [targetType]);
13308
+ targetType = getBuiltInObject(node, 'BaseExceptionGroup', [targetType]);
13309
13309
  }
13310
13310
  if (node.name) {
13311
13311
  assignTypeToExpression(node.name, targetType, /* isIncomplete */ false, node.name);
@@ -15497,33 +15497,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15497
15497
  }
15498
15498
  }
15499
15499
  });
15500
+ // How many times have we already attempted to evaluate this declaration already?
15501
+ 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;
15502
+ let resultType;
15500
15503
  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
15504
  // Ignore the pending evaluation flag if we've already attempted the
15504
15505
  // type evaluation many times because this probably means there's a
15505
15506
  // cyclical dependency that cannot be broken.
15506
15507
  isIncomplete = sawPendingEvaluation && evaluationAttempts < maxEffectiveTypeEvaluationAttempts;
15507
- const result = {
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;
15508
+ resultType = (0, types_1.combineTypes)(typesToCombine);
15519
15509
  }
15520
- return {
15521
- type: types_1.UnboundType.create(),
15510
+ else {
15511
+ resultType = types_1.UnboundType.create();
15512
+ }
15513
+ const result = {
15514
+ type: resultType,
15522
15515
  isIncomplete,
15523
15516
  includesVariableDecl,
15524
15517
  includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
15525
15518
  isRecursiveDefinition: false,
15519
+ evaluationAttempts,
15526
15520
  };
15521
+ if (!includesSpeculativeResult) {
15522
+ addToEffectiveTypeCache(result);
15523
+ }
15524
+ return result;
15527
15525
  function addToEffectiveTypeCache(result) {
15528
15526
  // Add the entry to the cache so we don't need to compute it next time.
15529
15527
  if (!cacheEntries) {
@@ -16059,7 +16057,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16059
16057
  });
16060
16058
  return isAssignable;
16061
16059
  }
16062
- function assignTupleTypeArgs(destType, srcType, diag, typeVarContext, flags, recursionCount) {
16060
+ function assignTupleTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
16063
16061
  var _a, _b;
16064
16062
  const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
16065
16063
  const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
@@ -16113,8 +16111,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16113
16111
  if (srcTypeArgs.length === destTypeArgs.length) {
16114
16112
  for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
16115
16113
  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(), typeVarContext,
16117
- /* srcTypeVarContext */ undefined, flags, recursionCount)) {
16114
+ if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16118
16115
  if (entryDiag) {
16119
16116
  entryDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleEntryTypeMismatch().format({
16120
16117
  entry: argIndex + 1,
@@ -16173,7 +16170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16173
16170
  // Handle built-in types that support arbitrary numbers
16174
16171
  // of type parameters like Tuple.
16175
16172
  if (ancestorIndex === 0 && destType.tupleTypeArguments && curSrcType.tupleTypeArguments) {
16176
- return assignTupleTypeArgs(destType, curSrcType, diag, curDestTypeVarContext, flags, recursionCount);
16173
+ return assignTupleTypeArgs(destType, curSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16177
16174
  }
16178
16175
  // If there are no type parameters on this class, we're done.
16179
16176
  const ancestorTypeParams = types_1.ClassType.getTypeParameters(ancestorType);
@@ -16248,6 +16245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16248
16245
  destTypeArgs = destType.typeArguments;
16249
16246
  srcTypeArgs = srcType.typeArguments;
16250
16247
  }
16248
+ let isCompatible = true;
16251
16249
  if (srcTypeArgs) {
16252
16250
  for (let srcArgIndex = 0; srcArgIndex < srcTypeArgs.length; srcArgIndex++) {
16253
16251
  const srcTypeArg = srcTypeArgs[srcArgIndex];
@@ -16272,7 +16270,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16272
16270
  diag.addAddendum(assignmentDiag);
16273
16271
  }
16274
16272
  }
16275
- return false;
16273
+ isCompatible = false;
16276
16274
  }
16277
16275
  }
16278
16276
  else if (types_1.TypeVarType.getVariance(destTypeParam) === 4 /* Contravariant */) {
@@ -16284,7 +16282,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16284
16282
  }));
16285
16283
  childDiag.addAddendum(assignmentDiag);
16286
16284
  }
16287
- return false;
16285
+ isCompatible = false;
16288
16286
  }
16289
16287
  }
16290
16288
  else {
@@ -16299,13 +16297,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16299
16297
  }));
16300
16298
  childDiag.addAddendum(assignmentDiag);
16301
16299
  }
16302
- return false;
16300
+ isCompatible = false;
16303
16301
  }
16304
16302
  }
16305
16303
  }
16306
16304
  }
16307
16305
  }
16308
- return true;
16306
+ return isCompatible;
16309
16307
  }
16310
16308
  // Determines if the source type can be assigned to the dest type.
16311
16309
  // If typeVarContext is provided, type variables within the destType are
@@ -16513,6 +16511,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16513
16511
  }
16514
16512
  }
16515
16513
  if ((0, types_1.isNever)(srcType)) {
16514
+ if ((flags & 1 /* EnforceInvariance */) !== 0) {
16515
+ return (0, types_1.isNever)(destType);
16516
+ }
16516
16517
  const targetTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
16517
16518
  if (targetTypeVarContext) {
16518
16519
  (0, typeUtils_1.setTypeArgumentsRecursive)(destType, types_1.UnknownType.create(), targetTypeVarContext, recursionCount);
@@ -16694,9 +16695,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16694
16695
  if (destCallbackType) {
16695
16696
  return assignType(destCallbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16696
16697
  }
16697
- // All functions are objects, so try to assign as an object.
16698
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
16699
- return assignType(destType, objectType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16698
+ // All functions are considered instances of "builtins.function".
16699
+ if (functionObj && (0, types_1.isClassInstance)(functionObj)) {
16700
+ return assignType(destType, functionObj, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16700
16701
  }
16701
16702
  }
16702
16703
  else if ((0, types_1.isModule)(concreteSrcType)) {