@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
@@ -52,6 +52,16 @@ export interface InferenceContext {
52
52
  isTypeIncomplete?: boolean;
53
53
  typeVarContext?: TypeVarContext;
54
54
  }
55
+ export interface SignatureWithCount {
56
+ type: FunctionType;
57
+ count: number;
58
+ }
59
+ export declare class UniqueSignatureTracker {
60
+ signaturesSeen: SignatureWithCount[];
61
+ constructor();
62
+ findSignature(signature: FunctionType): SignatureWithCount | undefined;
63
+ addSignature(signature: FunctionType): void;
64
+ }
55
65
  export declare function isOptionalType(type: Type): boolean;
56
66
  export declare function isIncompleteUnknown(type: Type): boolean;
57
67
  export declare function isTypeVarSame(type1: TypeVarType, type2: Type): boolean;
@@ -88,6 +98,7 @@ export declare function isTupleClass(type: ClassType): boolean;
88
98
  export declare function isUnboundedTupleClass(type: ClassType): boolean | undefined;
89
99
  export declare function partiallySpecializeType(type: Type, contextClassType: ClassType, selfClass?: ClassType, typeClassType?: Type): Type;
90
100
  export declare function populateTypeVarContextForSelfType(typeVarContext: TypeVarContext, contextClassType: ClassType, selfClass: ClassType): void;
101
+ export declare function ensureFunctionSignaturesAreUnique(type: Type, signatureTracker: UniqueSignatureTracker): Type;
91
102
  export declare function applySolvedTypeVars(type: Type, typeVarContext: TypeVarContext, options?: ApplyTypeVarOptions): Type;
92
103
  export declare function validateTypeVarDefault(typeVar: TypeVarType, liveTypeParams: TypeVarType[], invalidTypeVars: Set<string>): void;
93
104
  export declare function transformExpectedTypeForConstructor(expectedType: Type, liveTypeVarScopes: TypeVarScopeId[]): Type | undefined;
@@ -8,8 +8,8 @@
8
8
  * Functions that operate on Type objects.
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.specializeClassType = exports.isTypeVarLimitedToCallable = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbols = exports.transformExpectedTypeForConstructor = exports.validateTypeVarDefault = exports.applySolvedTypeVars = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.containsType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.isOptionalType = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
12
- exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = void 0;
11
+ exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbols = exports.transformExpectedTypeForConstructor = exports.validateTypeVarDefault = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.containsType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
12
+ exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.isTypeVarLimitedToCallable = void 0;
13
13
  const collectionUtils_1 = require("../common/collectionUtils");
14
14
  const debug_1 = require("../common/debug");
15
15
  const symbol_1 = require("./symbol");
@@ -99,6 +99,26 @@ var AssignTypeFlags;
99
99
  // employing narrowing or widening, and don't strip literals.
100
100
  AssignTypeFlags[AssignTypeFlags["PopulatingExpectedType"] = 1024] = "PopulatingExpectedType";
101
101
  })(AssignTypeFlags = exports.AssignTypeFlags || (exports.AssignTypeFlags = {}));
