@zzzen/pyright-internal 1.2.0-dev.20230205 → 1.2.0-dev.20230219

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 (161) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
  2. package/dist/analyzer/backgroundAnalysisProgram.js +5 -0
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/checker.js +8 -5
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/commentUtils.d.ts +6 -1
  7. package/dist/analyzer/commentUtils.js +100 -25
  8. package/dist/analyzer/commentUtils.js.map +1 -1
  9. package/dist/analyzer/constraintSolver.js +83 -67
  10. package/dist/analyzer/constraintSolver.js.map +1 -1
  11. package/dist/analyzer/dataClasses.js +9 -2
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/declaration.d.ts +1 -0
  14. package/dist/analyzer/declaration.js.map +1 -1
  15. package/dist/analyzer/importStatementUtils.d.ts +1 -0
  16. package/dist/analyzer/importStatementUtils.js +14 -1
  17. package/dist/analyzer/importStatementUtils.js.map +1 -1
  18. package/dist/analyzer/parameterUtils.d.ts +2 -0
  19. package/dist/analyzer/parameterUtils.js +20 -0
  20. package/dist/analyzer/parameterUtils.js.map +1 -0
  21. package/dist/analyzer/parseTreeUtils.d.ts +6 -2
  22. package/dist/analyzer/parseTreeUtils.js +52 -14
  23. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  24. package/dist/analyzer/parseTreeWalker.d.ts +1 -1
  25. package/dist/analyzer/patternMatching.js +25 -5
  26. package/dist/analyzer/patternMatching.js.map +1 -1
  27. package/dist/analyzer/program.d.ts +9 -2
  28. package/dist/analyzer/program.js +106 -8
  29. package/dist/analyzer/program.js.map +1 -1
  30. package/dist/analyzer/service.d.ts +1 -4
  31. package/dist/analyzer/service.js +16 -36
  32. package/dist/analyzer/service.js.map +1 -1
  33. package/dist/analyzer/sourceFile.d.ts +4 -0
  34. package/dist/analyzer/sourceFile.js +82 -16
  35. package/dist/analyzer/sourceFile.js.map +1 -1
  36. package/dist/analyzer/testWalker.js +23 -15
  37. package/dist/analyzer/testWalker.js.map +1 -1
  38. package/dist/analyzer/typeEvaluator.js +122 -71
  39. package/dist/analyzer/typeEvaluator.js.map +1 -1
  40. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
  41. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  42. package/dist/analyzer/typePrinter.d.ts +2 -1
  43. package/dist/analyzer/typePrinter.js +13 -0
  44. package/dist/analyzer/typePrinter.js.map +1 -1
  45. package/dist/analyzer/typeUtils.d.ts +1 -1
  46. package/dist/analyzer/typeUtils.js +189 -142
  47. package/dist/analyzer/typeUtils.js.map +1 -1
  48. package/dist/analyzer/typeVarContext.d.ts +31 -14
  49. package/dist/analyzer/typeVarContext.js +158 -79
  50. package/dist/analyzer/typeVarContext.js.map +1 -1
  51. package/dist/analyzer/types.d.ts +2 -1
  52. package/dist/analyzer/types.js +1 -0
  53. package/dist/analyzer/types.js.map +1 -1
  54. package/dist/backgroundAnalysisBase.d.ts +2 -1
  55. package/dist/backgroundAnalysisBase.js +15 -1
  56. package/dist/backgroundAnalysisBase.js.map +1 -1
  57. package/dist/backgroundThreadBase.js +1 -0
  58. package/dist/backgroundThreadBase.js.map +1 -1
  59. package/dist/common/commandLineOptions.d.ts +2 -0
  60. package/dist/common/commandLineOptions.js.map +1 -1
  61. package/dist/common/configOptions.d.ts +3 -0
  62. package/dist/common/configOptions.js +10 -1
  63. package/dist/common/configOptions.js.map +1 -1
  64. package/dist/common/core.d.ts +2 -0
  65. package/dist/common/core.js +9 -1
  66. package/dist/common/core.js.map +1 -1
  67. package/dist/common/diagnostic.d.ts +15 -3
  68. package/dist/common/diagnostic.js +13 -4
  69. package/dist/common/diagnostic.js.map +1 -1
  70. package/dist/common/editAction.d.ts +1 -0
  71. package/dist/common/editAction.js +8 -0
  72. package/dist/common/editAction.js.map +1 -1
  73. package/dist/common/extensibility.d.ts +34 -11
  74. package/dist/common/extensibility.js +63 -18
  75. package/dist/common/extensibility.js.map +1 -1
  76. package/dist/common/pathUtils.d.ts +3 -0
  77. package/dist/common/pathUtils.js +18 -0
  78. package/dist/common/pathUtils.js.map +1 -1
  79. package/dist/common/textEditUtils.d.ts +26 -9
  80. package/dist/common/textEditUtils.js +218 -41
  81. package/dist/common/textEditUtils.js.map +1 -1
  82. package/dist/common/textRangeCollection.d.ts +1 -0
  83. package/dist/common/textRangeCollection.js +54 -20
  84. package/dist/common/textRangeCollection.js.map +1 -1
  85. package/dist/languageServerBase.d.ts +3 -0
  86. package/dist/languageServerBase.js +90 -1
  87. package/dist/languageServerBase.js.map +1 -1
  88. package/dist/languageService/analyzerServiceExecutor.js +1 -0
  89. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  90. package/dist/languageService/completionProvider.js +13 -7
  91. package/dist/languageService/completionProvider.js.map +1 -1
  92. package/dist/languageService/definitionProvider.js +1 -1
  93. package/dist/languageService/definitionProvider.js.map +1 -1
  94. package/dist/languageService/documentSymbolCollector.js +1 -1
  95. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  96. package/dist/languageService/hoverProvider.js +10 -6
  97. package/dist/languageService/hoverProvider.js.map +1 -1
  98. package/dist/languageService/importAdder.d.ts +4 -0
  99. package/dist/languageService/importAdder.js +50 -13
  100. package/dist/languageService/importAdder.js.map +1 -1
  101. package/dist/languageService/insertionPointUtils.js +28 -7
  102. package/dist/languageService/insertionPointUtils.js.map +1 -1
  103. package/dist/languageService/renameModuleProvider.d.ts +12 -10
  104. package/dist/languageService/renameModuleProvider.js +240 -229
  105. package/dist/languageService/renameModuleProvider.js.map +1 -1
  106. package/dist/languageService/signatureHelpProvider.js +20 -3
  107. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  108. package/dist/languageService/tooltipUtils.js +1 -1
  109. package/dist/languageService/tooltipUtils.js.map +1 -1
  110. package/dist/localization/localize.d.ts +10 -1
  111. package/dist/localization/localize.js +6 -1
  112. package/dist/localization/localize.js.map +1 -1
  113. package/dist/localization/package.nls.en-us.json +8 -2
  114. package/dist/tests/checker.test.js +5 -0
  115. package/dist/tests/checker.test.js.map +1 -1
  116. package/dist/tests/fourslash/completions.params.fourslash.js +37 -0
  117. package/dist/tests/fourslash/completions.params.fourslash.js.map +1 -1
  118. package/dist/tests/fourslash/hover.inferred.fourslash.d.ts +1 -0
  119. package/dist/tests/fourslash/hover.inferred.fourslash.js +24 -0
  120. package/dist/tests/fourslash/hover.inferred.fourslash.js.map +1 -0
  121. package/dist/tests/fourslash/signature.complicated.fourslash.js +31 -1
  122. package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
  123. package/dist/tests/hoverProvider.test.js +27 -0
  124. package/dist/tests/hoverProvider.test.js.map +1 -1
  125. package/dist/tests/importAdder.test.js +39 -2
  126. package/dist/tests/importAdder.test.js.map +1 -1
  127. package/dist/tests/insertionPointUtils.test.js +70 -3
  128. package/dist/tests/insertionPointUtils.test.js.map +1 -1
  129. package/dist/tests/{updateSymbolReference.test.d.ts → moveSymbol.importAdder.test.d.ts} +0 -0
  130. package/dist/tests/moveSymbol.importAdder.test.js +139 -0
  131. package/dist/tests/moveSymbol.importAdder.test.js.map +1 -0
  132. package/dist/tests/moveSymbol.insertion.test.d.ts +1 -0
  133. package/dist/tests/moveSymbol.insertion.test.js +360 -0
  134. package/dist/tests/moveSymbol.insertion.test.js.map +1 -0
  135. package/dist/tests/moveSymbol.misc.test.d.ts +1 -0
  136. package/dist/tests/moveSymbol.misc.test.js +37 -0
  137. package/dist/tests/moveSymbol.misc.test.js.map +1 -0
  138. package/dist/tests/moveSymbol.updateReference.test.d.ts +1 -0
  139. package/dist/tests/{updateSymbolReference.test.js → moveSymbol.updateReference.test.js} +235 -158
  140. package/dist/tests/moveSymbol.updateReference.test.js.map +1 -0
  141. package/dist/tests/parseTreeUtils.test.js +36 -13
  142. package/dist/tests/parseTreeUtils.test.js.map +1 -1
  143. package/dist/tests/renameModuleTestUtils.js +9 -3
  144. package/dist/tests/renameModuleTestUtils.js.map +1 -1
  145. package/dist/tests/testStateUtils.d.ts +2 -0
  146. package/dist/tests/testStateUtils.js +25 -22
  147. package/dist/tests/testStateUtils.js.map +1 -1
  148. package/dist/tests/textEditUtil.test.d.ts +1 -0
  149. package/dist/tests/textEditUtil.test.js +107 -0
  150. package/dist/tests/textEditUtil.test.js.map +1 -0
  151. package/dist/tests/typeEvaluator1.test.js +4 -0
  152. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  153. package/dist/tests/typeEvaluator3.test.js +2 -2
  154. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  155. package/dist/tests/typeEvaluator4.test.js +10 -2
  156. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  157. package/dist/workspaceMap.d.ts +0 -1
  158. package/dist/workspaceMap.js +0 -11
  159. package/dist/workspaceMap.js.map +1 -1
  160. package/package.json +1 -1
  161. package/dist/tests/updateSymbolReference.test.js.map +0 -1
@@ -1354,8 +1354,8 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
1354
1354
  setTypeArgumentsRecursive(destType.details.declaredReturnType, srcType, typeVarContext, recursionCount);
1355
1355
  }
1356
1356
  if (destType.details.paramSpec) {
1357
- // Fill in an empty signature for a ParamSpec if the source is Any or Unknown.
1358
- if (!typeVarContext.hasTypeVar(destType.details.paramSpec) && (0, types_1.isAnyOrUnknown)(srcType)) {
1357
+ // Fill in an empty signature for a ParamSpec.
1358
+ if (!typeVarContext.getPrimarySignature().getTypeVar(destType.details.paramSpec)) {
1359
1359
  const newFunction = types_1.FunctionType.createInstance('', '', '', 32768 /* SkipArgsKwargsCompatibilityCheck */ | 65536 /* ParamSpecValue */);
1360
1360
  types_1.FunctionType.addDefaultParameters(newFunction);
1361
1361
  typeVarContext.setTypeVarType(destType.details.paramSpec, newFunction);
@@ -1369,7 +1369,7 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
1369
1369
  });
1370
1370
  break;
1371
1371
  case 10 /* TypeVar */:
1372
- if (!typeVarContext.hasTypeVar(destType)) {
1372
+ if (!typeVarContext.getPrimarySignature().getTypeVar(destType)) {
1373
1373
  typeVarContext.setTypeVarType(destType, srcType);
1374
1374
  }
1375
1375
  break;
@@ -2370,7 +2370,12 @@ class TypeVarTransformer {
2370
2370
  const newOverloads = [];
2371
2371
  type.overloads.forEach((entry) => {
2372
2372
  const replacementType = this._transformTypeVarsInFunctionType(entry, recursionCount);
2373
- newOverloads.push(replacementType);
2373
+ if ((0, types_1.isFunction)(replacementType)) {
2374
+ newOverloads.push(replacementType);
2375
+ }
2376
+ else {
2377
+ newOverloads.push(...replacementType.overloads);
2378
+ }
2374
2379
  if (replacementType !== entry) {
2375
2380
  requiresUpdate = true;
2376
2381
  }
@@ -2393,6 +2398,11 @@ class TypeVarTransformer {
2393
2398
  transformUnionSubtype(preTransform, postTransform, recursionCount) {
2394
2399
  return postTransform;
2395
2400
  }
2401
+ doForEachSignatureContext(callback) {
2402
+ // By default, simply return the result of the callback. Subclasses
2403
+ // can override this method as they see fit.
2404
+ return callback();
2405
+ }
2396
2406
  _transformGenericTypeAlias(type, recursionCount) {
2397
2407
  if (!type.typeAliasInfo || !type.typeAliasInfo.typeParameters || !type.typeAliasInfo.typeArguments) {
2398
2408
  return type;
@@ -2511,148 +2521,156 @@ class TypeVarTransformer {
2511
2521
  /* includeSubclasses */ undefined, newTupleTypeArgs);
2512
2522
  }
2513
2523
  _transformTypeVarsInFunctionType(sourceType, recursionCount) {
2514
- let functionType = sourceType;
2515
- // Handle functions with a parameter specification in a special manner.
2516
- if (functionType.details.paramSpec) {
2517
- const paramSpec = this.transformParamSpec(functionType.details.paramSpec, recursionCount);
2518
- if (paramSpec) {
2519
- functionType = types_1.FunctionType.cloneForParamSpec(functionType, paramSpec);
2520
- }
2521
- }
2522
- const declaredReturnType = types_1.FunctionType.getSpecializedReturnType(functionType);
2523
- const specializedReturnType = declaredReturnType ? this.apply(declaredReturnType, recursionCount) : undefined;
2524
- let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
2525
- const specializedParameters = {
2526
- parameterTypes: [],
2527
- returnType: specializedReturnType,
2528
- };
2529
- // Does this function end with *args: P.args, **args: P.kwargs? If so, we'll
2530
- // modify the function and replace these parameters with the signature captured
2531
- // by the ParamSpec.
2532
- if (functionType.details.parameters.length >= 2) {
2533
- const argsParam = functionType.details.parameters[functionType.details.parameters.length - 2];
2534
- const kwargsParam = functionType.details.parameters[functionType.details.parameters.length - 1];
2535
- const argsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 2);
2536
- const kwargsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 1);
2537
- if (argsParam.category === 1 /* VarArgList */ &&
2538
- kwargsParam.category === 2 /* VarArgDictionary */ &&
2539
- (0, types_1.isParamSpec)(argsParamType) &&
2540
- (0, types_1.isParamSpec)(kwargsParamType) &&
2541
- (0, types_1.isTypeSame)(argsParamType, kwargsParamType)) {
2542
- const paramSpecType = this.transformParamSpec(argsParamType, recursionCount);
2543
- if (paramSpecType) {
2544
- if (paramSpecType.details.parameters.length > 0 ||
2545
- paramSpecType.details.paramSpec === undefined ||
2546
- !(0, types_1.isTypeSame)(argsParamType, paramSpecType.details.paramSpec)) {
2547
- functionType = types_1.FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
2524
+ return this.doForEachSignatureContext(() => {
2525
+ let functionType = sourceType;
2526
+ // Handle functions with a parameter specification in a special manner.
2527
+ if (functionType.details.paramSpec) {
2528
+ const paramSpec = this.transformParamSpec(functionType.details.paramSpec, recursionCount);
2529
+ if (paramSpec) {
2530
+ functionType = types_1.FunctionType.cloneForParamSpec(functionType, paramSpec);
2531
+ }
2532
+ }
2533
+ const declaredReturnType = types_1.FunctionType.getSpecializedReturnType(functionType);
2534
+ const specializedReturnType = declaredReturnType
2535
+ ? this.apply(declaredReturnType, recursionCount)
2536
+ : undefined;
2537
+ let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
2538
+ const specializedParameters = {
2539
+ parameterTypes: [],
2540
+ returnType: specializedReturnType,
2541
+ };
2542
+ // Does this function end with *args: P.args, **args: P.kwargs? If so, we'll
2543
+ // modify the function and replace these parameters with the signature captured
2544
+ // by the ParamSpec.
2545
+ if (functionType.details.parameters.length >= 2) {
2546
+ const argsParam = functionType.details.parameters[functionType.details.parameters.length - 2];
2547
+ const kwargsParam = functionType.details.parameters[functionType.details.parameters.length - 1];
2548
+ const argsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 2);
2549
+ const kwargsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 1);
2550
+ if (argsParam.category === 1 /* VarArgList */ &&
2551
+ kwargsParam.category === 2 /* VarArgDictionary */ &&
2552
+ (0, types_1.isParamSpec)(argsParamType) &&
2553
+ (0, types_1.isParamSpec)(kwargsParamType) &&
2554
+ (0, types_1.isTypeSame)(argsParamType, kwargsParamType)) {
2555
+ const paramSpecType = this.transformParamSpec(argsParamType, recursionCount);
2556
+ if (paramSpecType) {
2557
+ if (paramSpecType.details.parameters.length > 0 ||
2558
+ paramSpecType.details.paramSpec === undefined ||
2559
+ !(0, types_1.isTypeSame)(argsParamType, paramSpecType.details.paramSpec)) {
2560
+ functionType = types_1.FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
2561
+ }
2548
2562
  }
2549
2563
  }
2550
2564
  }
2551
- }
2552
- let variadicParamIndex;
2553
- let variadicTypesToUnpack;
2554
- const specializedDefaultArgs = [];
2555
- const wasTransformingTypeArg = this._isTransformingTypeArg;
2556
- this._isTransformingTypeArg = true;
2557
- for (let i = 0; i < functionType.details.parameters.length; i++) {
2558
- const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, i);
2559
- const specializedType = this.apply(paramType, recursionCount);
2560
- specializedParameters.parameterTypes.push(specializedType);
2561
- // Do we need to specialize the default argument type for this parameter?
2562
- let defaultArgType = types_1.FunctionType.getEffectiveParameterDefaultArgType(functionType, i);
2563
- if (defaultArgType) {
2564
- const specializedArgType = this.apply(defaultArgType, recursionCount);
2565
- if (specializedArgType !== defaultArgType) {
2566
- defaultArgType = specializedArgType;
2565
+ let variadicParamIndex;
2566
+ let variadicTypesToUnpack;
2567
+ const specializedDefaultArgs = [];
2568
+ const wasTransformingTypeArg = this._isTransformingTypeArg;
2569
+ this._isTransformingTypeArg = true;
2570
+ for (let i = 0; i < functionType.details.parameters.length; i++) {
2571
+ const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, i);
2572
+ const specializedType = this.apply(paramType, recursionCount);
2573
+ specializedParameters.parameterTypes.push(specializedType);
2574
+ // Do we need to specialize the default argument type for this parameter?
2575
+ let defaultArgType = types_1.FunctionType.getEffectiveParameterDefaultArgType(functionType, i);
2576
+ if (defaultArgType) {
2577
+ const specializedArgType = this.apply(defaultArgType, recursionCount);
2578
+ if (specializedArgType !== defaultArgType) {
2579
+ defaultArgType = specializedArgType;
2580
+ typesRequiredSpecialization = true;
2581
+ }
2582
+ }
2583
+ specializedDefaultArgs.push(defaultArgType);
2584
+ if (variadicParamIndex === undefined &&
2585
+ (0, types_1.isVariadicTypeVar)(paramType) &&
2586
+ functionType.details.parameters[i].category === 1 /* VarArgList */) {
2587
+ variadicParamIndex = i;
2588
+ if ((0, types_1.isClassInstance)(specializedType) &&
2589
+ isTupleClass(specializedType) &&
2590
+ specializedType.isUnpacked) {
2591
+ variadicTypesToUnpack = specializedType.tupleTypeArguments;
2592
+ }
2593
+ }
2594
+ if (paramType !== specializedType) {
2567
2595
  typesRequiredSpecialization = true;
2568
2596
  }
2569
2597
  }
2570
- specializedDefaultArgs.push(defaultArgType);
2571
- if (variadicParamIndex === undefined &&
2572
- (0, types_1.isVariadicTypeVar)(paramType) &&
2573
- functionType.details.parameters[i].category === 1 /* VarArgList */) {
2574
- variadicParamIndex = i;
2575
- if ((0, types_1.isClassInstance)(specializedType) && isTupleClass(specializedType) && specializedType.isUnpacked) {
2576
- variadicTypesToUnpack = specializedType.tupleTypeArguments;
2598
+ let specializedInferredReturnType;
2599
+ if (functionType.inferredReturnType) {
2600
+ specializedInferredReturnType = this.apply(functionType.inferredReturnType, recursionCount);
2601
+ if (specializedInferredReturnType !== functionType.inferredReturnType) {
2602
+ typesRequiredSpecialization = true;
2577
2603
  }
2578
2604
  }
2579
- if (paramType !== specializedType) {
2580
- typesRequiredSpecialization = true;
2581
- }
2582
- }
2583
- let specializedInferredReturnType;
2584
- if (functionType.inferredReturnType) {
2585
- specializedInferredReturnType = this.apply(functionType.inferredReturnType, recursionCount);
2586
- if (specializedInferredReturnType !== functionType.inferredReturnType) {
2587
- typesRequiredSpecialization = true;
2588
- }
2589
- }
2590
- this._isTransformingTypeArg = wasTransformingTypeArg;
2591
- if (!typesRequiredSpecialization) {
2592
- return functionType;
2593
- }
2594
- if (specializedDefaultArgs.some((t) => t !== undefined)) {
2595
- specializedParameters.parameterDefaultArgs = specializedDefaultArgs;
2596
- }
2597
- // If there was no unpacked variadic type variable, we're done.
2598
- if (!variadicTypesToUnpack) {
2599
- return types_1.FunctionType.cloneForSpecialization(functionType, specializedParameters, specializedInferredReturnType);
2600
- }
2601
- // Unpack the tuple and synthesize a new function in the process.
2602
- const newFunctionType = types_1.FunctionType.createSynthesizedInstance('', functionType.details.flags);
2603
- let insertKeywordOnlySeparator = false;
2604
- let swallowPositionOnlySeparator = false;
2605
- specializedParameters.parameterTypes.forEach((paramType, index) => {
2606
- if (index === variadicParamIndex) {
2607
- let sawUnboundedEntry = false;
2608
- // Unpack the tuple into individual parameters.
2609
- variadicTypesToUnpack.forEach((unpackedType) => {
2610
- types_1.FunctionType.addParameter(newFunctionType, {
2611
- category: unpackedType.isUnbounded ? 1 /* VarArgList */ : 0 /* Simple */,
2612
- name: `__p${newFunctionType.details.parameters.length}`,
2613
- isNameSynthesized: true,
2614
- type: unpackedType.type,
2615
- hasDeclaredType: true,
2605
+ this._isTransformingTypeArg = wasTransformingTypeArg;
2606
+ if (!typesRequiredSpecialization) {
2607
+ return functionType;
2608
+ }
2609
+ if (specializedDefaultArgs.some((t) => t !== undefined)) {
2610
+ specializedParameters.parameterDefaultArgs = specializedDefaultArgs;
2611
+ }
2612
+ // If there was no unpacked variadic type variable, we're done.
2613
+ if (!variadicTypesToUnpack) {
2614
+ return types_1.FunctionType.cloneForSpecialization(functionType, specializedParameters, specializedInferredReturnType);
2615
+ }
2616
+ // Unpack the tuple and synthesize a new function in the process.
2617
+ const newFunctionType = types_1.FunctionType.createSynthesizedInstance('', functionType.details.flags);
2618
+ let insertKeywordOnlySeparator = false;
2619
+ let swallowPositionOnlySeparator = false;
2620
+ specializedParameters.parameterTypes.forEach((paramType, index) => {
2621
+ if (index === variadicParamIndex) {
2622
+ let sawUnboundedEntry = false;
2623
+ // Unpack the tuple into individual parameters.
2624
+ variadicTypesToUnpack.forEach((unpackedType) => {
2625
+ types_1.FunctionType.addParameter(newFunctionType, {
2626
+ category: unpackedType.isUnbounded
2627
+ ? 1 /* VarArgList */
2628
+ : 0 /* Simple */,
2629
+ name: `__p${newFunctionType.details.parameters.length}`,
2630
+ isNameSynthesized: true,
2631
+ type: unpackedType.type,
2632
+ hasDeclaredType: true,
2633
+ });
2634
+ if (unpackedType.isUnbounded) {
2635
+ sawUnboundedEntry = true;
2636
+ }
2616
2637
  });
2617
- if (unpackedType.isUnbounded) {
2618
- sawUnboundedEntry = true;
2638
+ if (sawUnboundedEntry) {
2639
+ swallowPositionOnlySeparator = true;
2640
+ }
2641
+ else {
2642
+ insertKeywordOnlySeparator = true;
2619
2643
  }
2620
- });
2621
- if (sawUnboundedEntry) {
2622
- swallowPositionOnlySeparator = true;
2623
2644
  }
2624
2645
  else {
2625
- insertKeywordOnlySeparator = true;
2626
- }
2627
- }
2628
- else {
2629
- const param = { ...functionType.details.parameters[index] };
2630
- if (param.category === 1 /* VarArgList */ && !param.name) {
2631
- insertKeywordOnlySeparator = false;
2632
- }
2633
- else if (param.category === 2 /* VarArgDictionary */) {
2634
- insertKeywordOnlySeparator = false;
2635
- }
2636
- // Insert a keyword-only separator parameter if we previously
2637
- // unpacked a variadic TypeVar.
2638
- if (param.category === 0 /* Simple */ && param.name && insertKeywordOnlySeparator) {
2639
- types_1.FunctionType.addParameter(newFunctionType, {
2640
- category: 1 /* VarArgList */,
2641
- type: types_1.UnknownType.create(),
2642
- });
2643
- insertKeywordOnlySeparator = false;
2644
- }
2645
- param.type = paramType;
2646
- if (param.name && param.isNameSynthesized) {
2647
- param.name = `__p${newFunctionType.details.parameters.length}`;
2648
- }
2649
- if (param.category !== 0 /* Simple */ || param.name || !swallowPositionOnlySeparator) {
2650
- types_1.FunctionType.addParameter(newFunctionType, param);
2646
+ const param = { ...functionType.details.parameters[index] };
2647
+ if (param.category === 1 /* VarArgList */ && !param.name) {
2648
+ insertKeywordOnlySeparator = false;
2649
+ }
2650
+ else if (param.category === 2 /* VarArgDictionary */) {
2651
+ insertKeywordOnlySeparator = false;
2652
+ }
2653
+ // Insert a keyword-only separator parameter if we previously
2654
+ // unpacked a variadic TypeVar.
2655
+ if (param.category === 0 /* Simple */ && param.name && insertKeywordOnlySeparator) {
2656
+ types_1.FunctionType.addParameter(newFunctionType, {
2657
+ category: 1 /* VarArgList */,
2658
+ type: types_1.UnknownType.create(),
2659
+ });
2660
+ insertKeywordOnlySeparator = false;
2661
+ }
2662
+ param.type = paramType;
2663
+ if (param.name && param.isNameSynthesized) {
2664
+ param.name = `__p${newFunctionType.details.parameters.length}`;
2665
+ }
2666
+ if (param.category !== 0 /* Simple */ || param.name || !swallowPositionOnlySeparator) {
2667
+ types_1.FunctionType.addParameter(newFunctionType, param);
2668
+ }
2651
2669
  }
2652
- }
2670
+ });
2671
+ newFunctionType.details.declaredReturnType = specializedParameters.returnType;
2672
+ return newFunctionType;
2653
2673
  });
2654
- newFunctionType.details.declaredReturnType = specializedParameters.returnType;
2655
- return newFunctionType;
2656
2674
  }
2657
2675
  }
2658
2676
  // For a TypeVar with a default type, validates whether the default type is using
@@ -2688,15 +2706,17 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
2688
2706
  this._isSolvingDefaultType = false;
2689
2707
  }
2690
2708
  transformTypeVar(typeVar, recursionCount) {
2709
+ var _a;
2710
+ const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
2691
2711
  // If the type variable is unrelated to the scopes we're solving,
2692
2712
  // don't transform that type variable.
2693
2713
  if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
2694
- let replacement = this._typeVarContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
2714
+ let replacement = signatureContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
2695
2715
  // If there was no narrow bound but there is a wide bound that
2696
2716
  // contains literals, we'll use the wide bound even if "useNarrowBoundOnly"
2697
2717
  // is specified.
2698
2718
  if (!replacement && !!this._options.useNarrowBoundOnly) {
2699
- const wideType = this._typeVarContext.getTypeVarType(typeVar);
2719
+ const wideType = signatureContext.getTypeVarType(typeVar);
2700
2720
  if (wideType) {
2701
2721
  if (containsLiteralType(wideType, /* includeTypeArgs */ true)) {
2702
2722
  replacement = wideType;
@@ -2730,11 +2750,11 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
2730
2750
  }
2731
2751
  // If we're solving a default type, handle type variables with no scope ID.
2732
2752
  if (this._isSolvingDefaultType && !typeVar.scopeId) {
2733
- const replacementEntry = this._typeVarContext
2753
+ const replacementEntry = signatureContext
2734
2754
  .getTypeVars()
2735
2755
  .find((entry) => entry.typeVar.details.name === typeVar.details.name);
2736
2756
  if (replacementEntry) {
2737
- return this._typeVarContext.getTypeVarType(replacementEntry.typeVar);
2757
+ return signatureContext.getTypeVarType(replacementEntry.typeVar);
2738
2758
  }
2739
2759
  if (typeVar.details.defaultType) {
2740
2760
  return this.apply(typeVar.details.defaultType, recursionCount);
@@ -2743,11 +2763,11 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
2743
2763
  }
2744
2764
  // If we're solving a default type, handle type variables with no scope ID.
2745
2765
  if (this._isSolvingDefaultType && !typeVar.scopeId) {
2746
- const replacementEntry = this._typeVarContext
2766
+ const replacementEntry = signatureContext
2747
2767
  .getTypeVars()
2748
2768
  .find((entry) => entry.typeVar.details.name === typeVar.details.name);
2749
2769
  if (replacementEntry) {
2750
- return this._typeVarContext.getTypeVarType(replacementEntry.typeVar);
2770
+ return signatureContext.getTypeVarType(replacementEntry.typeVar);
2751
2771
  }
2752
2772
  if (typeVar.details.defaultType) {
2753
2773
  return this.apply(typeVar.details.defaultType, recursionCount);
@@ -2781,6 +2801,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
2781
2801
  return postTransform;
2782
2802
  }
2783
2803
  transformTupleTypeVar(typeVar) {
2804
+ var _a;
2784
2805
  if (!typeVar.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
2785
2806
  const defaultType = typeVar.details.defaultType;
2786
2807
  if (defaultType && (0, types_1.isClassInstance)(defaultType) && defaultType.tupleTypeArguments) {
@@ -2788,16 +2809,19 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
2788
2809
  }
2789
2810
  return undefined;
2790
2811
  }
2791
- return this._typeVarContext.getTupleTypeVar(typeVar);
2812
+ const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
2813
+ return signatureContext.getTupleTypeVar(typeVar);
2792
2814
  }
2793
2815
  transformParamSpec(paramSpec, recursionCount) {
2816
+ var _a;
2817
+ const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
2794
2818
  // If we're solving a default type, handle param specs with no scope ID.
2795
2819
  if (this._isSolvingDefaultType && !paramSpec.scopeId) {
2796
- const replacementEntry = this._typeVarContext
2820
+ const replacementEntry = signatureContext
2797
2821
  .getTypeVars()
2798
2822
  .find((entry) => entry.typeVar.details.name === paramSpec.details.name);
2799
2823
  if (replacementEntry) {
2800
- return this._typeVarContext.getParamSpecType(replacementEntry.typeVar);
2824
+ return signatureContext.getParamSpecType(replacementEntry.typeVar);
2801
2825
  }
2802
2826
  if (paramSpec.details.defaultType) {
2803
2827
  return convertTypeToParamSpecValue(this.apply(paramSpec.details.defaultType, recursionCount));
@@ -2807,7 +2831,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
2807
2831
  if (!paramSpec.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.scopeId)) {
2808
2832
  return undefined;
2809
2833
  }
2810
- const transformedParamSpec = this._typeVarContext.getParamSpecType(paramSpec);
2834
+ const transformedParamSpec = signatureContext.getParamSpecType(paramSpec);
2811
2835
  if (transformedParamSpec) {
2812
2836
  return transformedParamSpec;
2813
2837
  }
@@ -2821,6 +2845,29 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
2821
2845
  }
2822
2846
  return undefined;
2823
2847
  }
2848
+ doForEachSignatureContext(callback) {
2849
+ const signatureContexts = this._typeVarContext.getSignatureContexts();
2850
+ // Handle the common case where there are not multiple signature contexts.
2851
+ if (signatureContexts.length <= 1) {
2852
+ return callback();
2853
+ }
2854
+ // Loop through all of the signature contexts in the type var context
2855
+ // to create an overload type.
2856
+ const overloadTypes = signatureContexts.map((_, index) => {
2857
+ this._activeTypeVarSignatureContextIndex = index;
2858
+ return callback();
2859
+ });
2860
+ this._activeTypeVarSignatureContextIndex = undefined;
2861
+ const filteredOverloads = [];
2862
+ doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
2863
+ (0, debug_1.assert)((0, types_1.isFunction)(subtype));
2864
+ filteredOverloads.push(subtype);
2865
+ });
2866
+ if (filteredOverloads.length === 1) {
2867
+ return filteredOverloads[0];
2868
+ }
2869
+ return types_1.OverloadedFunctionType.create(filteredOverloads);
2870
+ }
2824
2871
  _solveDefaultType(defaultType, recursionCount) {
2825
2872
  const wasSolvingDefaultType = this._isSolvingDefaultType;
2826
2873
  this._isSolvingDefaultType = true;