102
+ class UniqueSignatureTracker {
103
+ constructor() {
104
+ this.signaturesSeen = [];
105
+ }
106
+ findSignature(signature) {
107
+ return this.signaturesSeen.find((s) => {
108
+ return (0, types_1.isTypeSame)(signature, s.type);
109
+ });
110
+ }
111
+ addSignature(signature) {
112
+ const existingSignature = this.findSignature(signature);
113
+ if (existingSignature) {
114
+ existingSignature.count++;
115
+ }
116
+ else {
117
+ this.signaturesSeen.push({ type: signature, count: 1 });
118
+ }
119
+ }
120
+ }
121
+ exports.UniqueSignatureTracker = UniqueSignatureTracker;
102
122
  function isOptionalType(type) {
103
123
  if ((0, types_1.isUnion)(type)) {
104
124
  return (0, types_1.findSubtype)(type, (subtype) => (0, types_1.isNoneInstance)(subtype)) !== undefined;
@@ -687,6 +707,13 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
687
707
  typeVarContext.setTypeVarType(synthesizedSelfTypeVar, convertToInstance(selfClass));
688
708
  }
689
709
  exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
710
+ // Looks for duplicate function types within the type and ensures that
711
+ // if they are generic, they have unique type variables.
712
+ function ensureFunctionSignaturesAreUnique(type, signatureTracker) {
713
+ const transformer = new UniqueFunctionSignatureTransformer(signatureTracker);
714
+ return transformer.apply(type, 0);
715
+ }
716
+ exports.ensureFunctionSignaturesAreUnique = ensureFunctionSignaturesAreUnique;
690
717
  // Specializes a (potentially generic) type by substituting
691
718
  // type variables from a type var map.
692
719
  function applySolvedTypeVars(type, typeVarContext, options = {}) {
@@ -2175,7 +2202,7 @@ class TypeVarTransformer {
2175
2202
  return type;
2176
2203
  }
2177
2204
  recursionCount++;
2178
- type = this._transformGenericTypeAlias(type, recursionCount);
2205
+ type = this.transformGenericTypeAlias(type, recursionCount);
2179
2206
  // Shortcut the operation if possible.
2180
2207
  if (!requiresSpecialization(type)) {
2181
2208
  return type;
@@ -2257,7 +2284,7 @@ class TypeVarTransformer {
2257
2284
  return !(0, types_1.isNever)(newUnionType) ? newUnionType : types_1.UnknownType.create();
2258
2285
  }
2259
2286
  if ((0, types_1.isClass)(type)) {
2260
- return this._transformTypeVarsInClassType(type, recursionCount);
2287
+ return this.transformTypeVarsInClassType(type, recursionCount);
2261
2288
  }
2262
2289
  if ((0, types_1.isFunction)(type)) {
2263
2290
  // Prevent recursion.
@@ -2265,7 +2292,7 @@ class TypeVarTransformer {
2265
2292
  return type;
2266
2293
  }
2267
2294
  this._pendingFunctionTransformations.push(type);
2268
- const result = this._transformTypeVarsInFunctionType(type, recursionCount);
2295
+ const result = this.transformTypeVarsInFunctionType(type, recursionCount);
2269
2296
  this._pendingFunctionTransformations.pop();
2270
2297
  return result;
2271
2298
  }
@@ -2279,7 +2306,7 @@ class TypeVarTransformer {
2279
2306
  // Specialize each of the functions in the overload.
2280
2307
  const newOverloads = [];
2281
2308
  type.overloads.forEach((entry) => {
2282
- const replacementType = this._transformTypeVarsInFunctionType(entry, recursionCount);
2309
+ const replacementType = this.transformTypeVarsInFunctionType(entry, recursionCount);
2283
2310
  if ((0, types_1.isFunction)(replacementType)) {
2284
2311
  newOverloads.push(replacementType);
2285
2312
  }
@@ -2297,7 +2324,7 @@ class TypeVarTransformer {
2297
2324
  return type;
2298
2325
  }
2299
2326
  transformTypeVar(typeVar, recursionCount) {
2300
- return typeVar;
2327
+ return undefined;
2301
2328
  }
2302
2329
  transformTupleTypeVar(paramSpec, recursionCount) {
2303
2330
  return undefined;
@@ -2313,7 +2340,7 @@ class TypeVarTransformer {
2313
2340
  // can override this method as they see fit.
2314
2341
  return callback();
2315
2342
  }
2316
- _transformGenericTypeAlias(type, recursionCount) {
2343
+ transformGenericTypeAlias(type, recursionCount) {
2317
2344
  if (!type.typeAliasInfo || !type.typeAliasInfo.typeParameters || !type.typeAliasInfo.typeArguments) {
2318
2345
  return type;
2319
2346
  }
@@ -2329,12 +2356,12 @@ class TypeVarTransformer {
2329
2356
  ? types_1.TypeBase.cloneForTypeAlias(type, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, newTypeArgs)
2330
2357
  : type;
2331
2358
  }
2332
- _transformTypeVarsInClassType(classType, recursionCount) {
2359
+ transformTypeVarsInClassType(classType, recursionCount) {
2333
2360
  // Handle the common case where the class has no type parameters.
2334
2361
  if (types_1.ClassType.getTypeParameters(classType).length === 0 && !types_1.ClassType.isSpecialBuiltIn(classType)) {
2335
2362
  return classType;
2336
2363
  }
2337
- let newTypeArgs = [];
2364
+ let newTypeArgs;
2338
2365
  let newTupleTypeArgs;
2339
2366
  let specializationNeeded = false;
2340
2367
  const typeParams = types_1.ClassType.getTypeParameters(classType);
@@ -2351,50 +2378,7 @@ class TypeVarTransformer {
2351
2378
  const wasTransformingTypeArg = this._isTransformingTypeArg;
2352
2379
  this._isTransformingTypeArg = true;
2353
2380
  // If type args were previously provided, specialize them.
2354
- if (classType.typeArguments) {
2355
- newTypeArgs = classType.typeArguments.map((oldTypeArgType) => {
2356
- if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.details.isParamSpec) {
2357
- return transformParamSpec(oldTypeArgType);
2358
- }
2359
- let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
2360
- if (newTypeArgType !== oldTypeArgType) {
2361
- specializationNeeded = true;
2362
- // If this was a variadic type variable that was part of a union
2363
- // (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
2364
- if ((0, types_1.isTypeVar)(oldTypeArgType) &&
2365
- (0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
2366
- oldTypeArgType.isVariadicInUnion) {
2367
- newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
2368
- }
2369
- }
2370
- return newTypeArgType;
2371
- });
2372
- }
2373
- else {
2374
- typeParams.forEach((typeParam) => {
2375
- let replacementType = typeParam;
2376
- if (typeParam.details.isParamSpec) {
2377
- replacementType = transformParamSpec(typeParam);
2378
- if (replacementType !== typeParam) {
2379
- specializationNeeded = true;
2380
- }
2381
- }
2382
- else {
2383
- const typeParamName = types_1.TypeVarType.getNameWithScope(typeParam);
2384
- if (!this._pendingTypeVarTransformations.has(typeParamName)) {
2385
- const transformedType = this.transformTypeVar(typeParam, recursionCount);
2386
- replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
2387
- if (replacementType !== typeParam) {
2388
- specializationNeeded = true;
2389
- }
2390
- else if (transformedType !== undefined && !classType.typeArguments) {
2391
- specializationNeeded = true;
2392
- }
2393
- }
2394
- }
2395
- newTypeArgs.push(replacementType);
2396
- });
2397
- }
2381
+ // Handle tuples specially.
2398
2382
  if (types_1.ClassType.isTupleClass(classType)) {
2399
2383
  if (classType.tupleTypeArguments) {
2400
2384
  newTupleTypeArgs = [];
@@ -2420,6 +2404,66 @@ class TypeVarTransformer {
2420
2404
  specializationNeeded = true;
2421
2405
  }
2422
2406
  }
2407
+ // If this is an empty tuple, don't recompute the non-tuple type argument.
2408
+ if (newTupleTypeArgs && newTupleTypeArgs.length > 0) {
2409
+ // Combine the tuple type args into a single non-tuple type argument.
2410
+ newTypeArgs = [
2411
+ (0, types_1.combineTypes)(newTupleTypeArgs.map((t) => {
2412
+ if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type)) {
2413
+ // Treat the unpacked TypeVarTuple as a union.
2414
+ return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
2415
+ }
2416
+ return t.type;
2417
+ })),
2418
+ ];
2419
+ }
2420
+ }
2421
+ if (!newTypeArgs) {
2422
+ if (classType.typeArguments) {
2423
+ newTypeArgs = classType.typeArguments.map((oldTypeArgType) => {
2424
+ if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.details.isParamSpec) {
2425
+ return transformParamSpec(oldTypeArgType);
2426
+ }
2427
+ let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
2428
+ if (newTypeArgType !== oldTypeArgType) {
2429
+ specializationNeeded = true;
2430
+ // If this was a variadic type variable that was part of a union
2431
+ // (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
2432
+ if ((0, types_1.isTypeVar)(oldTypeArgType) &&
2433
+ (0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
2434
+ oldTypeArgType.isVariadicInUnion) {
2435
+ newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
2436
+ }
2437
+ }
2438
+ return newTypeArgType;
2439
+ });
2440
+ }
2441
+ else {
2442
+ newTypeArgs = [];
2443
+ typeParams.forEach((typeParam) => {
2444
+ let replacementType = typeParam;
2445
+ if (typeParam.details.isParamSpec) {
2446
+ replacementType = transformParamSpec(typeParam);
2447
+ if (replacementType !== typeParam) {
2448
+ specializationNeeded = true;
2449
+ }
2450
+ }
2451
+ else {
2452
+ const typeParamName = types_1.TypeVarType.getNameWithScope(typeParam);
2453
+ if (!this._pendingTypeVarTransformations.has(typeParamName)) {
2454
+ const transformedType = this.transformTypeVar(typeParam, recursionCount);
2455
+ replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
2456
+ if (replacementType !== typeParam) {
2457
+ specializationNeeded = true;
2458
+ }
2459
+ else if (transformedType !== undefined && !classType.typeArguments) {
2460
+ specializationNeeded = true;
2461
+ }
2462
+ }
2463
+ }
2464
+ newTypeArgs.push(replacementType);
2465
+ });
2466
+ }
2423
2467
  }
2424
2468
  this._isTransformingTypeArg = wasTransformingTypeArg;
2425
2469
  // If specialization wasn't needed, don't allocate a new class.
@@ -2430,7 +2474,7 @@ class TypeVarTransformer {
2430
2474
  /* isTypeArgumentExplicit */ true,
2431
2475
  /* includeSubclasses */ undefined, newTupleTypeArgs);
2432
2476
  }
2433
- _transformTypeVarsInFunctionType(sourceType, recursionCount) {
2477
+ transformTypeVarsInFunctionType(sourceType, recursionCount) {
2434
2478
  return this.doForEachSignatureContext(() => {
2435
2479
  let functionType = sourceType;
2436
2480
  // Handle functions with a parameter specification in a special manner.
@@ -2606,6 +2650,32 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
2606
2650
  return undefined;
2607
2651
  }
2608
2652
  }
2653
+ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
2654
+ constructor(_signatureTracker) {
2655
+ super();
2656
+ this._signatureTracker = _signatureTracker;
2657
+ }
2658
+ transformTypeVarsInFunctionType(sourceType, recursionCount) {
2659
+ // If this function is not generic, there's no need to check for uniqueness.
2660
+ if (sourceType.details.typeParameters.length === 0) {
2661
+ return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
2662
+ }
2663
+ let updatedSourceType = sourceType;
2664
+ const existingSignature = this._signatureTracker.findSignature(sourceType);
2665
+ if (existingSignature) {
2666
+ const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(sourceType));
2667
+ // Create new type variables with the same scope but with
2668
+ // different (unique) names.
2669
+ sourceType.details.typeParameters.forEach((typeParam) => {
2670
+ const replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.details.name}(${existingSignature.count})`);
2671
+ typeVarContext.setTypeVarType(typeParam, replacement);
2672
+ updatedSourceType = applySolvedTypeVars(sourceType, typeVarContext);
2673
+ });
2674
+ }
2675
+ this._signatureTracker.addSignature(sourceType);
2676
+ return updatedSourceType;
2677
+ }
2678
+ }
2609
2679
  // Specializes a (potentially generic) type by substituting
2610
2680
  // type variables from a type var map.
2611
2681
  class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {