@zzzen/pyright-internal 1.2.0-dev.20240728 → 1.2.0-dev.20240804

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 (89) hide show
  1. package/dist/analyzer/binder.js +7 -4
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.d.ts +2 -1
  4. package/dist/analyzer/checker.js +135 -83
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/codeFlowEngine.js +4 -4
  7. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  8. package/dist/analyzer/constraintSolution.d.ts +21 -0
  9. package/dist/analyzer/constraintSolution.js +71 -0
  10. package/dist/analyzer/constraintSolution.js.map +1 -0
  11. package/dist/analyzer/constraintSolver.d.ts +9 -5
  12. package/dist/analyzer/constraintSolver.js +420 -322
  13. package/dist/analyzer/constraintSolver.js.map +1 -1
  14. package/dist/analyzer/constraintTracker.d.ts +44 -0
  15. package/dist/analyzer/constraintTracker.js +230 -0
  16. package/dist/analyzer/constraintTracker.js.map +1 -0
  17. package/dist/analyzer/constructorTransform.js +15 -15
  18. package/dist/analyzer/constructorTransform.js.map +1 -1
  19. package/dist/analyzer/constructors.d.ts +1 -1
  20. package/dist/analyzer/constructors.js +59 -38
  21. package/dist/analyzer/constructors.js.map +1 -1
  22. package/dist/analyzer/dataClasses.js +35 -32
  23. package/dist/analyzer/dataClasses.js.map +1 -1
  24. package/dist/analyzer/decorators.js +1 -1
  25. package/dist/analyzer/decorators.js.map +1 -1
  26. package/dist/analyzer/functionTransform.js +1 -1
  27. package/dist/analyzer/functionTransform.js.map +1 -1
  28. package/dist/analyzer/operations.d.ts +1 -2
  29. package/dist/analyzer/operations.js +95 -72
  30. package/dist/analyzer/operations.js.map +1 -1
  31. package/dist/analyzer/packageTypeVerifier.js +8 -4
  32. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  33. package/dist/analyzer/parameterUtils.d.ts +3 -3
  34. package/dist/analyzer/parameterUtils.js +19 -21
  35. package/dist/analyzer/parameterUtils.js.map +1 -1
  36. package/dist/analyzer/patternMatching.js +21 -19
  37. package/dist/analyzer/patternMatching.js.map +1 -1
  38. package/dist/analyzer/properties.d.ts +3 -2
  39. package/dist/analyzer/properties.js +11 -11
  40. package/dist/analyzer/properties.js.map +1 -1
  41. package/dist/analyzer/protocols.d.ts +3 -3
  42. package/dist/analyzer/protocols.js +50 -48
  43. package/dist/analyzer/protocols.js.map +1 -1
  44. package/dist/analyzer/tuples.d.ts +2 -2
  45. package/dist/analyzer/tuples.js +10 -9
  46. package/dist/analyzer/tuples.js.map +1 -1
  47. package/dist/analyzer/typeComplexity.js +12 -4
  48. package/dist/analyzer/typeComplexity.js.map +1 -1
  49. package/dist/analyzer/typeEvaluator.js +806 -778
  50. package/dist/analyzer/typeEvaluator.js.map +1 -1
  51. package/dist/analyzer/typeEvaluatorTypes.d.ts +28 -8
  52. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  53. package/dist/analyzer/typeGuards.js +46 -39
  54. package/dist/analyzer/typeGuards.js.map +1 -1
  55. package/dist/analyzer/typePrinter.js +17 -15
  56. package/dist/analyzer/typePrinter.js.map +1 -1
  57. package/dist/analyzer/typeUtils.d.ts +32 -30
  58. package/dist/analyzer/typeUtils.js +331 -563
  59. package/dist/analyzer/typeUtils.js.map +1 -1
  60. package/dist/analyzer/typeWalker.js +1 -1
  61. package/dist/analyzer/typeWalker.js.map +1 -1
  62. package/dist/analyzer/typedDicts.d.ts +2 -2
  63. package/dist/analyzer/typedDicts.js +25 -25
  64. package/dist/analyzer/typedDicts.js.map +1 -1
  65. package/dist/analyzer/types.d.ts +24 -21
  66. package/dist/analyzer/types.js +110 -113
  67. package/dist/analyzer/types.js.map +1 -1
  68. package/dist/languageServerBase.d.ts +2 -2
  69. package/dist/languageServerBase.js +5 -2
  70. package/dist/languageServerBase.js.map +1 -1
  71. package/dist/languageService/completionProvider.js +2 -2
  72. package/dist/languageService/completionProvider.js.map +1 -1
  73. package/dist/tests/checker.test.js +10 -2
  74. package/dist/tests/checker.test.js.map +1 -1
  75. package/dist/tests/typeEvaluator1.test.js +1 -1
  76. package/dist/tests/typeEvaluator2.test.js +12 -0
  77. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  78. package/dist/tests/typeEvaluator3.test.js +4 -0
  79. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  80. package/dist/tests/typeEvaluator4.test.js +1 -1
  81. package/dist/tests/typeEvaluator5.test.js +1 -1
  82. package/dist/tests/typeEvaluator7.test.js +4 -0
  83. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  84. package/dist/tests/typeEvaluator8.test.js +4 -0
  85. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  86. package/package.json +1 -1
  87. package/dist/analyzer/typeVarContext.d.ts +0 -48
  88. package/dist/analyzer/typeVarContext.js +0 -288
  89. package/dist/analyzer/typeVarContext.js.map +0 -1
@@ -56,6 +56,7 @@ const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
56
56
  const codeFlowEngine_1 = require("./codeFlowEngine");
57
57
  const codeFlowTypes_1 = require("./codeFlowTypes");
58
58
  const constraintSolver_1 = require("./constraintSolver");
59
+ const constraintTracker_1 = require("./constraintTracker");
59
60
  const constructors_1 = require("./constructors");
60
61
  const dataClasses_1 = require("./dataClasses");
61
62
  const declarationUtils_1 = require("./declarationUtils");
@@ -76,12 +77,11 @@ const symbolNameUtils_1 = require("./symbolNameUtils");
76
77
  const symbolUtils_1 = require("./symbolUtils");
77
78
  const tuples_1 = require("./tuples");
78
79
  const typeCacheUtils_1 = require("./typeCacheUtils");
80
+ const typedDicts_1 = require("./typedDicts");
79
81
  const typeEvaluatorTypes_1 = require("./typeEvaluatorTypes");
80
82
  const TypePrinter = __importStar(require("./typePrinter"));
81
- const typeUtils_1 = require("./typeUtils");
82
- const typeVarContext_1 = require("./typeVarContext");
83
- const typedDicts_1 = require("./typedDicts");
84
83
  const types_1 = require("./types");
84
+ const typeUtils_1 = require("./typeUtils");
85
85
  // This table contains the names of several built-in types that
86
86
  // are not subscriptable at runtime on older versions of Python.
87
87
  // It lists the first version of Python where subscripting is
@@ -571,8 +571,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
571
571
  const diag = new diagnostic_1.DiagnosticAddendum();
572
572
  // Make sure the resulting type is assignable to the expected type.
573
573
  if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
574
- /* destTypeVarContext */ undefined,
575
- /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
574
+ /* destConstraints */ undefined,
575
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
576
576
  typeResult.typeErrors = true;
577
577
  typeResult.expectedTypeDiagAddendum = diag;
578
578
  diag.addTextRange(node);
@@ -779,7 +779,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
779
779
  return;
780
780
  }
781
781
  if ((flags & 64 /* EvalFlags.NoTypeVarTuple */) !== 0) {
782
- if ((0, types_1.isTypeVarTuple)(typeResult.type) && !typeResult.type.priv.isVariadicInUnion) {
782
+ if ((0, types_1.isTypeVarTuple)(typeResult.type) && !typeResult.type.priv.isInUnion) {
783
783
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeVarTupleContext(), node);
784
784
  typeResult.type = types_1.UnknownType.create();
785
785
  }
@@ -862,7 +862,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
862
862
  }
863
863
  const iterTypeResult = getTypeOfExpression(node.d.expr, flags, (0, typeUtils_1.makeInferenceContext)(iterExpectedType));
864
864
  const iterType = iterTypeResult.type;
865
- if ((flags & 64 /* EvalFlags.NoTypeVarTuple */) === 0 && (0, types_1.isTypeVarTuple)(iterType) && !iterType.priv.isVariadicUnpacked) {
865
+ if ((flags & 64 /* EvalFlags.NoTypeVarTuple */) === 0 && (0, types_1.isTypeVarTuple)(iterType) && !iterType.priv.isUnpacked) {
866
866
  typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
867
867
  }
868
868
  else if ((flags & 2097152 /* EvalFlags.AllowUnpackedTuple */) !== 0 &&
@@ -1343,6 +1343,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1343
1343
  return subtype;
1344
1344
  });
1345
1345
  }
1346
+ function solveAndApplyConstraints(type, constraints, applyOptions, solveOptions) {
1347
+ if (solveOptions === null || solveOptions === void 0 ? void 0 : solveOptions.applyUnificationVars) {
1348
+ (0, constraintSolver_1.applyUnificationVars)(evaluatorInterface, constraints);
1349
+ }
1350
+ const solution = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints, solveOptions);
1351
+ return (0, typeUtils_1.applySolvedTypeVars)(type, solution, applyOptions);
1352
+ }
1346
1353
  // Gets a member type from an object or class. If it's a function, binds
1347
1354
  // it to the object or class. If selfType is undefined, the binding is done
1348
1355
  // using the objectType parameter. Callers can specify these separately
@@ -1535,7 +1542,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1535
1542
  function addOneFunctionToSignature(type) {
1536
1543
  let callResult;
1537
1544
  useSpeculativeMode(callNode, () => {
1538
- callResult = validateArgs(exprNode, argList, { type }, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
1545
+ callResult = validateArgs(exprNode, argList, { type },
1546
+ /* constraints */ undefined,
1539
1547
  /* skipUnknownArgCheck */ true,
1540
1548
  /* inferenceContext */ undefined);
1541
1549
  });
@@ -1606,7 +1614,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1606
1614
  return functionType;
1607
1615
  }
1608
1616
  (0, debug_1.assert)(kwargsIndex === functionType.shared.parameters.length - 1);
1609
- const kwargsType = types_1.FunctionType.getEffectiveParamType(functionType, kwargsIndex);
1617
+ const kwargsType = types_1.FunctionType.getParamType(functionType, kwargsIndex);
1610
1618
  if (!(0, types_1.isClassInstance)(kwargsType) || !types_1.ClassType.isTypedDictClass(kwargsType) || !kwargsType.priv.isUnpacked) {
1611
1619
  return functionType;
1612
1620
  }
@@ -1707,7 +1715,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1707
1715
  if (baseType && (0, types_1.isClassInstance)(baseType)) {
1708
1716
  const setItemType = getBoundMagicMethod(baseType, '__setitem__');
1709
1717
  if (setItemType && (0, types_1.isFunction)(setItemType) && setItemType.shared.parameters.length >= 2) {
1710
- const paramType = types_1.FunctionType.getEffectiveParamType(setItemType, 1);
1718
+ const paramType = types_1.FunctionType.getParamType(setItemType, 1);
1711
1719
  if (!(0, types_1.isAnyOrUnknown)(paramType)) {
1712
1720
  return paramType;
1713
1721
  }
@@ -1729,7 +1737,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1729
1737
  if (useDescriptorSetterType && (0, types_1.isClassInstance)(declaredType)) {
1730
1738
  const setter = getBoundMagicMethod(declaredType, '__set__');
1731
1739
  if (setter && (0, types_1.isFunction)(setter) && setter.shared.parameters.length >= 2) {
1732
- declaredType = setter.shared.parameters[1].type;
1740
+ declaredType = types_1.FunctionType.getParamType(setter, 1);
1733
1741
  if ((0, types_1.isAnyOrUnknown)(declaredType)) {
1734
1742
  return undefined;
1735
1743
  }
@@ -1766,9 +1774,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1766
1774
  }
1767
1775
  const diag = errorNode ? new diagnostic_1.DiagnosticAddendum() : undefined;
1768
1776
  if ((0, types_1.isClassInstance)(subtype)) {
1769
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(awaitableProtocolObj));
1770
- if (assignType(awaitableProtocolObj, subtype, diag, typeVarContext)) {
1771
- const specializedType = (0, typeUtils_1.applySolvedTypeVars)(awaitableProtocolObj, typeVarContext);
1777
+ const constraints = new constraintTracker_1.ConstraintTracker();
1778
+ if (assignType(awaitableProtocolObj, subtype, diag, constraints)) {
1779
+ const specializedType = solveAndApplyConstraints(awaitableProtocolObj, constraints);
1772
1780
  if ((0, types_1.isClass)(specializedType) &&
1773
1781
  specializedType.priv.typeArgs &&
1774
1782
  specializedType.priv.typeArgs.length > 0) {
@@ -1799,6 +1807,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1799
1807
  type = (0, typeUtils_1.removeNoneFromUnion)(type);
1800
1808
  }
1801
1809
  const iterableType = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1810
+ var _a, _b;
1802
1811
  subtype = makeTopLevelTypeVarsConcrete(subtype);
1803
1812
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
1804
1813
  return subtype;
@@ -1812,18 +1821,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1812
1821
  subtype.priv.tupleTypeArgs.length === 0) {
1813
1822
  return types_1.NeverType.createNever();
1814
1823
  }
1815
- const iterReturnType = getTypeOfMagicMethodCall(subtype, iterMethodName, [], errorNode);
1824
+ const iterReturnType = (_a = getTypeOfMagicMethodCall(subtype, iterMethodName, [], errorNode)) === null || _a === void 0 ? void 0 : _a.type;
1816
1825
  if (!iterReturnType) {
1817
1826
  // There was no __iter__. See if we can fall back to
1818
1827
  // the __getitem__ method instead.
1819
1828
  if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
1820
- const getItemReturnType = getTypeOfMagicMethodCall(subtype, '__getitem__', [
1829
+ const getItemReturnType = (_b = getTypeOfMagicMethodCall(subtype, '__getitem__', [
1821
1830
  {
1822
1831
  type: intClass && (0, types_1.isInstantiableClass)(intClass)
1823
1832
  ? types_1.ClassType.cloneAsInstance(intClass)
1824
1833
  : types_1.UnknownType.create(),
1825
1834
  },
1826
- ], errorNode);
1835
+ ], errorNode)) === null || _b === void 0 ? void 0 : _b.type;
1827
1836
  if (getItemReturnType) {
1828
1837
  return getItemReturnType;
1829
1838
  }
@@ -1833,10 +1842,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1833
1842
  else {
1834
1843
  const iterReturnTypeDiag = new diagnostic_1.DiagnosticAddendum();
1835
1844
  const returnType = mapSubtypesExpandTypeVars(iterReturnType, /* options */ undefined, (subtype) => {
1845
+ var _a;
1836
1846
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
1837
1847
  return subtype;
1838
1848
  }
1839
- let nextReturnType = getTypeOfMagicMethodCall(subtype, nextMethodName, [], errorNode);
1849
+ let nextReturnType = (_a = getTypeOfMagicMethodCall(subtype, nextMethodName, [], errorNode)) === null || _a === void 0 ? void 0 : _a.type;
1840
1850
  if (!nextReturnType) {
1841
1851
  iterReturnTypeDiag.addMessage(localize_1.LocMessage.methodNotDefinedOnType().format({
1842
1852
  name: nextMethodName,
@@ -1887,11 +1897,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1887
1897
  type = (0, typeUtils_1.removeNoneFromUnion)(type);
1888
1898
  }
1889
1899
  const iterableType = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1900
+ var _a;
1890
1901
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
1891
1902
  return subtype;
1892
1903
  }
1893
1904
  if ((0, types_1.isClass)(subtype)) {
1894
- const iterReturnType = getTypeOfMagicMethodCall(subtype, iterMethodName, [], errorNode);
1905
+ const iterReturnType = (_a = getTypeOfMagicMethodCall(subtype, iterMethodName, [], errorNode)) === null || _a === void 0 ? void 0 : _a.type;
1895
1906
  if (iterReturnType) {
1896
1907
  return makeTopLevelTypeVarsConcrete(iterReturnType);
1897
1908
  }
@@ -2332,7 +2343,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2332
2343
  if (enclosingClass === null || enclosingClass === void 0 ? void 0 : enclosingClass.shared.typeVarScopeId) {
2333
2344
  memberResultToCache = {
2334
2345
  ...resultToCache,
2335
- type: (0, typeUtils_1.updateTypeWithExternalTypeVars)(resultToCache.type, [enclosingClass.shared.typeVarScopeId]),
2346
+ type: (0, typeUtils_1.makeTypeVarsFree)(resultToCache.type, [enclosingClass.shared.typeVarScopeId]),
2336
2347
  memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
2337
2348
  };
2338
2349
  }
@@ -2561,16 +2572,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2561
2572
  }
2562
2573
  }
2563
2574
  // If this is a function that contains only a ParamSpec (no additional
2564
- // parameters), convert it to a concrete type of (*args: Any, **kwargs: Any).
2575
+ // parameters), convert it to a concrete type of (*args: Unknown, **kwargs: Unknown).
2565
2576
  if (makeParamSpecsConcrete && (0, types_1.isFunction)(subtype)) {
2566
- const convertedType = (0, typeUtils_1.convertParamSpecValueToType)(subtype);
2577
+ const convertedType = (0, typeUtils_1.simplifyFunctionToParamSpec)(subtype);
2567
2578
  if ((0, types_1.isParamSpec)(convertedType)) {
2568
- return types_1.FunctionType.applyParamSpecValue(subtype, (0, typeUtils_1.getUnknownTypeForCallable)());
2579
+ return types_1.ParamSpecType.getUnknown();
2569
2580
  }
2570
2581
  }
2571
2582
  if ((0, types_1.isTypeVarTuple)(subtype)) {
2572
2583
  // If it's in a union, convert to type or object.
2573
- if (subtype.priv.isVariadicInUnion) {
2584
+ if (subtype.priv.isInUnion) {
2574
2585
  if (types_1.TypeBase.isInstantiable(subtype)) {
2575
2586
  if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
2576
2587
  return typeClass;
@@ -2590,7 +2601,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2590
2601
  if (subtype.shared.recursiveAlias) {
2591
2602
  return subtype;
2592
2603
  }
2593
- if (subtype.shared.constraints.length > 0) {
2604
+ if (types_1.TypeVarType.hasConstraints(subtype)) {
2594
2605
  const typesToCombine = [];
2595
2606
  // Expand the list of constrained subtypes, filtering out any that are
2596
2607
  // disallowed by the conditionFilter.
@@ -2617,9 +2628,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2617
2628
  // Fall back to a bound of "object" if no bound is provided.
2618
2629
  let boundType = (_a = subtype.shared.boundType) !== null && _a !== void 0 ? _a : getObjectType();
2619
2630
  // If this is a synthesized self/cls type var, self-specialize its type arguments.
2620
- if (subtype.shared.isSynthesizedSelf && (0, types_1.isClass)(boundType)) {
2631
+ if (types_1.TypeVarType.isSelf(subtype) && (0, types_1.isClass)(boundType) && !types_1.ClassType.isPseudoGenericClass(boundType)) {
2621
2632
  boundType = (0, typeUtils_1.selfSpecializeClass)(boundType, {
2622
- useInternalTypeVars: types_1.TypeVarType.hasInternalScopeId(subtype),
2633
+ useBoundTypeVars: types_1.TypeVarType.isBound(subtype),
2623
2634
  });
2624
2635
  }
2625
2636
  boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
@@ -2658,7 +2669,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2658
2669
  }
2659
2670
  if (transformedType) {
2660
2671
  // Apply the type condition if it's associated with a constrained TypeVar.
2661
- const typeCondition = (_a = (0, typeUtils_1.getTypeCondition)(subtype)) === null || _a === void 0 ? void 0 : _a.filter((condition) => condition.typeVar.shared.constraints.length > 0);
2672
+ const typeCondition = (_a = (0, typeUtils_1.getTypeCondition)(subtype)) === null || _a === void 0 ? void 0 : _a.filter((condition) => types_1.TypeVarType.hasConstraints(condition.typeVar));
2662
2673
  if (typeCondition && typeCondition.length > 0) {
2663
2674
  transformedType = (0, typeUtils_1.addConditionToType)(transformedType, typeCondition);
2664
2675
  }
@@ -3210,22 +3221,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3210
3221
  if (!type.priv.scopeId) {
3211
3222
  type = assignTypeVarScopeId(node, type, flags);
3212
3223
  }
3213
- // If this TypeVar has an external scope ID, see if we need to
3214
- // make it into an internal scope ID instead.
3215
- if (type.priv.scopeId && !types_1.TypeVarType.hasInternalScopeId(type)) {
3224
+ // If this is a free type var, see if we need to make it into a bound type var.
3225
+ if (type.priv.scopeId && !types_1.TypeVarType.isBound(type)) {
3216
3226
  // If this is a reference to a TypeVar defined in an outer scope,
3217
- // change it to have an internal scope ID.
3227
+ // mark it as bound.
3218
3228
  const scopedNode = (_a = findScopedTypeVar(node, type)) === null || _a === void 0 ? void 0 : _a.scopeNode;
3219
3229
  if (scopedNode) {
3220
3230
  const enclosingSuite = ParseTreeUtils.getEnclosingClassOrFunctionSuite(node);
3221
3231
  if (enclosingSuite && ParseTreeUtils.isNodeContainedWithin(enclosingSuite, scopedNode)) {
3222
3232
  if (scopedNode.nodeType !== 10 /* ParseNodeType.Class */ || scopedNode.d.suite !== enclosingSuite) {
3223
- type = types_1.TypeVarType.cloneWithInternalScopeId(type);
3233
+ type = types_1.TypeVarType.cloneAsBound(type);
3224
3234
  }
3225
3235
  }
3226
3236
  }
3227
3237
  }
3228
- // If this type var is variadic, the name refers to the packed form. It
3238
+ // If this is a TypeVarTuple, the name refers to the packed form. It
3229
3239
  // must be unpacked in most contexts.
3230
3240
  if ((0, types_1.isUnpackedTypeVarTuple)(type)) {
3231
3241
  type = types_1.TypeVarType.cloneForPacked(type);
@@ -3318,7 +3328,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3318
3328
  // an outer class that contains the class definition.
3319
3329
  function enforceClassTypeVarScope(node, type) {
3320
3330
  var _a, _b;
3321
- const scopeId = (_b = (_a = type.priv.externalTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) !== null && _b !== void 0 ? _b : type.priv.scopeId;
3331
+ const scopeId = (_b = (_a = type.priv.freeTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) !== null && _b !== void 0 ? _b : type.priv.scopeId;
3322
3332
  if (!scopeId) {
3323
3333
  return true;
3324
3334
  }
@@ -3366,16 +3376,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3366
3376
  !aliasInfo.typeArgs) {
3367
3377
  let reportMissingTypeArgs = false;
3368
3378
  const defaultTypeArgs = [];
3369
- const typeVarContext = new typeVarContext_1.TypeVarContext(aliasInfo.typeVarScopeId);
3379
+ const constraints = new constraintTracker_1.ConstraintTracker();
3370
3380
  aliasInfo.typeParams.forEach((param) => {
3371
3381
  if (!param.shared.isDefaultExplicit) {
3372
3382
  reportMissingTypeArgs = true;
3373
3383
  }
3374
3384
  let defaultType;
3375
3385
  if (param.shared.isDefaultExplicit || (0, types_1.isParamSpec)(param)) {
3376
- defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, {
3377
- unknownIfNotFound: true,
3378
- tupleClassType: getTupleClassType(),
3386
+ defaultType = solveAndApplyConstraints(param, constraints, {
3387
+ replaceUnsolved: {
3388
+ scopeIds: [aliasInfo.typeVarScopeId],
3389
+ tupleClassType: getTupleClassType(),
3390
+ },
3379
3391
  });
3380
3392
  }
3381
3393
  else if ((0, types_1.isTypeVarTuple)(param) && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
@@ -3386,17 +3398,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3386
3398
  defaultType = types_1.UnknownType.create();
3387
3399
  }
3388
3400
  defaultTypeArgs.push(defaultType);
3389
- (0, typeUtils_1.setTypeVarType)(typeVarContext, param, defaultType);
3401
+ constraints.setBounds(param, defaultType);
3390
3402
  });
3391
3403
  if (reportMissingTypeArgs) {
3392
3404
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.typeArgsMissingForAlias().format({
3393
3405
  name: aliasInfo.name,
3394
3406
  }), node);
3395
3407
  }
3396
- type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, {
3397
- unknownIfNotFound: true,
3398
- tupleClassType: getTupleClassType(),
3399
- }), aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParams, defaultTypeArgs);
3408
+ type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(type, constraints, {
3409
+ replaceUnsolved: {
3410
+ scopeIds: [aliasInfo.typeVarScopeId],
3411
+ tupleClassType: getTupleClassType(),
3412
+ },
3413
+ }), { ...aliasInfo, typeArgs: defaultTypeArgs });
3400
3414
  }
3401
3415
  return type;
3402
3416
  }
@@ -4161,7 +4175,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4161
4175
  return { type: types_1.AnyType.create(), typeErrors: true };
4162
4176
  }
4163
4177
  if (classType.shared.typeVarScopeId) {
4164
- memberType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(memberType, [classType.shared.typeVarScopeId]);
4178
+ memberType = (0, typeUtils_1.makeTypeVarsBound)(memberType, [classType.shared.typeVarScopeId]);
4165
4179
  }
4166
4180
  return { type: memberType };
4167
4181
  }
@@ -4208,11 +4222,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4208
4222
  accessMethodClass = (_c = concreteMemberType.priv.fdelInfo) === null || _c === void 0 ? void 0 : _c.classType;
4209
4223
  }
4210
4224
  if (accessMethodClass) {
4211
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(accessMethodClass));
4225
+ const constraints = new constraintTracker_1.ConstraintTracker();
4212
4226
  accessMethodClass = (0, typeUtils_1.selfSpecializeClass)(accessMethodClass);
4213
4227
  assignType(types_1.ClassType.cloneAsInstance(accessMethodClass), types_1.ClassType.cloneAsInstance(memberInfo.classType),
4214
- /* diag */ undefined, typeVarContext);
4215
- accessMethodClass = (0, typeUtils_1.applySolvedTypeVars)(accessMethodClass, typeVarContext);
4228
+ /* diag */ undefined, constraints);
4229
+ accessMethodClass = solveAndApplyConstraints(accessMethodClass, constraints);
4216
4230
  const specializedType = (0, typeUtils_1.partiallySpecializeType)(methodType, accessMethodClass, getTypeClassType(), selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : classType);
4217
4231
  if ((0, types_1.isFunction)(specializedType) || (0, types_1.isOverloadedFunction)(specializedType)) {
4218
4232
  methodType = specializedType;
@@ -4284,7 +4298,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4284
4298
  // Suppress diagnostics for these method calls because they would be redundant.
4285
4299
  const callResult = suppressDiagnostics(errorNode, () => {
4286
4300
  return validateCallArgs(errorNode, argList, { type: methodType },
4287
- /* typeVarContext */ undefined,
4301
+ /* constraints */ undefined,
4288
4302
  /* skipUnknownArgCheck */ true,
4289
4303
  /* inferenceContext */ undefined);
4290
4304
  }, (suppressedDiags) => {
@@ -4369,7 +4383,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4369
4383
  if ((0, types_1.isFunction)(getterType) && (0, types_1.isFunction)(setterType)) {
4370
4384
  // If there's no declared return type on the getter, assume it's symmetric.
4371
4385
  if (setterType.shared.parameters.length >= 3 && getterType.shared.declaredReturnType) {
4372
- const setterValueType = types_1.FunctionType.getEffectiveParamType(setterType, 2);
4386
+ const setterValueType = types_1.FunctionType.getParamType(setterType, 2);
4373
4387
  const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
4374
4388
  if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
4375
4389
  isAsymmetric = true;
@@ -4401,7 +4415,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4401
4415
  if ((0, types_1.isFunction)(getterType) && (0, types_1.isFunction)(setterType)) {
4402
4416
  // If there's no declared return type on the getter, assume it's symmetric.
4403
4417
  if (setterType.shared.parameters.length >= 3 && getterType.shared.declaredReturnType) {
4404
- const setterValueType = types_1.FunctionType.getEffectiveParamType(setterType, 2);
4418
+ const setterValueType = types_1.FunctionType.getParamType(setterType, 2);
4405
4419
  const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
4406
4420
  if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
4407
4421
  isAsymmetric = true;
@@ -4467,8 +4481,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4467
4481
  // TODO - emit an error for this condition.
4468
4482
  return undefined;
4469
4483
  }
4470
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(accessMemberType));
4471
- const callResult = validateCallArgs(errorNode, argList, { type: accessMemberType }, typeVarContext,
4484
+ const callResult = validateCallArgs(errorNode, argList, { type: accessMemberType },
4485
+ /* constraints */ undefined,
4472
4486
  /* skipUnknownArgCheck */ true,
4473
4487
  /* inferenceContext */ undefined);
4474
4488
  let isAsymmetricAccessor = false;
@@ -4577,7 +4591,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4577
4591
  srcUnboundedTupleIndex >= 0 &&
4578
4592
  variadicIndex >= 0 &&
4579
4593
  typeArgs.length < typeParams.length) {
4580
- // "Smear" the tuple type across type argument slots prior to the variadic type var.
4594
+ // "Smear" the tuple type across type argument slots prior to the TypeVarTuple.
4581
4595
  while (variadicIndex > srcUnboundedTupleIndex) {
4582
4596
  typeArgs = [
4583
4597
  ...typeArgs.slice(0, srcUnboundedTupleIndex),
@@ -4586,7 +4600,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4586
4600
  ];
4587
4601
  srcUnboundedTupleIndex++;
4588
4602
  }
4589
- // "Smear" the tuple type across type argument slots following the variadic type var.
4603
+ // "Smear" the tuple type across type argument slots following the TypeVarTuple.
4590
4604
  while (typeArgs.length < typeParams.length) {
4591
4605
  typeArgs = [
4592
4606
  ...typeArgs.slice(0, srcUnboundedTupleIndex + 1),
@@ -4667,7 +4681,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4667
4681
  }
4668
4682
  // If the variadic type variable is not unpacked, report an error.
4669
4683
  function validateTypeVarTupleIsUnpacked(type, node) {
4670
- if (!type.priv.isVariadicUnpacked) {
4684
+ if (!type.priv.isUnpacked) {
4671
4685
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
4672
4686
  name1: type.shared.name,
4673
4687
  name2: type.shared.name,
@@ -4734,7 +4748,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4734
4748
  typeArgs.length >= 1) {
4735
4749
  return { node, type: typeArgs[0].type };
4736
4750
  }
4737
- const typeVarContext = new typeVarContext_1.TypeVarContext(aliasInfo.typeVarScopeId);
4751
+ const constraints = new constraintTracker_1.ConstraintTracker();
4738
4752
  const diag = new diagnostic_1.DiagnosticAddendum();
4739
4753
  typeParams.forEach((param, index) => {
4740
4754
  if ((0, types_1.isParamSpec)(param) && index < typeArgs.length) {
@@ -4748,10 +4762,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4748
4762
  if (typeList.length > 0) {
4749
4763
  types_1.FunctionType.addPositionOnlyParamSeparator(functionType);
4750
4764
  }
4751
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4765
+ (0, constraintSolver_1.assignTypeVar)(evaluatorInterface, param, functionType, diag, constraints, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4752
4766
  }
4753
4767
  else if ((0, types_1.isParamSpec)(typeArgType)) {
4754
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, (0, typeUtils_1.convertToInstance)(typeArgType), diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4768
+ (0, constraintSolver_1.assignTypeVar)(evaluatorInterface, param, (0, typeUtils_1.convertToInstance)(typeArgType), diag, constraints, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4755
4769
  }
4756
4770
  else if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isBuiltIn(typeArgType, 'Concatenate')) {
4757
4771
  const concatTypeArgs = typeArgType.priv.typeArgs;
@@ -4773,12 +4787,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4773
4787
  }
4774
4788
  });
4775
4789
  }
4776
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4790
+ (0, constraintSolver_1.assignTypeVar)(evaluatorInterface, param, functionType, diag, constraints, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4777
4791
  }
4778
4792
  else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
4779
4793
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
4780
4794
  types_1.FunctionType.addDefaultParams(functionType);
4781
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
4795
+ (0, constraintSolver_1.assignTypeVar)(evaluatorInterface, param, functionType, diag, constraints);
4782
4796
  }
4783
4797
  else {
4784
4798
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgListExpected(), typeArgs[index].node);
@@ -4793,9 +4807,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4793
4807
  typeArgType = (0, typeUtils_1.convertToInstance)(typeArgs[index].type);
4794
4808
  }
4795
4809
  else if (param.shared.isDefaultExplicit) {
4796
- typeArgType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, {
4797
- unknownIfNotFound: true,
4798
- tupleClassType: getTupleClassType(),
4810
+ typeArgType = solveAndApplyConstraints(param, constraints, {
4811
+ replaceUnsolved: {
4812
+ scopeIds: [aliasInfo.typeVarScopeId],
4813
+ tupleClassType: getTupleClassType(),
4814
+ },
4799
4815
  });
4800
4816
  }
4801
4817
  else {
@@ -4821,34 +4837,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4821
4837
  messageDiag.addTextRange(typeArgs[index].node);
4822
4838
  typeArgType = types_1.UnknownType.create();
4823
4839
  }
4824
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4840
+ (0, constraintSolver_1.assignTypeVar)(evaluatorInterface, param, typeArgType, diag, constraints, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4825
4841
  }
4826
4842
  });
4827
4843
  if (!diag.isEmpty()) {
4828
4844
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeNotSpecializable().format({ type: printType(baseType) }) + diag.getString(), node, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : node);
4829
4845
  }
4830
- const mainSolutionSet = typeVarContext.getMainSolutionSet();
4846
+ const solutionSet = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints).getMainSolutionSet();
4831
4847
  const aliasTypeArgs = [];
4832
4848
  (_c = aliasInfo.typeParams) === null || _c === void 0 ? void 0 : _c.forEach((typeParam) => {
4833
- let typeVarType;
4834
- if ((0, types_1.isParamSpec)(typeParam)) {
4835
- const paramSpecType = mainSolutionSet.getTypeVarType(typeParam);
4836
- typeVarType = paramSpecType ? (0, typeUtils_1.convertParamSpecValueToType)(paramSpecType) : types_1.UnknownType.create();
4837
- if (!typeVarType) {
4838
- typeVarType = types_1.ParamSpecType.getUnknown();
4839
- mainSolutionSet.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(typeVarType));
4840
- }
4841
- }
4842
- else {
4843
- typeVarType = mainSolutionSet.getTypeVarType(typeParam);
4844
- if (!typeVarType) {
4845
- typeVarType = types_1.UnknownType.create();
4846
- mainSolutionSet.setTypeVarType(typeParam, typeVarType);
4847
- }
4849
+ let typeVarType = solutionSet.getType(typeParam);
4850
+ // Fill in any unsolved type arguments with unknown.
4851
+ if (!typeVarType) {
4852
+ typeVarType = (0, typeUtils_1.getUnknownForTypeVar)(typeParam, getTupleClassType());
4853
+ constraints.setBounds(typeParam, typeVarType);
4848
4854
  }
4849
4855
  aliasTypeArgs.push(typeVarType);
4850
4856
  });
4851
- const type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(baseType, typeVarContext), aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParams, aliasTypeArgs);
4857
+ const type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(baseType, constraints), {
4858
+ ...aliasInfo,
4859
+ typeArgs: aliasTypeArgs,
4860
+ });
4852
4861
  return { type, node };
4853
4862
  }
4854
4863
  function getTypeOfIndexWithBaseType(node, baseTypeResult, usage, flags) {
@@ -4859,7 +4868,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4859
4868
  }
4860
4869
  if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
4861
4870
  const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
4862
- const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.shared.recursiveAlias.name, '', '', uri_1.Uri.empty(), baseTypeResult.type.shared.recursiveAlias.scopeId, !!baseTypeResult.type.shared.recursiveAlias.isPep695Syntax, baseTypeResult.type.shared.recursiveAlias.typeParams, typeArgTypes);
4871
+ const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, {
4872
+ name: baseTypeResult.type.shared.recursiveAlias.name,
4873
+ fullName: '',
4874
+ moduleName: '',
4875
+ fileUri: uri_1.Uri.empty(),
4876
+ typeVarScopeId: baseTypeResult.type.shared.recursiveAlias.scopeId,
4877
+ isPep695Syntax: !!baseTypeResult.type.shared.recursiveAlias.isPep695Syntax,
4878
+ typeParams: baseTypeResult.type.shared.recursiveAlias.typeParams,
4879
+ usageVariance: undefined,
4880
+ typeArgs: typeArgTypes,
4881
+ });
4863
4882
  return { type };
4864
4883
  }
4865
4884
  let isIncomplete = baseTypeResult.isIncomplete;
@@ -5229,7 +5248,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5229
5248
  if (usage.method === 'set') {
5230
5249
  let setType = (_b = (_a = usage.setType) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.AnyType.create();
5231
5250
  // Expand constrained type variables.
5232
- if ((0, types_1.isTypeVar)(setType) && setType.shared.constraints.length > 0) {
5251
+ if ((0, types_1.isTypeVar)(setType) && types_1.TypeVarType.hasConstraints(setType)) {
5233
5252
  const conditionFilter = (0, types_1.isClassInstance)(baseType) ? (_c = baseType.props) === null || _c === void 0 ? void 0 : _c.condition : undefined;
5234
5253
  setType = makeTopLevelTypeVarsConcrete(setType,
5235
5254
  /* makeParamSpecsConcrete */ undefined, conditionFilter);
@@ -5258,7 +5277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5258
5277
  });
5259
5278
  });
5260
5279
  const callResult = validateCallArgs(node, argList, { type: itemMethodType },
5261
- /* typeVarContext */ undefined,
5280
+ /* constraints */ undefined,
5262
5281
  /* skipUnknownArgCheck */ true,
5263
5282
  /* inferenceContext */ undefined);
5264
5283
  return {
@@ -5348,7 +5367,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5348
5367
  if (arg.d.argCategory !== 0 /* ArgCategory.Simple */) {
5349
5368
  if (arg.d.argCategory === 1 /* ArgCategory.UnpackedList */) {
5350
5369
  if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass) || index === 0) {
5351
- if ((0, types_1.isTypeVarTuple)(typeResult.type) && !typeResult.type.priv.isVariadicUnpacked) {
5370
+ if ((0, types_1.isTypeVarTuple)(typeResult.type) && !typeResult.type.priv.isUnpacked) {
5352
5371
  typeResult.type = types_1.TypeVarType.cloneForUnpacked(typeResult.type);
5353
5372
  }
5354
5373
  else if ((0, types_1.isInstantiableClass)(typeResult.type) &&
@@ -5483,11 +5502,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5483
5502
  }
5484
5503
  }
5485
5504
  else {
5486
- const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClass));
5487
- if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClass), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
5505
+ const tupleConstraints = new constraintTracker_1.ConstraintTracker();
5506
+ if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClass), inferenceContext.expectedType, tupleConstraints, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
5488
5507
  return undefined;
5489
5508
  }
5490
- const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClass, tupleTypeVarContext);
5509
+ const specializedTuple = solveAndApplyConstraints(tupleClass, tupleConstraints);
5491
5510
  if (!specializedTuple.priv.typeArgs || specializedTuple.priv.typeArgs.length !== 1) {
5492
5511
  return undefined;
5493
5512
  }
@@ -5628,7 +5647,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5628
5647
  }
5629
5648
  else {
5630
5649
  const callResult = validateCallArgs(node, argList, baseTypeResult,
5631
- /* typeVarContext */ undefined,
5650
+ /* constraints */ undefined,
5632
5651
  /* skipUnknownArgCheck */ false, inferenceContext);
5633
5652
  typeResult.type = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
5634
5653
  if (callResult.argumentErrors) {
@@ -5932,9 +5951,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5932
5951
  types_1.FunctionType.isInstanceMethod(methodType)) {
5933
5952
  if (methodType.shared.parameters.length > 0 &&
5934
5953
  types_1.FunctionParam.isTypeDeclared(methodType.shared.parameters[0])) {
5935
- let paramType = methodType.shared.parameters[0].type;
5954
+ let paramType = types_1.FunctionType.getParamType(methodType, 0);
5936
5955
  const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(node);
5937
- paramType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(paramType, liveScopeIds);
5956
+ paramType = (0, typeUtils_1.makeTypeVarsBound)(paramType, liveScopeIds);
5938
5957
  implicitBindToType = makeTopLevelTypeVarsConcrete(paramType);
5939
5958
  }
5940
5959
  }
@@ -5985,7 +6004,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5985
6004
  effectiveTargetClass = undefined;
5986
6005
  }
5987
6006
  if (bindToType) {
5988
- bindToType = (0, typeUtils_1.selfSpecializeClass)(bindToType, { useInternalTypeVars: true });
6007
+ bindToType = (0, typeUtils_1.selfSpecializeClass)(bindToType, { useBoundTypeVars: true });
5989
6008
  }
5990
6009
  const lookupResults = bindToType
5991
6010
  ? (0, typeUtils_1.lookUpClassMember)(bindToType, memberName, 0 /* MemberAccessFlags.Default */, effectiveTargetClass)
@@ -6009,8 +6028,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6009
6028
  }
6010
6029
  let bindToSelfType;
6011
6030
  if (bindToType) {
6012
- bindToSelfType = types_1.TypeBase.cloneForCondition(types_1.TypeVarType.cloneWithInternalScopeId((0, typeUtils_1.synthesizeTypeVarForSelfCls)(types_1.ClassType.cloneIncludeSubclasses(bindToType, /* includeSubclasses */ false),
6013
- /* isClsParam */ false)), (_b = bindToType.props) === null || _b === void 0 ? void 0 : _b.condition);
6031
+ if (node.d.args.length > 1) {
6032
+ // If this is a two-argument form of super(), use the
6033
+ // bindToType evaluated from the arguments.
6034
+ bindToSelfType = (0, typeUtils_1.convertToInstance)(bindToType);
6035
+ }
6036
+ else {
6037
+ // If this is a zero-argument form of super(), synthesize
6038
+ // a Self type to bind to.
6039
+ bindToSelfType = types_1.TypeBase.cloneForCondition(types_1.TypeVarType.cloneAsBound((0, typeUtils_1.synthesizeTypeVarForSelfCls)(types_1.ClassType.cloneIncludeSubclasses(bindToType, /* includeSubclasses */ false),
6040
+ /* isClsParam */ false)), (_b = bindToType.props) === null || _b === void 0 ? void 0 : _b.condition);
6041
+ }
6014
6042
  }
6015
6043
  const type = resultIsInstance ? (0, typeUtils_1.convertToInstance)(resultType, /* includeSubclasses */ false) : resultType;
6016
6044
  return { type, bindToSelfType };
@@ -6097,7 +6125,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6097
6125
  // there will be only one argument list in expandedArgTypes, and all entries
6098
6126
  // (one for each argument) will be undefined. On subsequent calls, this
6099
6127
  // list will grow to include union expansions.
6100
- function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6128
+ function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, constraints, skipUnknownArgCheck, inferenceContext) {
6101
6129
  var _a, _b;
6102
6130
  const returnTypes = [];
6103
6131
  const matchedOverloads = [];
@@ -6126,14 +6154,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6126
6154
  return argParamCopy;
6127
6155
  });
6128
6156
  }
6129
- // Clone the typeVarContext so we don't modify the original.
6130
- const effectiveTypeVarContext = (_a = typeVarContext === null || typeVarContext === void 0 ? void 0 : typeVarContext.clone()) !== null && _a !== void 0 ? _a : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overload));
6131
- effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(overload));
6132
- effectiveTypeVarContext.unlock();
6157
+ // Clone the constraints so we don't modify the original.
6158
+ const effectiveConstraints = (_a = constraints === null || constraints === void 0 ? void 0 : constraints.clone()) !== null && _a !== void 0 ? _a : new constraintTracker_1.ConstraintTracker();
6159
+ effectiveConstraints.unlock();
6133
6160
  // Use speculative mode so we don't output any diagnostics or
6134
6161
  // record any final types in the type cache.
6135
6162
  const callResult = useSpeculativeMode(speculativeNode, () => {
6136
- return validateArgTypesWithContext(errorNode, matchResults, effectiveTypeVarContext,
6163
+ return validateArgTypesWithContext(errorNode, matchResults, effectiveConstraints,
6137
6164
  /* skipUnknownArgCheck */ true, inferenceContext);
6138
6165
  });
6139
6166
  if (callResult.isTypeIncomplete) {
@@ -6145,7 +6172,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6145
6172
  const matchedOverloadInfo = {
6146
6173
  overload: matchedOverload,
6147
6174
  matchResults,
6148
- typeVarContext: effectiveTypeVarContext,
6175
+ constraints: effectiveConstraints,
6149
6176
  returnType: callResult.returnType,
6150
6177
  argResults: (_b = callResult.argResults) !== null && _b !== void 0 ? _b : [],
6151
6178
  };
@@ -6235,15 +6262,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6235
6262
  // resulting type var context back into the caller's type var context.
6236
6263
  // Use the type var context from the last matched overload because it
6237
6264
  // includes the type var solutions for all earlier matched overloads.
6238
- if (typeVarContext && isDefinitiveMatchFound) {
6239
- typeVarContext.copyFromClone(matchedOverloads[matchedOverloads.length - 1].typeVarContext);
6265
+ if (constraints && isDefinitiveMatchFound) {
6266
+ constraints.copyFromClone(matchedOverloads[matchedOverloads.length - 1].constraints);
6240
6267
  }
6241
6268
  // And run through the first expanded argument list one more time to
6242
6269
  // populate the type cache.
6243
- const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
6244
- finalTypeVarContext.unlock();
6245
- finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
6246
- const finalCallResult = validateArgTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
6270
+ const finalConstraints = constraints !== null && constraints !== void 0 ? constraints : matchedOverloads[0].constraints;
6271
+ finalConstraints.unlock();
6272
+ const finalCallResult = validateArgTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalConstraints, skipUnknownArgCheck, inferenceContext);
6247
6273
  if (finalCallResult.isTypeIncomplete) {
6248
6274
  isTypeIncomplete = true;
6249
6275
  }
@@ -6323,7 +6349,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6323
6349
  matches.forEach((match, matchIndex) => {
6324
6350
  if (winningOverloadIndex === undefined) {
6325
6351
  useSpeculativeMode(speculativeNode, () => {
6326
- const callResult = validateArgTypes(errorNode, match, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(match.overload)),
6352
+ const callResult = validateArgTypes(errorNode, match, new constraintTracker_1.ConstraintTracker(),
6327
6353
  /* skipUnknownArgCheck */ true);
6328
6354
  if (callResult && !callResult.argumentErrors) {
6329
6355
  winningOverloadIndex = matchIndex;
@@ -6342,7 +6368,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6342
6368
  return a.overloadIndex - b.overloadIndex;
6343
6369
  });
6344
6370
  }
6345
- function validateOverloadedArgTypes(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6371
+ function validateOverloadedArgTypes(errorNode, argList, typeResult, constraints, skipUnknownArgCheck, inferenceContext) {
6346
6372
  let filteredMatchResults = [];
6347
6373
  let contextFreeArgTypes;
6348
6374
  let isTypeIncomplete = !!typeResult.isIncomplete;
@@ -6412,10 +6438,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6412
6438
  diagnostic.addRelatedInfo(localize_1.LocAddendum.overloadIndex().format({ index: bestMatch.overloadIndex + 1 }), overrideDecl.uri, overrideDecl.range);
6413
6439
  }
6414
6440
  }
6415
- const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
6416
- effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(bestMatch.overload));
6417
- effectiveTypeVarContext.unlock();
6418
- return validateArgTypesWithContext(errorNode, bestMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6441
+ const effectiveConstraints = constraints !== null && constraints !== void 0 ? constraints : new constraintTracker_1.ConstraintTracker();
6442
+ effectiveConstraints.unlock();
6443
+ return validateArgTypesWithContext(errorNode, bestMatch, effectiveConstraints, skipUnknownArgCheck, inferenceContext);
6419
6444
  }
6420
6445
  // If there is only one possible arg/param match among the overloads,
6421
6446
  // use the normal type matching mechanism because it is faster and
@@ -6427,7 +6452,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6427
6452
  }
6428
6453
  let expandedArgTypes = [argList.map((arg) => undefined)];
6429
6454
  while (true) {
6430
- const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
6455
+ const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, constraints, skipUnknownArgCheck, inferenceContext);
6431
6456
  if (callResult.isTypeIncomplete) {
6432
6457
  isTypeIncomplete = true;
6433
6458
  }
@@ -6500,7 +6525,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6500
6525
  unionToExpand = makeTopLevelTypeVarsConcrete(argType);
6501
6526
  break;
6502
6527
  }
6503
- else if ((0, types_1.isTypeVar)(argType) && argType.shared.constraints.length > 1) {
6528
+ else if ((0, types_1.isTypeVar)(argType) && types_1.TypeVarType.hasConstraints(argType)) {
6504
6529
  unionToExpand = makeTopLevelTypeVarsConcrete(argType);
6505
6530
  break;
6506
6531
  }
@@ -6525,7 +6550,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6525
6550
  // list, specializes the call based on arg types, and returns the
6526
6551
  // specialized type of the return value. If it detects an error along
6527
6552
  // the way, it emits a diagnostic and sets argumentErrors to true.
6528
- function validateCallArgs(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount = 0) {
6553
+ function validateCallArgs(errorNode, argList, callTypeResult, constraints, skipUnknownArgCheck, inferenceContext, recursionCount = 0) {
6529
6554
  var _a;
6530
6555
  let argumentErrors = false;
6531
6556
  let isTypeIncomplete = false;
@@ -6545,7 +6570,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6545
6570
  }
6546
6571
  let returnType = mapSubtypesExpandTypeVars(callTypeResult.type, { sortSubtypes: true }, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
6547
6572
  return useSpeculativeMode(isLastIteration ? undefined : getSpeculativeNodeForCall(errorNode), () => {
6548
- const callResult = validateCallArgsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6573
+ const callResult = validateCallArgsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, constraints, skipUnknownArgCheck, inferenceContext, recursionCount);
6549
6574
  if (callResult.argumentErrors) {
6550
6575
  argumentErrors = true;
6551
6576
  }
@@ -6575,7 +6600,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6575
6600
  overloadsUsedForCall,
6576
6601
  };
6577
6602
  }
6578
- function validateCallArgsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
6603
+ function validateCallArgsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext, recursionCount) {
6579
6604
  switch (expandedCallType.category) {
6580
6605
  case 3 /* TypeCategory.Never */:
6581
6606
  case 1 /* TypeCategory.Unknown */:
@@ -6593,10 +6618,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6593
6618
  return { returnType: expandedCallType };
6594
6619
  }
6595
6620
  case 4 /* TypeCategory.Function */: {
6596
- return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6621
+ return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext);
6597
6622
  }
6598
6623
  case 5 /* TypeCategory.OverloadedFunction */: {
6599
- return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6624
+ return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext);
6600
6625
  }
6601
6626
  case 6 /* TypeCategory.Class */: {
6602
6627
  if ((0, typeUtils_1.isNoneInstance)(expandedCallType)) {
@@ -6606,14 +6631,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6606
6631
  if (types_1.TypeBase.isInstantiable(expandedCallType)) {
6607
6632
  return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext);
6608
6633
  }
6609
- return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6634
+ return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, constraints, skipUnknownArgCheck, inferenceContext, recursionCount);
6610
6635
  }
6611
6636
  // TypeVars should have been expanded in most cases,
6612
6637
  // but we still need to handle the case of Type[T] where
6613
6638
  // T is a constrained type that contains a union. We also
6614
6639
  // need to handle recursive type aliases.
6615
6640
  case 9 /* TypeCategory.TypeVar */: {
6616
- return validateCallArgs(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6641
+ return validateCallArgs(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, constraints, skipUnknownArgCheck, inferenceContext, recursionCount);
6617
6642
  }
6618
6643
  case 7 /* TypeCategory.Module */: {
6619
6644
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.moduleNotCallable(), errorNode);
@@ -6622,7 +6647,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6622
6647
  }
6623
6648
  return { argumentErrors: true };
6624
6649
  }
6625
- function validateCallForFunction(errorNode, argList, type, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6650
+ function validateCallForFunction(errorNode, argList, type, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext) {
6626
6651
  var _a;
6627
6652
  if (types_1.TypeBase.isInstantiable(type)) {
6628
6653
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.callableNotInstantiable().format({
@@ -6630,7 +6655,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6630
6655
  }), errorNode);
6631
6656
  return { returnType: undefined, argumentErrors: true };
6632
6657
  }
6633
- const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(type));
6634
6658
  // The stdlib collections/__init__.pyi stub file defines namedtuple
6635
6659
  // as a function rather than a class, so we need to check for it here.
6636
6660
  if (types_1.FunctionType.isBuiltIn(type, 'namedtuple')) {
@@ -6638,14 +6662,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6638
6662
  const result = {
6639
6663
  returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ false),
6640
6664
  };
6641
- validateArgs(errorNode, argList, { type: type }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6665
+ validateArgs(errorNode, argList, { type: type }, constraints, skipUnknownArgCheck, inferenceContext);
6642
6666
  return result;
6643
6667
  }
6644
6668
  // Handle the NewType specially, replacing the normal return type.
6645
6669
  if (types_1.FunctionType.isBuiltIn(type, 'NewType')) {
6646
6670
  return { returnType: createNewType(errorNode, argList) };
6647
6671
  }
6648
- const functionResult = validateArgs(errorNode, argList, { type, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6672
+ const functionResult = validateArgs(errorNode, argList, { type, isIncomplete: isCallTypeIncomplete }, constraints, skipUnknownArgCheck, inferenceContext);
6649
6673
  let isTypeIncomplete = !!functionResult.isTypeIncomplete;
6650
6674
  let returnType = functionResult.returnType;
6651
6675
  let argumentErrors = !!functionResult.argumentErrors;
@@ -6752,13 +6776,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6752
6776
  }
6753
6777
  return { symbol, symbolName, classType, hasImplementation };
6754
6778
  }
6755
- function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6779
+ function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext) {
6756
6780
  var _a, _b;
6757
6781
  // Handle the 'cast' call as a special case.
6758
6782
  if (types_1.FunctionType.isBuiltIn(expandedCallType.priv.overloads[0], 'cast') && argList.length === 2) {
6759
6783
  return { returnType: evaluateCastCall(argList, errorNode) };
6760
6784
  }
6761
- const callResult = validateOverloadedArgTypes(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
6785
+ const callResult = validateOverloadedArgTypes(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, constraints, skipUnknownArgCheck, inferenceContext);
6762
6786
  let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
6763
6787
  let isTypeIncomplete = !!callResult.isTypeIncomplete;
6764
6788
  let argumentErrors = !!callResult.argumentErrors;
@@ -6868,7 +6892,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6868
6892
  /* diag */ undefined, 0 /* MemberAccessFlags.Default */);
6869
6893
  if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
6870
6894
  validateOverloadedArgTypes(errorNode, argList, { type: initTypeResult.type },
6871
- /* typeVarContext */ undefined, skipUnknownArgCheck,
6895
+ /* constraints */ undefined, skipUnknownArgCheck,
6872
6896
  /* inferenceContext */ undefined);
6873
6897
  }
6874
6898
  return result;
@@ -6976,7 +7000,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6976
7000
  }
6977
7001
  return { returnType, overloadsUsedForCall, argumentErrors, isTypeIncomplete };
6978
7002
  }
6979
- function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
7003
+ function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, constraints, skipUnknownArgCheck, inferenceContext, recursionCount) {
6980
7004
  var _a;
6981
7005
  const callDiag = new diagnostic_1.DiagnosticAddendum();
6982
7006
  const callMethodResult = getTypeOfBoundMember(errorNode, expandedCallType, '__call__',
@@ -6989,7 +7013,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6989
7013
  }) + callDiag.getString(), errorNode);
6990
7014
  return { returnType: types_1.UnknownType.create(), argumentErrors: true };
6991
7015
  }
6992
- const callResult = validateCallArgs(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
7016
+ const callResult = validateCallArgs(errorNode, argList, { type: callMethodType }, constraints, skipUnknownArgCheck, inferenceContext, recursionCount);
6993
7017
  let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
6994
7018
  if ((0, types_1.isTypeVar)(unexpandedCallType) &&
6995
7019
  types_1.TypeBase.isInstantiable(unexpandedCallType) &&
@@ -7074,7 +7098,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7074
7098
  // validation is left to the caller.
7075
7099
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
7076
7100
  function matchArgsToParams(errorNode, argList, typeResult, overloadIndex) {
7077
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
7101
+ var _a, _b, _c, _d, _e, _f, _g, _h;
7078
7102
  const overload = typeResult.type;
7079
7103
  const paramDetails = (0, parameterUtils_1.getParamListDetails)(overload);
7080
7104
  const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(overload);
@@ -7092,7 +7116,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7092
7116
  const param = paramInfo.param;
7093
7117
  if (param.name && param.category === 0 /* ParamCategory.Simple */) {
7094
7118
  paramMap.set(param.name, {
7095
- argsNeeded: param.category === 0 /* ParamCategory.Simple */ && !param.defaultType ? 1 : 0,
7119
+ argsNeeded: param.category === 0 /* ParamCategory.Simple */ && !paramInfo.defaultType ? 1 : 0,
7096
7120
  argsReceived: 0,
7097
7121
  isPositionalOnly: paramInfo.kind === parameterUtils_1.ParamKind.Positional,
7098
7122
  });
@@ -7116,22 +7140,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7116
7140
  }
7117
7141
  if (varArgListParamIndex !== undefined && varArgDictParamIndex !== undefined) {
7118
7142
  (0, debug_1.assert)(paramDetails.params[varArgListParamIndex], 'varArgListParamIndex params entry is undefined');
7119
- const varArgListParam = paramDetails.params[varArgListParamIndex].param;
7143
+ const varArgListParamType = paramDetails.params[varArgListParamIndex].type;
7120
7144
  (0, debug_1.assert)(paramDetails.params[varArgDictParamIndex], 'varArgDictParamIndex params entry is undefined');
7121
- const varArgDictParam = paramDetails.params[varArgDictParamIndex].param;
7122
- if ((0, types_1.isParamSpec)(varArgListParam.type) &&
7123
- varArgListParam.type.priv.paramSpecAccess === 'args' &&
7124
- (0, types_1.isParamSpec)(varArgDictParam.type) &&
7125
- varArgDictParam.type.priv.paramSpecAccess === 'kwargs' &&
7126
- varArgListParam.type.shared.name === varArgDictParam.type.shared.name) {
7145
+ const varArgDictParamType = paramDetails.params[varArgDictParamIndex].type;
7146
+ if ((0, types_1.isParamSpec)(varArgListParamType) &&
7147
+ varArgListParamType.priv.paramSpecAccess === 'args' &&
7148
+ (0, types_1.isParamSpec)(varArgDictParamType) &&
7149
+ varArgDictParamType.priv.paramSpecAccess === 'kwargs' &&
7150
+ varArgListParamType.shared.name === varArgDictParamType.shared.name) {
7127
7151
  hasParamSpecArgsKwargs = true;
7128
7152
  // Does this function define the param spec, or is it an inner
7129
7153
  // function nested within another function that defines the param
7130
7154
  // spec? We need to handle these two cases differently.
7131
- const paramSpecScopeId = varArgListParam.type.priv.scopeId;
7132
- if ((_b = (0, typeUtils_1.getTypeVarScopeIds)(overload)) === null || _b === void 0 ? void 0 : _b.some((id) => id === paramSpecScopeId)) {
7155
+ const paramSpecScopeId = varArgListParamType.priv.scopeId;
7156
+ if ((0, typeUtils_1.getTypeVarScopeIds)(overload).some((id) => id === paramSpecScopeId)) {
7133
7157
  paramSpecArgList = [];
7134
- paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParam.type, /* access */ undefined);
7158
+ paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParamType, /* access */ undefined);
7135
7159
  }
7136
7160
  else {
7137
7161
  positionalOnlyLimitIndex = varArgListParamIndex;
@@ -7141,7 +7165,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7141
7165
  }
7142
7166
  }
7143
7167
  else if (paramSpec) {
7144
- if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(overload)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpec.priv.scopeId)) {
7168
+ if ((0, typeUtils_1.getTypeVarScopeIds)(overload).some((id) => id === paramSpec.priv.scopeId)) {
7145
7169
  hasParamSpecArgsKwargs = true;
7146
7170
  paramSpecArgList = [];
7147
7171
  paramSpecTarget = paramSpec;
@@ -7226,7 +7250,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7226
7250
  ? localize_1.LocMessage.argPositionalExpectedOne()
7227
7251
  : localize_1.LocMessage.argPositionalExpectedCount().format({
7228
7252
  expected: positionParamLimitIndex,
7229
- }), (_d = argList[argIndex].valueExpression) !== null && _d !== void 0 ? _d : errorNode);
7253
+ }), (_b = argList[argIndex].valueExpression) !== null && _b !== void 0 ? _b : errorNode);
7230
7254
  }
7231
7255
  reportedArgError = true;
7232
7256
  }
@@ -7259,15 +7283,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7259
7283
  ? localize_1.LocMessage.argPositionalExpectedOne()
7260
7284
  : localize_1.LocMessage.argPositionalExpectedCount().format({
7261
7285
  expected: positionParamLimitIndex,
7262
- }), (_e = argList[argIndex].valueExpression) !== null && _e !== void 0 ? _e : errorNode);
7286
+ }), (_c = argList[argIndex].valueExpression) !== null && _c !== void 0 ? _c : errorNode);
7263
7287
  }
7264
7288
  reportedArgError = true;
7265
7289
  }
7266
7290
  }
7267
7291
  const argType = argTypeResult.type;
7268
7292
  if (isParamVariadic && (0, types_1.isUnpackedTypeVarTuple)(argType)) {
7269
- // Allow an unpacked variadic type variable to satisfy an
7270
- // unpacked variadic type variable.
7293
+ // Allow an unpacked TypeVarTuple arg to satisfy an
7294
+ // unpacked TypeVarTuple param.
7271
7295
  listElementType = argType;
7272
7296
  isArgCompatibleWithVariadic = true;
7273
7297
  advanceToNextArg = true;
@@ -7278,7 +7302,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7278
7302
  argType.priv.tupleTypeArgs &&
7279
7303
  argType.priv.tupleTypeArgs.length === 1 &&
7280
7304
  (0, types_1.isUnpackedTypeVarTuple)(argType.priv.tupleTypeArgs[0].type)) {
7281
- // Handle the case where an unpacked variadic type var has
7305
+ // Handle the case where an unpacked TypeVarTuple has
7282
7306
  // been packaged into a tuple.
7283
7307
  listElementType = argType.priv.tupleTypeArgs[0].type;
7284
7308
  isArgCompatibleWithVariadic = true;
@@ -7301,9 +7325,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7301
7325
  listElementType = undefined;
7302
7326
  }
7303
7327
  else {
7304
- listElementType = (_f = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
7328
+ listElementType = (_d = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
7305
7329
  /* isAsync */ false, errorNode,
7306
- /* emitNotIterableError */ false)) === null || _f === void 0 ? void 0 : _f.type;
7330
+ /* emitNotIterableError */ false)) === null || _d === void 0 ? void 0 : _d.type;
7307
7331
  if (paramInfo.param.category !== 1 /* ParamCategory.ArgsList */) {
7308
7332
  matchedUnpackedListOfUnknownLength = true;
7309
7333
  }
@@ -7335,7 +7359,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7335
7359
  paramType,
7336
7360
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7337
7361
  argument: funcArg,
7338
- errorNode: (_g = argList[argIndex].valueExpression) !== null && _g !== void 0 ? _g : errorNode,
7362
+ errorNode: (_e = argList[argIndex].valueExpression) !== null && _e !== void 0 ? _e : errorNode,
7339
7363
  paramName,
7340
7364
  isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(paramInfo.param),
7341
7365
  mapsToVarArgList: isParamVariadic && remainingArgCount > remainingParamCount,
@@ -7430,7 +7454,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7430
7454
  paramIndex < positionalOnlyLimitIndex &&
7431
7455
  paramIndex < paramDetails.params.length &&
7432
7456
  paramDetails.params[paramIndex].param.category === 1 /* ParamCategory.ArgsList */ &&
7433
- !(0, types_1.isParamSpec)(paramDetails.params[paramIndex].param.type)) {
7457
+ !(0, types_1.isParamSpec)(paramDetails.params[paramIndex].type)) {
7434
7458
  paramIndex++;
7435
7459
  skippedArgsParam = true;
7436
7460
  }
@@ -7439,7 +7463,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7439
7463
  if (positionalOnlyLimitIndex >= 0 &&
7440
7464
  paramIndex < positionalOnlyLimitIndex &&
7441
7465
  (!foundUnpackedListArg || hasParamSpecArgsKwargs)) {
7442
- const firstParamWithDefault = paramDetails.params.findIndex((paramInfo) => !!paramInfo.param.defaultType);
7466
+ const firstParamWithDefault = paramDetails.params.findIndex((paramInfo) => !!paramInfo.defaultType);
7443
7467
  const positionOnlyWithoutDefaultsCount = firstParamWithDefault >= 0 && firstParamWithDefault < positionalOnlyLimitIndex
7444
7468
  ? firstParamWithDefault
7445
7469
  : positionalOnlyLimitIndex;
@@ -7450,7 +7474,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7450
7474
  // because it's permitted to pass zero arguments to *args.
7451
7475
  argsRemainingCount--;
7452
7476
  }
7453
- const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* ParamCategory.ArgsList */ && !(0, types_1.isParamSpec)(paramInfo.param.type));
7477
+ const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* ParamCategory.ArgsList */ && !(0, types_1.isParamSpec)(paramInfo.type));
7454
7478
  if (firstArgsParam >= paramIndex && firstArgsParam < positionalOnlyLimitIndex) {
7455
7479
  // If there is another args parameter beyond the current param index,
7456
7480
  // reduce the count by one because it's permitted to pass zero arguments
@@ -7569,7 +7593,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7569
7593
  (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass) &&
7570
7594
  strObjType &&
7571
7595
  (0, types_1.isClassInstance)(strObjType)) {
7572
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemClass));
7596
+ const mappingConstraints = new constraintTracker_1.ConstraintTracker();
7573
7597
  let isValidMappingType = false;
7574
7598
  // If this was a TypeVar (e.g. for pseudo-generic classes),
7575
7599
  // don't emit this error.
@@ -7577,8 +7601,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7577
7601
  isValidMappingType = true;
7578
7602
  }
7579
7603
  else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), argType,
7580
- /* diag */ undefined, mappingTypeVarContext)) {
7581
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
7604
+ /* diag */ undefined, mappingConstraints)) {
7605
+ const specializedMapping = solveAndApplyConstraints(supportsKeysAndGetItemClass, mappingConstraints);
7582
7606
  const typeArgs = specializedMapping.priv.typeArgs;
7583
7607
  if (typeArgs && typeArgs.length >= 2) {
7584
7608
  if (assignType(strObjType, typeArgs[0])) {
@@ -7640,7 +7664,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7640
7664
  paramType,
7641
7665
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7642
7666
  argument: argList[argIndex],
7643
- errorNode: (_h = argList[argIndex].valueExpression) !== null && _h !== void 0 ? _h : errorNode,
7667
+ errorNode: (_f = argList[argIndex].valueExpression) !== null && _f !== void 0 ? _f : errorNode,
7644
7668
  paramName: paramNameValue,
7645
7669
  });
7646
7670
  trySetActive(argList[argIndex], paramDetails.params[paramInfoIndex].param);
@@ -7663,7 +7687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7663
7687
  paramType,
7664
7688
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7665
7689
  argument: argList[argIndex],
7666
- errorNode: (_j = argList[argIndex].valueExpression) !== null && _j !== void 0 ? _j : errorNode,
7690
+ errorNode: (_g = argList[argIndex].valueExpression) !== null && _g !== void 0 ? _g : errorNode,
7667
7691
  paramName: paramNameValue,
7668
7692
  });
7669
7693
  // Remember that this parameter has already received a value.
@@ -7714,7 +7738,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7714
7738
  requiresTypeVarMatching: false,
7715
7739
  argument: argList[argIndex],
7716
7740
  argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
7717
- errorNode: (_k = argList[argIndex].valueExpression) !== null && _k !== void 0 ? _k : errorNode,
7741
+ errorNode: (_h = argList[argIndex].valueExpression) !== null && _h !== void 0 ? _h : errorNode,
7718
7742
  });
7719
7743
  }
7720
7744
  }
@@ -7779,15 +7803,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7779
7803
  // and _T is a TypeVar, we need to match the TypeVar to the default
7780
7804
  // value's type if it's not provided by the caller.
7781
7805
  paramDetails.params.forEach((paramInfo) => {
7782
- var _a;
7783
7806
  const param = paramInfo.param;
7784
7807
  if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
7785
7808
  const entry = paramMap.get(param.name);
7786
7809
  if (entry.argsNeeded === 0 && entry.argsReceived === 0) {
7787
- const defaultArgType = (_a = paramInfo.defaultArgType) !== null && _a !== void 0 ? _a : param.defaultType;
7810
+ const defaultArgType = paramInfo.defaultType;
7788
7811
  if (defaultArgType &&
7789
7812
  !(0, typeUtils_1.isEllipsisType)(defaultArgType) &&
7790
- (0, typeUtils_1.requiresSpecialization)(param.type)) {
7813
+ (0, typeUtils_1.requiresSpecialization)(paramInfo.declaredType)) {
7791
7814
  validateArgTypeParams.push({
7792
7815
  paramCategory: param.category,
7793
7816
  paramType: paramInfo.type,
@@ -7812,8 +7835,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7812
7835
  // correct overload.
7813
7836
  if (!reportedArgError || !isSpeculativeModeInUse(undefined)) {
7814
7837
  // If there are arguments that map to a variadic *args parameter that hasn't
7815
- // already been matched, see if the type of that *args parameter is a variadic
7816
- // type variable. If so, we'll preprocess those arguments and combine them
7838
+ // already been matched, see if the type of that *args parameter is a
7839
+ // TypeVarTuple. If so, we'll preprocess those arguments and combine them
7817
7840
  // into a tuple.
7818
7841
  (0, debug_1.assert)(paramDetails.argsIndex === undefined || paramDetails.argsIndex < paramDetails.params.length, 'paramDetails.argsIndex params entry is invalid');
7819
7842
  if (paramDetails.argsIndex !== undefined &&
@@ -7822,7 +7845,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7822
7845
  !isTypeVarTupleFullyMatched) {
7823
7846
  const paramType = paramDetails.params[paramDetails.argsIndex].type;
7824
7847
  const variadicArgs = validateArgTypeParams.filter((argParam) => argParam.mapsToVarArgList);
7825
- if ((0, types_1.isTypeVarTuple)(paramType) && !paramType.priv.isVariadicInUnion) {
7848
+ if ((0, types_1.isTypeVarTuple)(paramType) && !paramType.priv.isInUnion) {
7826
7849
  const tupleTypeArgs = variadicArgs.map((argParam) => {
7827
7850
  var _a;
7828
7851
  const argType = getTypeOfArg(argParam.argument, /* inferenceContext */ undefined).type;
@@ -7904,7 +7927,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7904
7927
  // After having matched arguments with parameters, this function evaluates the
7905
7928
  // types of each argument expression and validates that the resulting type is
7906
7929
  // compatible with the declared type of the corresponding parameter.
7907
- function validateArgTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7930
+ function validateArgTypesWithContext(errorNode, matchResults, constraints, skipUnknownArgCheck = false, inferenceContext) {
7908
7931
  var _a;
7909
7932
  const type = matchResults.overload;
7910
7933
  let expectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
@@ -7915,20 +7938,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7915
7938
  expectedType = undefined;
7916
7939
  }
7917
7940
  const tryExpectedType = (expectedSubtype) => {
7918
- const clonedTypeVarContext = typeVarContext.clone();
7919
- const callResult = validateArgTypesWithExpectedType(errorNode, matchResults, clonedTypeVarContext,
7941
+ const clonedConstraints = constraints.clone();
7942
+ const callResult = validateArgTypesWithExpectedType(errorNode, matchResults, clonedConstraints,
7920
7943
  /* skipUnknownArgCheck */ true, expectedSubtype, returnType);
7921
7944
  // Use a heuristic to pick a subtype that is most likely to be correct.
7922
7945
  // We'll look for a subtype that produces no argument errors and has
7923
7946
  // no Unknowns in the return type.
7924
7947
  if (!callResult.argumentErrors && callResult.returnType) {
7925
7948
  const returnType = (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnTypeOverride)
7926
- ? (0, typeUtils_1.applySolvedTypeVars)(inferenceContext.returnTypeOverride, clonedTypeVarContext)
7949
+ ? solveAndApplyConstraints(inferenceContext.returnTypeOverride, clonedConstraints)
7927
7950
  : callResult.returnType;
7928
7951
  if (assignType(expectedSubtype, returnType,
7929
7952
  /* diag */ undefined,
7930
- /* destTypeVarContext */ undefined,
7931
- /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
7953
+ /* destConstraints */ undefined,
7954
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
7932
7955
  const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(callResult.returnType, /* recurse */ true);
7933
7956
  // Prefer return types that have no unknown or Any.
7934
7957
  if (!anyOrUnknown) {
@@ -7974,39 +7997,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7974
7997
  // If there is no expected type, or the expected type is Any or Unknown,
7975
7998
  // there's nothing left to do here.
7976
7999
  if (!expectedType || (0, types_1.isAnyOrUnknown)(expectedType) || (0, types_1.isNever)(expectedType)) {
7977
- return validateArgTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck);
8000
+ return validateArgTypes(errorNode, matchResults, constraints, skipUnknownArgCheck);
7978
8001
  }
7979
- return validateArgTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, expectedType, returnType);
8002
+ return validateArgTypesWithExpectedType(errorNode, matchResults, constraints, skipUnknownArgCheck, expectedType, returnType);
7980
8003
  }
7981
- function validateArgTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, expectedType, returnType) {
8004
+ function validateArgTypesWithExpectedType(errorNode, matchResults, constraints, skipUnknownArgCheck = false, expectedType, returnType) {
7982
8005
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7983
8006
  let assignFlags = 2048 /* AssignTypeFlags.PopulatingExpectedType */;
7984
8007
  if ((0, typeUtils_1.containsLiteralType)(expectedType, /* includeTypeArgs */ true)) {
7985
8008
  assignFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
7986
8009
  }
7987
- // Prepopulate the typeVarContext based on the specialized expected type.
8010
+ // Prepopulate the constraints based on the specialized expected type.
7988
8011
  // This will allow us to more closely match the expected type if possible.
7989
8012
  if ((0, types_1.isClassInstance)(returnType) && (0, types_1.isClassInstance)(expectedType) && !(0, types_1.isTypeSame)(returnType, expectedType)) {
7990
- const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(returnType));
7991
- if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, returnType, expectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start)) {
8013
+ const tempConstraints = new constraintTracker_1.ConstraintTracker();
8014
+ if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, returnType, expectedType, tempConstraints, liveTypeVarScopes, errorNode.start)) {
7992
8015
  const genericReturnType = (0, typeUtils_1.selfSpecializeClass)(returnType, {
7993
8016
  overrideTypeArgs: true,
7994
8017
  });
7995
- expectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
7996
- unknownIfNotFound: true,
7997
- useUnknownOverDefault: true,
7998
- tupleClassType: getTupleClassType(),
8018
+ expectedType = solveAndApplyConstraints(genericReturnType, tempConstraints, {
8019
+ replaceUnsolved: {
8020
+ scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(returnType),
8021
+ useUnknown: true,
8022
+ tupleClassType: getTupleClassType(),
8023
+ },
7999
8024
  });
8000
8025
  assignFlags |= 4096 /* AssignTypeFlags.SkipPopulateUnknownExpectedType */;
8001
8026
  }
8002
8027
  }
8003
8028
  expectedType = (0, typeUtils_1.transformExpectedType)(expectedType, liveTypeVarScopes, errorNode.start);
8004
8029
  assignType(returnType, expectedType,
8005
- /* diag */ undefined, typeVarContext,
8006
- /* srcTypeVarContext */ undefined, assignFlags);
8007
- return validateArgTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck);
8030
+ /* diag */ undefined, constraints,
8031
+ /* srcConstraints */ undefined, assignFlags);
8032
+ return validateArgTypes(errorNode, matchResults, constraints, skipUnknownArgCheck);
8008
8033
  }
8009
- function validateArgTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck) {
8034
+ function validateArgTypes(errorNode, matchResults, constraints, skipUnknownArgCheck) {
8010
8035
  const type = matchResults.overload;
8011
8036
  let isTypeIncomplete = matchResults.isTypeIncomplete;
8012
8037
  let argumentErrors = false;
@@ -8040,7 +8065,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8040
8065
  if (index < typeParams.length) {
8041
8066
  const typeParam = typeParams[index];
8042
8067
  if (!(0, types_1.isTypeSame)(typeParam, typeArg, { ignorePseudoGeneric: true })) {
8043
- (0, typeUtils_1.setTypeVarType)(typeVarContext, typeParams[index], typeArg);
8068
+ constraints.setBounds(typeParams[index], typeArg);
8044
8069
  }
8045
8070
  }
8046
8071
  });
@@ -8071,24 +8096,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8071
8096
  if (!argParam.requiresTypeVarMatching) {
8072
8097
  return;
8073
8098
  }
8074
- // Populate the typeVarContext for the argument. If the argument
8099
+ // Populate the constraints for the argument. If the argument
8075
8100
  // is an overload function, skip it during the first pass
8076
8101
  // because the selection of the proper overload may depend
8077
8102
  // on type arguments supplied by other function arguments.
8078
- // We set useLowerBoundOnly to true if this is the first
8079
- // (but not only) pass through the parameter list because a wide
8080
- // bound on a TypeVar (if a lower bound has not yet been
8081
- // established) will unnecessarily constrain the expected type.
8082
8103
  // If the param type is a "bare" TypeVar, don't use it as an
8083
8104
  // expected type during the first pass. This causes problems for
8084
8105
  // cases where the the call expression result can influence the
8085
8106
  // type of the TypeVar, such as in the expression "min(1, max(2, 0.5))".
8086
- const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, {
8107
+ const argResult = validateArgType(argParam, constraints, { type, isIncomplete: matchResults.isTypeIncomplete }, {
8087
8108
  skipUnknownArgCheck,
8088
- skipOverloadArg: i === 0,
8089
- skipBareTypeVarExpectedType: i === 0,
8090
- useLowerBoundOnly: passCount > 1 && i === 0,
8109
+ isArgFirstPass: passCount > 1 && i === 0,
8091
8110
  conditionFilter: typeCondition,
8111
+ skipReportError: true,
8092
8112
  });
8093
8113
  if (argResult.isTypeIncomplete) {
8094
8114
  isTypeIncomplete = true;
@@ -8103,7 +8123,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8103
8123
  }
8104
8124
  // Lock the type var map so it cannot be modified when revalidating
8105
8125
  // the arguments in a second pass.
8106
- typeVarContext.lock();
8126
+ constraints.lock();
8107
8127
  }
8108
8128
  let sawParamSpecArgs = false;
8109
8129
  let sawParamSpecKwargs = false;
@@ -8111,7 +8131,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8111
8131
  const argResults = [];
8112
8132
  matchResults.argParams.forEach((argParam, argParamIndex) => {
8113
8133
  var _a;
8114
- const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, {
8134
+ const argResult = validateArgType(argParam, constraints, { type, isIncomplete: matchResults.isTypeIncomplete }, {
8115
8135
  skipUnknownArgCheck,
8116
8136
  conditionFilter: typeCondition,
8117
8137
  });
@@ -8147,15 +8167,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8147
8167
  }
8148
8168
  }
8149
8169
  });
8150
- let paramSpecTypeVarContext = [];
8170
+ let paramSpecConstraints = [];
8151
8171
  // Handle the assignment of additional arguments that map to a param spec.
8152
8172
  if (matchResults.paramSpecArgList && matchResults.paramSpecTarget) {
8153
- const paramSpecArgResult = validateArgTypesForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext);
8173
+ const paramSpecArgResult = validateArgTypesForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, constraints);
8154
8174
  if (paramSpecArgResult.argumentErrors) {
8155
8175
  argumentErrors = true;
8156
8176
  argumentMatchScore += 1;
8157
8177
  }
8158
- paramSpecTypeVarContext = paramSpecArgResult.typeVarContexts;
8178
+ paramSpecConstraints = paramSpecArgResult.constraintTrackers;
8159
8179
  }
8160
8180
  else if (paramSpec) {
8161
8181
  if (!sawParamSpecArgs || !sawParamSpecKwargs) {
@@ -8171,56 +8191,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8171
8191
  if (condition.length > 0) {
8172
8192
  returnType = types_1.TypeBase.cloneForCondition(returnType, condition);
8173
8193
  }
8174
- // Determine whether the expression being evaluated is within the current TypeVar
8175
- // scope. If not, then the expression is invoking a function in another scope,
8176
- // and we should eliminate unsolved type variables from union types that appear
8177
- // in the return type. If we're within the same scope, we should retain these
8178
- // extra type variables because they are still potentially relevant within this
8179
- // scope.
8180
8194
  let eliminateUnsolvedInUnions = true;
8181
- let curNode = errorNode;
8182
- while (curNode) {
8183
- const typeVarScopeNode = ParseTreeUtils.getTypeVarScopeNode(curNode);
8184
- if (!typeVarScopeNode) {
8185
- break;
8186
- }
8187
- const typeVarScopeId = ParseTreeUtils.getScopeIdForNode(typeVarScopeNode);
8188
- if (typeVarContext.hasSolveForScope(typeVarScopeId)) {
8189
- eliminateUnsolvedInUnions = false;
8190
- }
8191
- curNode = typeVarScopeNode.parent;
8192
- }
8193
8195
  // If the function is returning a callable, don't eliminate unsolved
8194
8196
  // type vars within a union. There are legit uses for unsolved type vars
8195
8197
  // within a callable.
8196
8198
  if ((0, types_1.isFunction)(returnType) || (0, types_1.isOverloadedFunction)(returnType)) {
8197
8199
  eliminateUnsolvedInUnions = false;
8198
8200
  }
8199
- // We'll leave TypeVars unsolved if the call is a recursive
8200
- // call to a generic function or if this isn't a callable
8201
- // return with type parameters that are rescoped from the original
8202
- // function to the returned callable.
8203
- const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
8204
- const unknownIfNotFound = !liveTypeVarScopes.some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope) ||
8205
- typeVarContext.hasSolveForScope(types_1.TypeVarType.makeInternalScopeId(typeVarScope)));
8206
- let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
8207
- unknownIfNotFound,
8208
- tupleClassType: getTupleClassType(),
8209
- unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
8210
- eliminateUnsolvedInUnions,
8211
- applyInScopePlaceholders: true,
8212
- });
8201
+ let specializedReturnType = solveAndApplyConstraints(returnType, constraints, {
8202
+ replaceUnsolved: {
8203
+ scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(type),
8204
+ unsolvedExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
8205
+ tupleClassType: getTupleClassType(),
8206
+ eliminateUnsolvedInUnions,
8207
+ },
8208
+ }, { applyUnificationVars: true });
8213
8209
  specializedReturnType = (0, typeUtils_1.addConditionToType)(specializedReturnType, typeCondition);
8214
8210
  // If the function includes a ParamSpec and the captured signature(s) includes
8215
8211
  // generic types, we may need to apply those solved TypeVars.
8216
- if (paramSpecTypeVarContext.length > 0) {
8217
- paramSpecTypeVarContext.forEach((paramSpecTypeVarContext) => {
8218
- if (paramSpecTypeVarContext) {
8219
- specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(specializedReturnType, paramSpecTypeVarContext);
8212
+ if (paramSpecConstraints.length > 0) {
8213
+ paramSpecConstraints.forEach((paramSpecConstraints) => {
8214
+ if (paramSpecConstraints) {
8215
+ specializedReturnType = solveAndApplyConstraints(specializedReturnType, paramSpecConstraints);
8220
8216
  // It's possible that one or more of the TypeVars or ParamSpecs
8221
- // in the typeVarContext refer to TypeVars that were solved in
8222
- // the paramSpecTypeVarContext. Apply these solved TypeVars accordingly.
8223
- (0, typeUtils_1.applySourceContextTypeVars)(typeVarContext, paramSpecTypeVarContext);
8217
+ // in the constraints refer to TypeVars that were solved in
8218
+ // the paramSpecConstraints. Apply these solved TypeVars accordingly.
8219
+ (0, typeUtils_1.applySourceContextTypeVars)(constraints, (0, constraintSolver_1.solveConstraints)(evaluatorInterface, paramSpecConstraints));
8224
8220
  }
8225
8221
  });
8226
8222
  }
@@ -8228,9 +8224,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8228
8224
  if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
8229
8225
  specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /* isUnpackedTuple */ false);
8230
8226
  }
8227
+ const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
8231
8228
  specializedReturnType = adjustCallableReturnType(type, specializedReturnType, liveTypeVarScopes);
8232
8229
  if (specializedInitSelfType) {
8233
- specializedInitSelfType = (0, typeUtils_1.applySolvedTypeVars)(specializedInitSelfType, typeVarContext);
8230
+ specializedInitSelfType = solveAndApplyConstraints(specializedInitSelfType, constraints);
8234
8231
  }
8235
8232
  matchResults.argumentMatchScore = argumentMatchScore;
8236
8233
  return {
@@ -8259,9 +8256,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8259
8256
  if (returnTypeScopeId && functionType.shared.typeVarScopeId) {
8260
8257
  let typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgsRecursive)(returnType);
8261
8258
  // Remove any type variables that appear in the function's input parameters.
8262
- functionType.shared.parameters.forEach((param) => {
8259
+ functionType.shared.parameters.forEach((param, index) => {
8263
8260
  if (types_1.FunctionParam.isTypeDeclared(param)) {
8264
- const typeVarsInInputParam = (0, typeUtils_1.getTypeVarArgsRecursive)(param.type);
8261
+ const typeVarsInInputParam = (0, typeUtils_1.getTypeVarArgsRecursive)(types_1.FunctionType.getParamType(functionType, index));
8265
8262
  typeVarsInReturnType = typeVarsInReturnType.filter((returnTypeVar) => !typeVarsInInputParam.some((inputTypeVar) => (0, types_1.isTypeSame)(returnTypeVar, inputTypeVar)));
8266
8263
  }
8267
8264
  });
@@ -8276,14 +8273,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8276
8273
  // or unions of callables. It's intended for a specific use case. We may
8277
8274
  // need to make this more sophisticated in the future.
8278
8275
  function adjustCallableReturnType(callableType, returnType, liveTypeVarScopes) {
8276
+ var _a, _b;
8279
8277
  if ((0, types_1.isFunction)(returnType) && !returnType.shared.name && callableType.shared.typeVarScopeId) {
8280
8278
  // What type variables are referenced in the callable return type? Do not include any live type variables.
8281
- const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgsRecursive)(returnType).filter((t) => !liveTypeVarScopes.some((scopeId) => t.priv.scopeId === scopeId));
8279
+ const newTypeParams = (0, typeUtils_1.getTypeVarArgsRecursive)(returnType).filter((t) => !liveTypeVarScopes.some((scopeId) => t.priv.scopeId === scopeId));
8282
8280
  // If there are no unsolved type variables, we're done. If there are
8283
8281
  // unsolved type variables, treat them as though they are rescoped
8284
8282
  // to the callable.
8285
- if (typeVarsInReturnType.length > 0) {
8286
- return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, callableType.shared.typeVarScopeId, callableType.priv.constructorTypeVarScopeId, typeVarsInReturnType);
8283
+ if (newTypeParams.length > 0) {
8284
+ const newScopeId = (_b = (_a = newTypeParams[0].priv.freeTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) !== null && _b !== void 0 ? _b : newTypeParams[0].priv.scopeId;
8285
+ return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, newScopeId, callableType.priv.constructorTypeVarScopeId, newTypeParams);
8287
8286
  }
8288
8287
  }
8289
8288
  return returnType;
@@ -8291,7 +8290,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8291
8290
  // Tries to assign the call arguments to the function parameter
8292
8291
  // list and reports any mismatches in types or counts. Returns the
8293
8292
  // specialized return type of the call.
8294
- function validateArgs(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
8293
+ function validateArgs(errorNode, argList, typeResult, constraints, skipUnknownArgCheck = false, inferenceContext) {
8295
8294
  const matchResults = matchArgsToParams(errorNode, argList, typeResult, 0);
8296
8295
  if (matchResults.argumentErrors) {
8297
8296
  // Evaluate types of all args. This will ensure that referenced symbols are
@@ -8307,46 +8306,45 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8307
8306
  overloadsUsedForCall: [],
8308
8307
  };
8309
8308
  }
8310
- return validateArgTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnTypeOverride));
8309
+ return validateArgTypesWithContext(errorNode, matchResults, constraints !== null && constraints !== void 0 ? constraints : new constraintTracker_1.ConstraintTracker(), skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.returnTypeOverride));
8311
8310
  }
8312
8311
  // Determines whether the specified argument list satisfies the function
8313
8312
  // signature bound to the specified ParamSpec. Return value indicates success.
8314
- function validateArgTypesForParamSpec(errorNode, argList, paramSpec, destTypeVarContext) {
8315
- const solutionSets = destTypeVarContext.getSolutionSets();
8313
+ function validateArgTypesForParamSpec(errorNode, argList, paramSpec, destConstraints) {
8314
+ const sets = destConstraints.getConstraintSets();
8316
8315
  // Handle the common case where there is only one signature context.
8317
- if (solutionSets.length === 1) {
8318
- return validateArgTypesForParamSpecSignature(errorNode, argList, paramSpec, solutionSets[0]);
8316
+ if (sets.length === 1) {
8317
+ return validateArgTypesForParamSpecSignature(errorNode, argList, paramSpec, sets[0]);
8319
8318
  }
8320
- const filteredSolutionSets = [];
8321
- const typeVarContexts = [];
8319
+ const filteredSets = [];
8320
+ const constraintTrackers = [];
8322
8321
  const speculativeNode = getSpeculativeNodeForCall(errorNode);
8323
- solutionSets.forEach((context) => {
8322
+ sets.forEach((context) => {
8324
8323
  // Use speculative mode to avoid emitting errors or caching types.
8325
8324
  useSpeculativeMode(speculativeNode, () => {
8326
8325
  const paramSpecArgResult = validateArgTypesForParamSpecSignature(errorNode, argList, paramSpec, context);
8327
8326
  if (!paramSpecArgResult.argumentErrors) {
8328
- filteredSolutionSets.push(context);
8327
+ filteredSets.push(context);
8329
8328
  }
8330
- (0, collectionUtils_1.appendArray)(typeVarContexts, paramSpecArgResult.typeVarContexts);
8329
+ (0, collectionUtils_1.appendArray)(constraintTrackers, paramSpecArgResult.constraintTrackers);
8331
8330
  });
8332
8331
  });
8333
8332
  // Copy back any compatible signature contexts if any were compatible.
8334
- if (filteredSolutionSets.length > 0) {
8335
- destTypeVarContext.addSolutionSets(filteredSolutionSets);
8333
+ if (filteredSets.length > 0) {
8334
+ destConstraints.addConstraintSets(filteredSets);
8336
8335
  }
8337
8336
  // Evaluate non-speculatively to produce a final result and cache types.
8338
- const paramSpecArgResult = validateArgTypesForParamSpecSignature(errorNode, argList, paramSpec, filteredSolutionSets.length > 0 ? filteredSolutionSets[0] : solutionSets[0]);
8339
- return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
8337
+ const paramSpecArgResult = validateArgTypesForParamSpecSignature(errorNode, argList, paramSpec, filteredSets.length > 0 ? filteredSets[0] : sets[0]);
8338
+ return { argumentErrors: paramSpecArgResult.argumentErrors, constraintTrackers: constraintTrackers };
8340
8339
  }
8341
- function validateArgTypesForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext) {
8340
+ function validateArgTypesForParamSpecSignature(errorNode, argList, paramSpec, constraintSet) {
8342
8341
  var _a;
8343
- let paramSpecType = typeVarContext.getTypeVarType(paramSpec);
8344
- if (!paramSpecType) {
8345
- paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpec);
8346
- }
8342
+ const solutionSet = (0, constraintSolver_1.solveConstraintSet)(evaluatorInterface, constraintSet);
8343
+ let paramSpecType = solutionSet.getType(paramSpec);
8344
+ paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpecType !== null && paramSpecType !== void 0 ? paramSpecType : paramSpec);
8347
8345
  const matchResults = matchArgsToParams(errorNode, argList, { type: paramSpecType }, 0);
8348
8346
  const functionType = matchResults.overload;
8349
- const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
8347
+ const srcConstraints = new constraintTracker_1.ConstraintTracker();
8350
8348
  if (matchResults.argumentErrors) {
8351
8349
  // Evaluate types of all args. This will ensure that referenced symbols are
8352
8350
  // not reported as unaccessed.
@@ -8355,7 +8353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8355
8353
  getTypeOfExpression(arg.valueExpression);
8356
8354
  }
8357
8355
  });
8358
- return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
8356
+ return { argumentErrors: true, constraintTrackers: [srcConstraints] };
8359
8357
  }
8360
8358
  const functionParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
8361
8359
  const functionWithoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(functionType);
@@ -8395,13 +8393,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8395
8393
  type: printType(functionParamSpec),
8396
8394
  }), argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : errorNode);
8397
8395
  }
8398
- return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
8396
+ return { argumentErrors, constraintTrackers: [srcConstraints] };
8399
8397
  }
8400
- const result = validateArgTypes(errorNode, matchResults, srcTypeVarContext,
8401
- /* skipUnknownArgCheck */ undefined);
8402
- return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
8398
+ const result = validateArgTypes(errorNode, matchResults, srcConstraints, /* skipUnknownArgCheck */ undefined);
8399
+ return { argumentErrors: !!result.argumentErrors, constraintTrackers: [srcConstraints] };
8403
8400
  }
8404
- function validateArgType(argParam, typeVarContext, typeResult, options) {
8401
+ function validateArgType(argParam, constraints, typeResult, options) {
8405
8402
  var _a, _b;
8406
8403
  let argType;
8407
8404
  let expectedTypeDiag;
@@ -8409,7 +8406,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8409
8406
  let isCompatible = true;
8410
8407
  const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.shared.name;
8411
8408
  let skippedBareTypeVarExpectedType = false;
8412
- let skipSolveTypeVars = false;
8413
8409
  if (argParam.argument.valueExpression) {
8414
8410
  let expectedType;
8415
8411
  // Is the expected type a "bare" in-scope TypeVar or a union of bare in-scope TypeVars?
@@ -8419,29 +8415,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8419
8415
  isExpectedTypeBareTypeVar = false;
8420
8416
  }
8421
8417
  });
8422
- if (!options.skipBareTypeVarExpectedType || !isExpectedTypeBareTypeVar) {
8418
+ if (!options.isArgFirstPass || !isExpectedTypeBareTypeVar) {
8423
8419
  expectedType = argParam.paramType;
8424
8420
  // If the parameter type is a function with a ParamSpec, don't apply
8425
- // the solved TypeVars if the typeVarContext has more than one signature.
8421
+ // the solved TypeVars if the constraint tracker has more than one signature.
8426
8422
  // This will expand the ParamSpec into an overload, which will cause problems.
8427
8423
  const skipApplySolvedTypeVars = (0, types_1.isFunction)(argParam.paramType) &&
8428
8424
  types_1.FunctionType.getParamSpecFromArgsKwargs(argParam.paramType) &&
8429
- typeVarContext.getSolutionSets().length > 1;
8425
+ constraints.getConstraintSets().length > 1;
8430
8426
  if (!skipApplySolvedTypeVars) {
8431
- expectedType = (0, typeUtils_1.applySolvedTypeVars)(expectedType, typeVarContext, {
8432
- useLowerBoundOnly: !!options.useLowerBoundOnly,
8427
+ expectedType = solveAndApplyConstraints(expectedType, constraints, /* applyOptions */ undefined, {
8428
+ useLowerBoundOnly: !!options.isArgFirstPass,
8433
8429
  });
8434
8430
  }
8435
8431
  }
8436
8432
  else {
8437
8433
  skippedBareTypeVarExpectedType = true;
8438
- // If the expected type is a union of bare TypeVars, it's not clear which of the two
8439
- // (or both) should be constrained. We'll skip any attempt to solve the TypeVars during
8440
- // this pass and hope that subsequent arg assignments will help us establish the correct
8441
- // constraints.
8442
- if ((0, types_1.isUnion)(argParam.paramType)) {
8443
- skipSolveTypeVars = true;
8444
- }
8445
8434
  }
8446
8435
  // If the expected type is unknown, don't use an expected type. Instead,
8447
8436
  // use default rules for evaluating the expression type.
@@ -8466,10 +8455,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8466
8455
  }
8467
8456
  else if (expectedType && (0, typeUtils_1.requiresSpecialization)(expectedType)) {
8468
8457
  // Assign the argument type back to the expected type to assign
8469
- // values to any in-scope placeholder type variables.
8470
- const typeVarContextClone = typeVarContext.clone();
8471
- if (assignType(expectedType, argType, /* diag */ undefined, typeVarContextClone)) {
8472
- typeVarContext.copyFromClone(typeVarContextClone);
8458
+ // values to any unification variables.
8459
+ const clonedConstraints = constraints.clone();
8460
+ if (assignType(expectedType, argType,
8461
+ /* diag */ undefined, clonedConstraints,
8462
+ /* srcConstraints */ undefined, (options === null || options === void 0 ? void 0 : options.isArgFirstPass) ? 8 /* AssignTypeFlags.ArgAssignmentFirstPass */ : 0 /* AssignTypeFlags.Default */)) {
8463
+ constraints.copyFromClone(clonedConstraints);
8473
8464
  }
8474
8465
  else {
8475
8466
  isCompatible = false;
@@ -8496,7 +8487,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8496
8487
  // If the argument came from a parameter's default argument value,
8497
8488
  // we may need to specialize the type.
8498
8489
  if (argParam.isDefaultArg) {
8499
- argType = (0, typeUtils_1.applySolvedTypeVars)(argType, typeVarContext);
8490
+ argType = solveAndApplyConstraints(argType, constraints);
8500
8491
  }
8501
8492
  }
8502
8493
  // If we're assigning to a var arg dictionary with a TypeVar type,
@@ -8514,7 +8505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8514
8505
  });
8515
8506
  }
8516
8507
  const condition = (_a = argType.props) === null || _a === void 0 ? void 0 : _a.condition;
8517
- let diag = new diagnostic_1.DiagnosticAddendum();
8508
+ let diag = (options === null || options === void 0 ? void 0 : options.skipReportError) ? undefined : new diagnostic_1.DiagnosticAddendum();
8518
8509
  if ((0, types_1.isParamSpec)(argParam.paramType)) {
8519
8510
  // Handle the case where we're assigning a *args or **kwargs argument
8520
8511
  // to a *P.args or **P.kwargs parameter.
@@ -8527,107 +8518,65 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8527
8518
  return { isCompatible, argType, isTypeIncomplete, condition };
8528
8519
  }
8529
8520
  }
8530
- // If we are asked to skip overload arguments, determine whether the argument
8531
- // is an explicit overload type, an overloaded class constructor, or a
8532
- // an overloaded callback protocol.
8533
- if (options.skipOverloadArg) {
8534
- if ((0, types_1.isOverloadedFunction)(argType)) {
8535
- return {
8536
- isCompatible,
8537
- argType,
8538
- isTypeIncomplete,
8539
- skippedOverloadArg: true,
8540
- skippedBareTypeVarExpectedType,
8541
- condition,
8542
- };
8543
- }
8544
- const concreteParamType = makeTopLevelTypeVarsConcrete(argParam.paramType);
8545
- if ((0, types_1.isFunction)(concreteParamType) || (0, types_1.isOverloadedFunction)(concreteParamType)) {
8546
- if ((0, types_1.isInstantiableClass)(argType)) {
8547
- const constructor = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, argType);
8548
- if (constructor) {
8549
- return {
8550
- isCompatible,
8551
- argType,
8552
- isTypeIncomplete,
8553
- skippedOverloadArg: true,
8554
- skippedBareTypeVarExpectedType,
8555
- condition,
8556
- };
8557
- }
8558
- }
8559
- if ((0, types_1.isClassInstance)(argType)) {
8560
- const callMember = (0, typeUtils_1.lookUpObjectMember)(argType, '__call__', 16 /* MemberAccessFlags.SkipInstanceMembers */);
8561
- if (callMember) {
8562
- const memberType = getTypeOfMember(callMember);
8563
- if ((0, types_1.isOverloadedFunction)(memberType)) {
8564
- return {
8565
- isCompatible,
8566
- argType,
8567
- isTypeIncomplete,
8568
- skippedOverloadArg: true,
8569
- skippedBareTypeVarExpectedType,
8570
- condition,
8571
- };
8572
- }
8573
- }
8574
- }
8575
- }
8576
- }
8577
- let assignTypeFlags = skipSolveTypeVars ? 8 /* AssignTypeFlags.SkipSolveTypeVars */ : 0 /* AssignTypeFlags.Default */;
8521
+ let assignTypeFlags = 0 /* AssignTypeFlags.Default */;
8578
8522
  if (argParam.isinstanceParam) {
8579
8523
  assignTypeFlags |= 16384 /* AssignTypeFlags.AllowIsinstanceSpecialForms */;
8580
8524
  }
8581
- if (!assignType(argParam.paramType, argType, diag.createAddendum(), typeVarContext,
8582
- /* srcTypeVarContext */ undefined, assignTypeFlags)) {
8583
- // Mismatching parameter types are common in untyped code; don't bother spending time
8584
- // printing types if the diagnostic is disabled.
8585
- const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
8586
- if (fileInfo.diagnosticRuleSet.reportArgumentType !== 'none' &&
8587
- !canSkipDiagnosticForNode(argParam.errorNode) &&
8588
- !isTypeIncomplete) {
8589
- const argTypeText = printType(argType);
8590
- const paramTypeText = printType(argParam.paramType);
8591
- let message;
8592
- if (argParam.paramName && !argParam.isParamNameSynthesized) {
8593
- if (functionName) {
8594
- message = localize_1.LocMessage.argAssignmentParamFunction().format({
8595
- argType: argTypeText,
8596
- paramType: paramTypeText,
8597
- functionName,
8598
- paramName: argParam.paramName,
8599
- });
8525
+ if (options === null || options === void 0 ? void 0 : options.isArgFirstPass) {
8526
+ assignTypeFlags |= 8 /* AssignTypeFlags.ArgAssignmentFirstPass */;
8527
+ }
8528
+ if (!assignType(argParam.paramType, argType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints,
8529
+ /* srcConstraints */ undefined, assignTypeFlags)) {
8530
+ if (!(options === null || options === void 0 ? void 0 : options.skipReportError)) {
8531
+ // Mismatching parameter types are common in untyped code; don't bother spending time
8532
+ // printing types if the diagnostic is disabled.
8533
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
8534
+ if (fileInfo.diagnosticRuleSet.reportArgumentType !== 'none' &&
8535
+ !canSkipDiagnosticForNode(argParam.errorNode) &&
8536
+ !isTypeIncomplete) {
8537
+ const argTypeText = printType(argType);
8538
+ const paramTypeText = printType(argParam.paramType);
8539
+ let message;
8540
+ if (argParam.paramName && !argParam.isParamNameSynthesized) {
8541
+ if (functionName) {
8542
+ message = localize_1.LocMessage.argAssignmentParamFunction().format({
8543
+ argType: argTypeText,
8544
+ paramType: paramTypeText,
8545
+ functionName,
8546
+ paramName: argParam.paramName,
8547
+ });
8548
+ }
8549
+ else {
8550
+ message = localize_1.LocMessage.argAssignmentParam().format({
8551
+ argType: argTypeText,
8552
+ paramType: paramTypeText,
8553
+ paramName: argParam.paramName,
8554
+ });
8555
+ }
8600
8556
  }
8601
8557
  else {
8602
- message = localize_1.LocMessage.argAssignmentParam().format({
8603
- argType: argTypeText,
8604
- paramType: paramTypeText,
8605
- paramName: argParam.paramName,
8606
- });
8607
- }
8608
- }
8609
- else {
8610
- if (functionName) {
8611
- message = localize_1.LocMessage.argAssignmentFunction().format({
8612
- argType: argTypeText,
8613
- paramType: paramTypeText,
8614
- functionName,
8615
- });
8558
+ if (functionName) {
8559
+ message = localize_1.LocMessage.argAssignmentFunction().format({
8560
+ argType: argTypeText,
8561
+ paramType: paramTypeText,
8562
+ functionName,
8563
+ });
8564
+ }
8565
+ else {
8566
+ message = localize_1.LocMessage.argAssignment().format({
8567
+ argType: argTypeText,
8568
+ paramType: paramTypeText,
8569
+ });
8570
+ }
8616
8571
  }
8617
- else {
8618
- message = localize_1.LocMessage.argAssignment().format({
8619
- argType: argTypeText,
8620
- paramType: paramTypeText,
8621
- });
8572
+ // If we have an expected type diagnostic addendum, use that
8573
+ // instead of the local diagnostic addendum because it will
8574
+ // be more informative.
8575
+ if (expectedTypeDiag) {
8576
+ diag = expectedTypeDiag;
8622
8577
  }
8578
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, message + (diag === null || diag === void 0 ? void 0 : diag.getString()), argParam.errorNode, (_b = diag === null || diag === void 0 ? void 0 : diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : argParam.errorNode);
8623
8579
  }
8624
- // If we have an expected type diagnostic addendum, use that
8625
- // instead of the local diagnostic addendum because it will
8626
- // be more informative.
8627
- if (expectedTypeDiag) {
8628
- diag = expectedTypeDiag;
8629
- }
8630
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, message + diag.getString(), argParam.errorNode, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : argParam.errorNode);
8631
8580
  }
8632
8581
  return { isCompatible: false, argType, isTypeIncomplete, skippedBareTypeVarExpectedType, condition };
8633
8582
  }
@@ -8699,7 +8648,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8699
8648
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.duplicateParam().format({ name: paramName }), argList[i].valueExpression || errorNode);
8700
8649
  }
8701
8650
  if (paramName === 'bound') {
8702
- if (typeVar.shared.constraints.length > 0) {
8651
+ if (types_1.TypeVarType.hasConstraints(typeVar)) {
8703
8652
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
8704
8653
  }
8705
8654
  else {
@@ -8768,7 +8717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8768
8717
  paramNameMap.set(paramName, paramName);
8769
8718
  }
8770
8719
  else {
8771
- if (typeVar.shared.boundType) {
8720
+ if (types_1.TypeVarType.hasBound(typeVar)) {
8772
8721
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
8773
8722
  }
8774
8723
  else {
@@ -8797,22 +8746,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8797
8746
  }
8798
8747
  function verifyTypeVarDefaultIsCompatible(typeVar, defaultValueNode) {
8799
8748
  (0, debug_1.assert)(typeVar.shared.isDefaultExplicit);
8800
- const typeVarContext = new typeVarContext_1.TypeVarContext(typeVar.priv.scopeId);
8801
- const concreteDefaultType = makeTopLevelTypeVarsConcrete((0, typeUtils_1.applySolvedTypeVars)(typeVar.shared.defaultType, typeVarContext, {
8802
- unknownIfNotFound: true,
8803
- tupleClassType: getTupleClassType(),
8749
+ const constraints = new constraintTracker_1.ConstraintTracker();
8750
+ const concreteDefaultType = makeTopLevelTypeVarsConcrete(solveAndApplyConstraints(typeVar.shared.defaultType, constraints, {
8751
+ replaceUnsolved: {
8752
+ scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(typeVar),
8753
+ tupleClassType: getTupleClassType(),
8754
+ },
8804
8755
  }));
8805
8756
  if (typeVar.shared.boundType) {
8806
8757
  if (!assignType(typeVar.shared.boundType, concreteDefaultType)) {
8807
8758
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), defaultValueNode);
8808
8759
  }
8809
8760
  }
8810
- else if (typeVar.shared.constraints.length > 0) {
8761
+ else if (types_1.TypeVarType.hasConstraints(typeVar)) {
8811
8762
  let isConstraintCompatible = true;
8812
8763
  // If the default type is a constrained TypeVar, make sure all of its constraints
8813
8764
  // are also constraints in typeVar. If the default type is not a constrained TypeVar,
8814
8765
  // use its concrete type to compare against the constraints.
8815
- if ((0, types_1.isTypeVar)(typeVar.shared.defaultType) && typeVar.shared.defaultType.shared.constraints.length > 0) {
8766
+ if ((0, types_1.isTypeVar)(typeVar.shared.defaultType) && types_1.TypeVarType.hasConstraints(typeVar.shared.defaultType)) {
8816
8767
  for (const constraint of typeVar.shared.defaultType.shared.constraints) {
8817
8768
  if (!typeVar.shared.constraints.some((c) => (0, types_1.isTypeSame)(c, constraint))) {
8818
8769
  isConstraintCompatible = false;
@@ -9047,7 +8998,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9047
8998
  typeParamsExpr.d.items.map((expr) => {
9048
8999
  let entryType = getTypeOfExpression(expr, 128 /* EvalFlags.InstantiableType */ | 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */).type;
9049
9000
  if ((0, types_1.isTypeVar)(entryType)) {
9050
- if (entryType.priv.scopeId || ((0, types_1.isTypeVarTuple)(entryType) && entryType.priv.isVariadicUnpacked)) {
9001
+ if (entryType.priv.scopeId || ((0, types_1.isTypeVarTuple)(entryType) && entryType.priv.isUnpacked)) {
9051
9002
  isTypeParamListValid = false;
9052
9003
  }
9053
9004
  else {
@@ -9219,6 +9170,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9219
9170
  }
9220
9171
  function getTypeOfMagicMethodCall(objType, methodName, argList, errorNode, inferenceContext, diag) {
9221
9172
  let magicMethodSupported = true;
9173
+ let isIncomplete = false;
9174
+ let deprecationInfo;
9175
+ const overloadsUsedForCall = [];
9222
9176
  // Create a helper lambda for object subtypes.
9223
9177
  const handleSubtype = (subtype) => {
9224
9178
  let magicMethodType;
@@ -9237,7 +9191,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9237
9191
  callResult = useSpeculativeMode(errorNode, () => {
9238
9192
  (0, debug_1.assert)(magicMethodType !== undefined);
9239
9193
  return validateCallArgs(errorNode, functionArgs, { type: magicMethodType },
9240
- /* typeVarContext */ undefined,
9194
+ /* constraints */ undefined,
9241
9195
  /* skipUnknownArgCheck */ true, inferenceContext);
9242
9196
  });
9243
9197
  // If there were errors with the expected type, try
@@ -9246,7 +9200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9246
9200
  callResult = useSpeculativeMode(errorNode, () => {
9247
9201
  (0, debug_1.assert)(magicMethodType !== undefined);
9248
9202
  return validateCallArgs(errorNode, functionArgs, { type: magicMethodType },
9249
- /* typeVarContext */ undefined,
9203
+ /* constraints */ undefined,
9250
9204
  /* skipUnknownArgCheck */ true,
9251
9205
  /* inferenceContext */ undefined);
9252
9206
  });
@@ -9254,6 +9208,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9254
9208
  if (callResult.argumentErrors) {
9255
9209
  magicMethodSupported = false;
9256
9210
  }
9211
+ else if (callResult.overloadsUsedForCall) {
9212
+ callResult.overloadsUsedForCall.forEach((overload) => {
9213
+ overloadsUsedForCall.push(overload);
9214
+ // If one of the overloads is deprecated, note the message.
9215
+ if (overload.shared.deprecatedMessage && (0, types_1.isClass)(concreteSubtype)) {
9216
+ deprecationInfo = {
9217
+ deprecatedMessage: overload.shared.deprecatedMessage,
9218
+ className: concreteSubtype.shared.name,
9219
+ methodName,
9220
+ };
9221
+ }
9222
+ });
9223
+ }
9224
+ if (callResult.isTypeIncomplete) {
9225
+ isIncomplete = true;
9226
+ }
9257
9227
  return callResult.returnType;
9258
9228
  }
9259
9229
  magicMethodSupported = false;
@@ -9284,7 +9254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9284
9254
  if (!magicMethodSupported) {
9285
9255
  return undefined;
9286
9256
  }
9287
- return returnType;
9257
+ return { type: returnType, isIncomplete, magicMethodDeprecationInfo: deprecationInfo, overloadsUsedForCall };
9288
9258
  }
9289
9259
  function getTypeOfDictionary(node, flags, inferenceContext) {
9290
9260
  var _a;
@@ -9381,11 +9351,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9381
9351
  if (!(0, types_1.isClassInstance)(builtInDict)) {
9382
9352
  return undefined;
9383
9353
  }
9384
- const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
9385
- if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
9354
+ const dictConstraints = new constraintTracker_1.ConstraintTracker();
9355
+ if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictConstraints, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
9386
9356
  return undefined;
9387
9357
  }
9388
- const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
9358
+ const specializedDict = solveAndApplyConstraints(types_1.ClassType.cloneAsInstantiable(builtInDict), dictConstraints);
9389
9359
  if (!specializedDict.priv.typeArgs || specializedDict.priv.typeArgs.length !== 2) {
9390
9360
  return undefined;
9391
9361
  }
@@ -9511,12 +9481,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9511
9481
  (0, typeUtils_1.isLiteralType)(keyType) &&
9512
9482
  (expectedTypedDictEntries.knownItems.has(keyType.priv.literalValue) ||
9513
9483
  expectedTypedDictEntries.extraItems)) {
9514
- const effectiveValueType = (_b = (_a = expectedTypedDictEntries.knownItems.get(keyType.priv.literalValue)) === null || _a === void 0 ? void 0 : _a.valueType) !== null && _b !== void 0 ? _b : (_c = expectedTypedDictEntries.extraItems) === null || _c === void 0 ? void 0 : _c.valueType;
9484
+ let effectiveValueType = (_b = (_a = expectedTypedDictEntries.knownItems.get(keyType.priv.literalValue)) === null || _a === void 0 ? void 0 : _a.valueType) !== null && _b !== void 0 ? _b : (_c = expectedTypedDictEntries.extraItems) === null || _c === void 0 ? void 0 : _c.valueType;
9485
+ if (effectiveValueType) {
9486
+ const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
9487
+ effectiveValueType = (0, typeUtils_1.transformExpectedType)(effectiveValueType, liveTypeVarScopes, node.start);
9488
+ }
9515
9489
  entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
9516
9490
  valueTypeResult = getTypeOfExpression(entryNode.d.valueExpr, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
9517
9491
  }
9518
9492
  else {
9519
- const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
9493
+ let effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
9494
+ if (effectiveValueType) {
9495
+ const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
9496
+ effectiveValueType = (0, typeUtils_1.transformExpectedType)(effectiveValueType, liveTypeVarScopes, node.start);
9497
+ }
9520
9498
  entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
9521
9499
  valueTypeResult = getTypeOfExpression(entryNode.d.valueExpr, flags | 268435456 /* EvalFlags.StripTupleLiterals */, entryInferenceContext);
9522
9500
  }
@@ -9602,12 +9580,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9602
9580
  }
9603
9581
  }
9604
9582
  else if (supportsKeysAndGetItemClass && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass)) {
9605
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemClass));
9583
+ const mappingConstraints = new constraintTracker_1.ConstraintTracker();
9606
9584
  supportsKeysAndGetItemClass = (0, typeUtils_1.selfSpecializeClass)(supportsKeysAndGetItemClass);
9607
9585
  if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), unexpandedType,
9608
- /* diag */ undefined, mappingTypeVarContext,
9609
- /* srcTypeVarContext */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
9610
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
9586
+ /* diag */ undefined, mappingConstraints,
9587
+ /* srcConstraints */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
9588
+ const specializedMapping = solveAndApplyConstraints(supportsKeysAndGetItemClass, mappingConstraints);
9611
9589
  const typeArgs = specializedMapping.priv.typeArgs;
9612
9590
  if (typeArgs && typeArgs.length >= 2) {
9613
9591
  if (forceStrictInference || index < maxEntriesToUseForInference) {
@@ -9763,11 +9741,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9763
9741
  if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
9764
9742
  return undefined;
9765
9743
  }
9766
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(expectedClassType));
9767
- if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
9744
+ const constraints = new constraintTracker_1.ConstraintTracker();
9745
+ if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, constraints, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
9768
9746
  return undefined;
9769
9747
  }
9770
- const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(expectedClassType, typeVarContext);
9748
+ const specializedListOrSet = solveAndApplyConstraints(expectedClassType, constraints);
9771
9749
  if (!specializedListOrSet.priv.typeArgs) {
9772
9750
  return undefined;
9773
9751
  }
@@ -9851,11 +9829,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9851
9829
  if ((0, types_1.isAny)(inferenceContext.expectedType)) {
9852
9830
  return inferenceContext.expectedType;
9853
9831
  }
9854
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(inferenceContext.expectedType));
9832
+ const constraints = new constraintTracker_1.ConstraintTracker();
9855
9833
  const expectedType = inferenceContext.expectedType;
9856
9834
  let isCompatible = true;
9857
9835
  entryTypes.forEach((entryType) => {
9858
- if (isCompatible && !assignType(expectedType, entryType, /* diag */ undefined, typeVarContext)) {
9836
+ if (isCompatible && !assignType(expectedType, entryType, /* diag */ undefined, constraints)) {
9859
9837
  isCompatible = false;
9860
9838
  }
9861
9839
  });
@@ -9868,7 +9846,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9868
9846
  ? combinedTypes
9869
9847
  : stripLiteralValue(combinedTypes);
9870
9848
  }
9871
- return (0, typeUtils_1.mapSubtypes)((0, typeUtils_1.applySolvedTypeVars)(inferenceContext.expectedType, typeVarContext, { applyInScopePlaceholders: true }), (subtype) => {
9849
+ return (0, typeUtils_1.mapSubtypes)(solveAndApplyConstraints(inferenceContext.expectedType, constraints, {
9850
+ replaceUnsolved: {
9851
+ scopeIds: [],
9852
+ tupleClassType: getTupleClassType(),
9853
+ },
9854
+ }, { applyUnificationVars: true }), (subtype) => {
9872
9855
  if (entryTypes.length !== 1) {
9873
9856
  return subtype;
9874
9857
  }
@@ -9894,11 +9877,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9894
9877
  let returnType = types_1.FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
9895
9878
  if (returnType) {
9896
9879
  const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(node);
9897
- returnType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(returnType, liveScopeIds);
9880
+ returnType = (0, typeUtils_1.makeTypeVarsBound)(returnType, liveScopeIds);
9898
9881
  expectedYieldType = (0, typeUtils_1.getGeneratorYieldType)(returnType, !!enclosingFunction.d.isAsync);
9899
9882
  const generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(returnType);
9900
9883
  if (generatorTypeArgs && generatorTypeArgs.length >= 2) {
9901
- sentType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(generatorTypeArgs[1], liveScopeIds);
9884
+ sentType = (0, typeUtils_1.makeTypeVarsBound)(generatorTypeArgs[1], liveScopeIds);
9902
9885
  }
9903
9886
  }
9904
9887
  }
@@ -10082,12 +10065,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10082
10065
  // If the expectedReturnType is generic, see if the actual return type
10083
10066
  // provides types for some or all type variables.
10084
10067
  if ((0, typeUtils_1.requiresSpecialization)(expectedReturnType)) {
10085
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType));
10086
- if (assignType(expectedReturnType, returnTypeResult.type,
10087
- /* diag */ undefined, typeVarContext)) {
10088
- functionType = (0, typeUtils_1.applySolvedTypeVars)(functionType, typeVarContext, {
10089
- applyInScopePlaceholders: true,
10090
- });
10068
+ const constraints = new constraintTracker_1.ConstraintTracker();
10069
+ if (assignType(expectedReturnType, returnTypeResult.type, /* diag */ undefined, constraints)) {
10070
+ functionType = solveAndApplyConstraints(functionType, constraints, {
10071
+ replaceUnsolved: {
10072
+ scopeIds: [],
10073
+ tupleClassType: getTupleClassType(),
10074
+ },
10075
+ }, { applyUnificationVars: true });
10091
10076
  }
10092
10077
  }
10093
10078
  }
@@ -10290,7 +10275,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10290
10275
  return false;
10291
10276
  }
10292
10277
  }
10293
- if ((0, types_1.isTypeVarTuple)(argResult.type) && !argResult.type.priv.isVariadicInUnion) {
10278
+ if ((0, types_1.isTypeVarTuple)(argResult.type) && !argResult.type.priv.isInUnion) {
10294
10279
  if (!(options === null || options === void 0 ? void 0 : options.allowTypeVarTuple)) {
10295
10280
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeVarTupleContext(), argResult.node);
10296
10281
  return false;
@@ -10328,7 +10313,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10328
10313
  let sawUnpacked = false;
10329
10314
  let reportedUnpackedError = false;
10330
10315
  const noteSawUnpacked = (entry) => {
10331
- // Make sure we have at most one unpacked variadic type variable.
10316
+ // Make sure we have at most one unpacked TypeVarTuple.
10332
10317
  if (sawUnpacked) {
10333
10318
  if (!reportedUnpackedError) {
10334
10319
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.variadicTypeArgsTooMany(), entry.node);
@@ -10416,7 +10401,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10416
10401
  functionType.shared.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
10417
10402
  }
10418
10403
  if (paramSpec) {
10419
- types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
10404
+ types_1.FunctionType.addParamSpecVariadics(functionType, (0, typeUtils_1.convertToInstance)(paramSpec));
10420
10405
  }
10421
10406
  return functionType;
10422
10407
  }
@@ -10653,7 +10638,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10653
10638
  const annotationType = getTypeOfAnnotation(firstParamTypeAnnotation, {
10654
10639
  typeVarGetsCurScope: true,
10655
10640
  });
10656
- if (!(0, types_1.isTypeVar)(annotationType) || !annotationType.shared.isSynthesizedSelf) {
10641
+ if (!(0, types_1.isTypeVar)(annotationType) || !types_1.TypeVarType.isSelf(annotationType)) {
10657
10642
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.selfTypeWithTypedSelfOrCls(), errorNode);
10658
10643
  }
10659
10644
  }
@@ -10663,11 +10648,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10663
10648
  let result = (0, typeUtils_1.synthesizeTypeVarForSelfCls)(enclosingClassTypeResult.classType, /* isClsParam */ true);
10664
10649
  if (enclosingClass) {
10665
10650
  // If "Self" is used as a type expression within a function suite, it needs
10666
- // to be marked as "internal".
10651
+ // to be marked as bound.
10667
10652
  const enclosingSuite = ParseTreeUtils.getEnclosingClassOrFunctionSuite(errorNode);
10668
10653
  if (enclosingSuite && ParseTreeUtils.isNodeContainedWithin(enclosingSuite, enclosingClass)) {
10669
10654
  if (enclosingClass.d.suite !== enclosingSuite) {
10670
- result = types_1.TypeVarType.cloneWithInternalScopeId(result);
10655
+ result = types_1.TypeVarType.cloneAsBound(result);
10671
10656
  }
10672
10657
  }
10673
10658
  }
@@ -10751,7 +10736,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10751
10736
  if ((0, types_1.isInstantiableClass)(typeArgType) && !typeArgType.priv.includeSubclasses && (0, typeUtils_1.isTupleClass)(typeArgType)) {
10752
10737
  return types_1.ClassType.cloneForUnpacked(typeArgType);
10753
10738
  }
10754
- if ((0, types_1.isTypeVarTuple)(typeArgType) && !typeArgType.priv.isVariadicUnpacked) {
10739
+ if ((0, types_1.isTypeVarTuple)(typeArgType) && !typeArgType.priv.isUnpacked) {
10755
10740
  return types_1.TypeVarType.cloneForUnpacked(typeArgType);
10756
10741
  }
10757
10742
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.unpackExpectedTypeVarTuple(), errorNode);
@@ -10858,7 +10843,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10858
10843
  typeResult: { type: (0, typeUtils_1.convertToInstance)(annotatedType) },
10859
10844
  },
10860
10845
  ], { type: supportsTypeMethod },
10861
- /* typeVarContext */ undefined,
10846
+ /* constraints */ undefined,
10862
10847
  /* skipUnknownArgCheck */ true,
10863
10848
  /* inferenceContext */ undefined));
10864
10849
  if (callResult.isTypeIncomplete || !callResult.returnType) {
@@ -10911,7 +10896,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10911
10896
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.ellipsisSecondArg(), typeArg.node);
10912
10897
  }
10913
10898
  else {
10914
- if ((0, types_1.isTypeVarTuple)(typeArgs[0].type) && !typeArgs[0].type.priv.isVariadicInUnion) {
10899
+ if ((0, types_1.isTypeVarTuple)(typeArgs[0].type) && !typeArgs[0].type.priv.isInUnion) {
10915
10900
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeVarTupleContext(), typeArgs[0].node);
10916
10901
  }
10917
10902
  else if ((0, types_1.isUnpackedClass)(typeArgs[0].type)) {
@@ -10923,7 +10908,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10923
10908
  // Nothing to do - this is allowed.
10924
10909
  }
10925
10910
  else if (paramLimit === undefined && (0, types_1.isTypeVarTuple)(typeArg.type)) {
10926
- if (!typeArg.type.priv.isVariadicInUnion) {
10911
+ if (!typeArg.type.priv.isInUnion) {
10927
10912
  noteSawUnpacked(typeArg);
10928
10913
  }
10929
10914
  validateTypeVarTupleIsUnpacked(typeArg.type, typeArg.node);
@@ -11046,7 +11031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11046
11031
  }
11047
11032
  }
11048
11033
  // Validate that we received at least two type arguments. One type argument
11049
- // is allowed if it's an unpacked variadic type var or tuple. None is also allowed
11034
+ // is allowed if it's an unpacked TypeVarTuple or tuple. None is also allowed
11050
11035
  // since it is used to define NoReturn in typeshed stubs).
11051
11036
  if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
11052
11037
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
@@ -11137,7 +11122,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11137
11122
  }
11138
11123
  validateTypeParamDefault(bestErrorNode, typeParam, typeParams.slice(0, index), typeAliasScopeId);
11139
11124
  });
11140
- // Verify that we have at most one variadic type variable.
11125
+ // Verify that we have at most one TypeVarTuple.
11141
11126
  const variadics = typeParams.filter((param) => (0, types_1.isTypeVarTuple)(param));
11142
11127
  if (variadics.length > 1) {
11143
11128
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.variadicTypeParamTooManyAlias().format({
@@ -11153,7 +11138,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11153
11138
  }
11154
11139
  }
11155
11140
  const fileInfo = AnalyzerNodeInfo.getFileInfo(name);
11156
- let typeAlias = types_1.TypeBase.cloneForTypeAlias(type, name.d.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.d.value), fileInfo.moduleName, fileInfo.fileUri, typeAliasScopeId, isPep695Syntax, typeParams.length > 0 ? typeParams : undefined);
11141
+ let typeAlias = types_1.TypeBase.cloneForTypeAlias(type, {
11142
+ name: name.d.value,
11143
+ fullName: ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.d.value),
11144
+ moduleName: fileInfo.moduleName,
11145
+ fileUri: fileInfo.fileUri,
11146
+ typeVarScopeId: typeAliasScopeId,
11147
+ isPep695Syntax,
11148
+ typeParams: typeParams.length > 0 ? typeParams : undefined,
11149
+ usageVariance: undefined,
11150
+ typeArgs: undefined,
11151
+ });
11157
11152
  // All PEP 695 type aliases are special forms because they are
11158
11153
  // TypeAliasType objects at runtime.
11159
11154
  if (isPep695Syntax || isPep695TypeVarType) {
@@ -11886,7 +11881,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11886
11881
  if (classType.shared.typeParams.some((param) => param.shared.declaredVariance === 0 /* Variance.Auto */ && param.priv.computedVariance === undefined)) {
11887
11882
  classType.shared.requiresVarianceInference = true;
11888
11883
  }
11889
- // Make sure there's at most one variadic type parameter.
11884
+ // Make sure there's at most one TypeVarTuple.
11890
11885
  const variadics = typeParams.filter((param) => (0, types_1.isTypeVarTuple)(param));
11891
11886
  if (variadics.length > 1) {
11892
11887
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.variadicTypeParamTooManyClass().format({
@@ -11894,7 +11889,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11894
11889
  }), node.d.name, textRange_1.TextRange.combine(node.d.arguments) || node.d.name);
11895
11890
  }
11896
11891
  else if (variadics.length > 0) {
11897
- // Make sure a TypeVar with a default doesn't come after a variadic type parameter.
11892
+ // Make sure a TypeVar with a default doesn't come after a TypeVarTuple.
11898
11893
  const firstVariadicIndex = classType.shared.typeParams.findIndex((param) => (0, types_1.isTypeVarTuple)(param));
11899
11894
  const typeVarWithDefaultIndex = classType.shared.typeParams.findIndex((param, index) => index > firstVariadicIndex && !(0, types_1.isParamSpec)(param) && param.shared.isDefaultExplicit);
11900
11895
  if (typeVarWithDefaultIndex >= 0) {
@@ -12138,9 +12133,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12138
12133
  // parameters and updates the scope of the type parameter referred to in the
12139
12134
  // default type expression.
12140
12135
  function validateTypeParamDefault(errorNode, typeParam, otherLiveTypeParams, scopeId) {
12141
- if (!typeParam.shared.isDefaultExplicit &&
12142
- !typeParam.shared.isSynthesized &&
12143
- !typeParam.shared.isSynthesizedSelf) {
12136
+ if (!typeParam.shared.isDefaultExplicit && !typeParam.shared.isSynthesized && !types_1.TypeVarType.isSelf(typeParam)) {
12144
12137
  const typeVarWithDefault = otherLiveTypeParams.find((param) => param.shared.isDefaultExplicit && param.priv.scopeId === scopeId);
12145
12138
  if (typeVarWithDefault) {
12146
12139
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithoutDefault().format({
@@ -12179,7 +12172,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12179
12172
  });
12180
12173
  const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', uri_1.Uri.empty(), 0, 0, undefined, undefined);
12181
12174
  classType.shared.typeParams.forEach((param, paramIndex) => {
12182
- // Skip variadics and ParamSpecs.
12175
+ // Skip TypeVarTuples and ParamSpecs.
12183
12176
  if ((0, types_1.isTypeVarTuple)(param) || (0, types_1.isParamSpec)(param)) {
12184
12177
  return;
12185
12178
  }
@@ -12413,7 +12406,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12413
12406
  argument: arg,
12414
12407
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : node.d.name,
12415
12408
  };
12416
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), { type: newMethodType }, { skipUnknownArgCheck: true, skipOverloadArg: true });
12409
+ validateArgType(argParam, new constraintTracker_1.ConstraintTracker(), { type: newMethodType }, { skipUnknownArgCheck: true });
12417
12410
  paramMap.delete(arg.name.d.value);
12418
12411
  }
12419
12412
  else {
@@ -12426,7 +12419,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12426
12419
  const unassignedParams = [];
12427
12420
  paramMap.forEach((index, paramName) => {
12428
12421
  const paramInfo = paramListDetails.params[index];
12429
- if (!paramInfo.param.defaultType) {
12422
+ if (!paramInfo.defaultType) {
12430
12423
  unassignedParams.push(paramName);
12431
12424
  }
12432
12425
  });
@@ -12451,7 +12444,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12451
12444
  const initSubclassMethodType = initSubclassMethodInfo.type;
12452
12445
  if (initSubclassMethodType && initSubclassMethodInfo.classType) {
12453
12446
  const callResult = validateCallArgs(node.d.name, argList, { type: initSubclassMethodType },
12454
- /* typeVarContext */ undefined,
12447
+ /* constraints */ undefined,
12455
12448
  /* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()));
12456
12449
  if (callResult.argumentErrors) {
12457
12450
  const diag = addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initSubclassCallFailed(), node.d.name);
@@ -12682,7 +12675,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12682
12675
  if (annotatedType) {
12683
12676
  (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParamsSeen, (0, typeUtils_1.getTypeVarArgsRecursive)(annotatedType), functionType.shared.typeVarScopeId);
12684
12677
  }
12685
- if ((0, types_1.isTypeVarTuple)(annotatedType) && !annotatedType.priv.isVariadicUnpacked) {
12678
+ if ((0, types_1.isTypeVarTuple)(annotatedType) && !annotatedType.priv.isUnpacked) {
12686
12679
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
12687
12680
  name1: annotatedType.shared.name,
12688
12681
  name2: annotatedType.shared.name,
@@ -12724,13 +12717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12724
12717
  // that the default value matches the annotation.
12725
12718
  if (param.d.defaultValue && defaultValueType) {
12726
12719
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12727
- const typeVarContext = new typeVarContext_1.TypeVarContext(functionType.shared.typeVarScopeId);
12728
- if (containingClassType && containingClassType.shared.typeVarScopeId !== undefined) {
12729
- if (node.d.name.d.value === '__init__' || node.d.name.d.value === '__new__') {
12730
- typeVarContext.addSolveForScope(containingClassType.shared.typeVarScopeId);
12731
- }
12732
- }
12733
- if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
12720
+ if (!assignType(annotatedType, defaultValueType, diagAddendum)) {
12734
12721
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
12735
12722
  sourceType: printType(defaultValueType),
12736
12723
  paramType: printType(annotatedType),
@@ -12777,18 +12764,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12777
12764
  paramType = inferredType;
12778
12765
  }
12779
12766
  }
12780
- const functionParam = types_1.FunctionParam.create(param.d.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(), (isTypeInferred ? types_1.FunctionParamFlags.TypeInferred : types_1.FunctionParamFlags.None) |
12767
+ paramType = paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create();
12768
+ const functionParam = types_1.FunctionParam.create(param.d.category, paramType, (isTypeInferred ? types_1.FunctionParamFlags.TypeInferred : types_1.FunctionParamFlags.None) |
12781
12769
  (paramTypeNode ? types_1.FunctionParamFlags.TypeDeclared : types_1.FunctionParamFlags.None), param.d.name ? param.d.name.d.value : undefined, defaultValueType);
12782
12770
  types_1.FunctionType.addParam(functionType, functionParam);
12783
12771
  if (types_1.FunctionParam.isTypeDeclared(functionParam)) {
12784
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParamsSeen, (0, typeUtils_1.getTypeVarArgsRecursive)(functionParam.type), functionType.shared.typeVarScopeId);
12772
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParamsSeen, (0, typeUtils_1.getTypeVarArgsRecursive)(paramType), functionType.shared.typeVarScopeId);
12785
12773
  }
12786
12774
  if (param.d.name) {
12787
- const variadicParamType = transformVariadicParamType(node, param.d.category, functionParam.type);
12775
+ const variadicParamType = transformVariadicParamType(node, param.d.category, paramType);
12788
12776
  paramTypes.push(variadicParamType);
12789
12777
  }
12790
12778
  else {
12791
- paramTypes.push(functionParam.type);
12779
+ paramTypes.push(paramType);
12792
12780
  }
12793
12781
  });
12794
12782
  if (paramsArePositionOnly && functionType.shared.parameters.length > firstNonClsSelfParamIndex) {
@@ -12802,7 +12790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12802
12790
  if ((0, types_1.isUnknown)(paramType)) {
12803
12791
  functionType.shared.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
12804
12792
  }
12805
- paramType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(paramType, scopeIds);
12793
+ paramType = (0, typeUtils_1.makeTypeVarsBound)(paramType, scopeIds);
12806
12794
  writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvalFlags.None */);
12807
12795
  }
12808
12796
  });
@@ -12821,7 +12809,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12821
12809
  // If the function contains an *args and a **kwargs parameter and both
12822
12810
  // are annotated as Any or are unannotated, make it exempt from
12823
12811
  // args/kwargs compatibility checks.
12824
- const variadicsWithAnyType = functionType.shared.parameters.filter((param) => param.category !== 0 /* ParamCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
12812
+ const variadicsWithAnyType = functionType.shared.parameters.filter((param, index) => param.category !== 0 /* ParamCategory.Simple */ &&
12813
+ param.name &&
12814
+ (0, types_1.isAnyOrUnknown)(types_1.FunctionType.getParamType(functionType, index)));
12825
12815
  if (variadicsWithAnyType.length >= 2) {
12826
12816
  functionType.shared.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12827
12817
  }
@@ -12944,13 +12934,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12944
12934
  // If the parameter type is generic, specialize it in the context
12945
12935
  // of the child class.
12946
12936
  if ((0, typeUtils_1.requiresSpecialization)(inferredParamType) && (0, types_1.isClass)(baseClassMemberInfo.classType)) {
12947
- const typeVarContext = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(baseClassMemberInfo.classType);
12948
- // Add the scope of the method to handle any function-scoped TypeVars.
12949
- typeVarContext.addSolveForScope(ParseTreeUtils.getScopeIdForNode(baseClassMethodNode));
12937
+ const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(baseClassMemberInfo.classType);
12938
+ const solution = (0, typeUtils_1.buildSolutionFromSpecializedClass)(baseClassMemberInfo.classType);
12939
+ scopeIds.push(ParseTreeUtils.getScopeIdForNode(baseClassMethodNode));
12950
12940
  // Replace any unsolved TypeVars with Unknown (including all function-scoped TypeVars).
12951
- inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, typeVarContext, {
12952
- unknownIfNotFound: true,
12953
- tupleClassType: getTupleClassType(),
12941
+ inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, solution, {
12942
+ replaceUnsolved: {
12943
+ scopeIds,
12944
+ tupleClassType: getTupleClassType(),
12945
+ },
12954
12946
  });
12955
12947
  }
12956
12948
  const fileInfo = AnalyzerNodeInfo.getFileInfo(functionNode);
@@ -13367,14 +13359,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13367
13359
  // Verify that the target has an __enter__ or __aenter__ method defined.
13368
13360
  const enterMethodName = isAsync ? '__aenter__' : '__enter__';
13369
13361
  const scopedType = (0, typeUtils_1.mapSubtypes)(exprType, (subtype) => {
13362
+ var _a, _b;
13370
13363
  subtype = makeTopLevelTypeVarsConcrete(subtype);
13371
13364
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
13372
13365
  return subtype;
13373
13366
  }
13374
13367
  const additionalHelp = new diagnostic_1.DiagnosticAddendum();
13375
13368
  if ((0, types_1.isClass)(subtype)) {
13376
- let enterType = getTypeOfMagicMethodCall(subtype, enterMethodName, [], node.d.expr,
13377
- /* inferenceContext */ undefined, additionalHelp.createAddendum());
13369
+ let enterType = (_a = getTypeOfMagicMethodCall(subtype, enterMethodName, [], node.d.expr,
13370
+ /* inferenceContext */ undefined, additionalHelp.createAddendum())) === null || _a === void 0 ? void 0 : _a.type;
13378
13371
  if (enterType) {
13379
13372
  // For "async while", an implicit "await" is performed.
13380
13373
  if (isAsync) {
@@ -13383,8 +13376,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13383
13376
  return enterType;
13384
13377
  }
13385
13378
  if (!isAsync) {
13386
- if (getTypeOfMagicMethodCall(subtype, '__aenter__', [], node.d.expr,
13387
- /* inferenceContext */ undefined)) {
13379
+ if ((_b = getTypeOfMagicMethodCall(subtype, '__aenter__', [], node.d.expr,
13380
+ /* inferenceContext */ undefined)) === null || _b === void 0 ? void 0 : _b.type) {
13388
13381
  additionalHelp.addMessage(localize_1.LocAddendum.asyncHelp());
13389
13382
  }
13390
13383
  }
@@ -13396,14 +13389,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13396
13389
  // Verify that the target has an __exit__ or __aexit__ method defined.
13397
13390
  const exitMethodName = isAsync ? '__aexit__' : '__exit__';
13398
13391
  (0, typeUtils_1.doForEachSubtype)(exprType, (subtype) => {
13392
+ var _a;
13399
13393
  subtype = makeTopLevelTypeVarsConcrete(subtype);
13400
13394
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
13401
13395
  return;
13402
13396
  }
13403
13397
  if ((0, types_1.isClass)(subtype)) {
13404
13398
  const anyArg = { type: types_1.AnyType.create() };
13405
- const exitType = getTypeOfMagicMethodCall(subtype, exitMethodName, [anyArg, anyArg, anyArg], node.d.expr,
13406
- /* inferenceContext */ undefined);
13399
+ const exitType = (_a = getTypeOfMagicMethodCall(subtype, exitMethodName, [anyArg, anyArg, anyArg], node.d.expr,
13400
+ /* inferenceContext */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
13407
13401
  if (exitType) {
13408
13402
  return;
13409
13403
  }
@@ -13937,7 +13931,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13937
13931
  : undefined;
13938
13932
  if (declaredReturnType) {
13939
13933
  const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(node);
13940
- declaredReturnType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(declaredReturnType, liveScopeIds);
13934
+ declaredReturnType = (0, typeUtils_1.makeTypeVarsBound)(declaredReturnType, liveScopeIds);
13941
13935
  }
13942
13936
  getTypeOfExpression(parent.d.expr, 0 /* EvalFlags.None */, (0, typeUtils_1.makeInferenceContext)(declaredReturnType));
13943
13937
  return;
@@ -13993,7 +13987,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13993
13987
  const typeParamName = getPseudoGenericTypeVarName(node.d.name.d.value);
13994
13988
  const paramType = classInfo.classType.shared.typeParams.find((param) => param.shared.name === typeParamName);
13995
13989
  if (paramType) {
13996
- writeTypeCache(node.d.name, { type: types_1.TypeVarType.cloneWithInternalScopeId(paramType) }, 0 /* EvalFlags.None */);
13990
+ writeTypeCache(node.d.name, { type: types_1.TypeVarType.cloneAsBound(paramType) }, 0 /* EvalFlags.None */);
13997
13991
  return;
13998
13992
  }
13999
13993
  }
@@ -14004,7 +13998,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14004
13998
  /* isInClass */ true).flags;
14005
13999
  let inferredParamType = (_a = inferParamType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
14006
14000
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
14007
- inferredParamType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(inferredParamType, liveTypeVarScopes);
14001
+ inferredParamType = (0, typeUtils_1.makeTypeVarsBound)(inferredParamType, liveTypeVarScopes);
14008
14002
  writeTypeCache(node.d.name, { type: transformVariadicParamType(node, node.d.category, inferredParamType) }, 0 /* EvalFlags.None */);
14009
14003
  }
14010
14004
  // Evaluates the types that are assigned within the statement that contains
@@ -14390,8 +14384,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14390
14384
  }
14391
14385
  typeArgs.forEach((typeArg, index) => {
14392
14386
  if (index === variadicTypeParamIndex) {
14393
- // The types that make up the tuple that maps to the variadic
14394
- // type variable have already been validated when the tuple
14387
+ // The types that make up the tuple that maps to the
14388
+ // TypeVarTuple have already been validated when the tuple
14395
14389
  // object was created in adjustTypeArgsForTypeVarTuple.
14396
14390
  if ((0, types_1.isClassInstance)(typeArg.type) && (0, typeUtils_1.isTupleClass)(typeArg.type)) {
14397
14391
  return;
@@ -14444,7 +14438,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14444
14438
  }
14445
14439
  }
14446
14440
  }
14447
- const typeVarContext = new typeVarContext_1.TypeVarContext(classType.shared.typeVarScopeId);
14441
+ const constraints = new constraintTracker_1.ConstraintTracker();
14448
14442
  fullTypeParams.forEach((typeParam, index) => {
14449
14443
  if (typeArgs && index < typeArgs.length) {
14450
14444
  if ((0, types_1.isParamSpec)(typeParam)) {
@@ -14454,7 +14448,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14454
14448
  types_1.FunctionType.addDefaultParams(functionType);
14455
14449
  functionType.shared.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
14456
14450
  typeArgTypes.push(functionType);
14457
- (0, typeUtils_1.setTypeVarType)(typeVarContext, typeParam, functionType);
14451
+ constraints.setBounds(typeParam, functionType);
14458
14452
  return;
14459
14453
  }
14460
14454
  if (typeArg.typeList) {
@@ -14465,7 +14459,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14465
14459
  types_1.FunctionType.addPositionOnlyParamSeparator(functionType);
14466
14460
  }
14467
14461
  typeArgTypes.push(functionType);
14468
- (0, typeUtils_1.setTypeVarType)(typeVarContext, typeParam, functionType);
14462
+ constraints.setBounds(typeParam, functionType);
14469
14463
  return;
14470
14464
  }
14471
14465
  if ((0, types_1.isInstantiableClass)(typeArg.type) && types_1.ClassType.isBuiltIn(typeArg.type, 'Concatenate')) {
@@ -14492,15 +14486,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14492
14486
  }
14493
14487
  const typeArgType = (0, typeUtils_1.convertToInstance)(typeArgs[index].type);
14494
14488
  typeArgTypes.push(typeArgType);
14495
- (0, typeUtils_1.setTypeVarType)(typeVarContext, typeParam, typeArgType);
14489
+ constraints.setBounds(typeParam, typeArgType);
14496
14490
  return;
14497
14491
  }
14498
- const solvedDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeParam, typeVarContext, {
14499
- unknownIfNotFound: true,
14500
- tupleClassType: getTupleClassType(),
14492
+ const solvedDefaultType = solveAndApplyConstraints(typeParam, constraints, {
14493
+ replaceUnsolved: {
14494
+ scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(classType),
14495
+ tupleClassType: getTupleClassType(),
14496
+ },
14501
14497
  });
14502
14498
  typeArgTypes.push(solvedDefaultType);
14503
- (0, typeUtils_1.setTypeVarType)(typeVarContext, typeParam, solvedDefaultType);
14499
+ constraints.setBounds(typeParam, solvedDefaultType);
14504
14500
  });
14505
14501
  typeArgTypes = typeArgTypes.map((typeArgType, index) => {
14506
14502
  if (index < typeArgCount) {
@@ -14806,7 +14802,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14806
14802
  return type;
14807
14803
  }
14808
14804
  if ((0, types_1.isFunction)(type) || (0, types_1.isOverloadedFunction)(type)) {
14809
- return (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(type, tracker, node.start);
14805
+ return (0, typeUtils_1.ensureSignaturesAreUnique)(type, tracker, node.start);
14810
14806
  }
14811
14807
  return type;
14812
14808
  }
@@ -15151,7 +15147,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15151
15147
  if (typeAnnotationNode) {
15152
15148
  let declaredType = getTypeOfParamAnnotation(typeAnnotationNode, declaration.node.d.category);
15153
15149
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(declaration.node);
15154
- declaredType = (0, typeUtils_1.updateTypeWithInternalTypeVars)(declaredType, liveTypeVarScopes);
15150
+ declaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveTypeVarScopes);
15155
15151
  return {
15156
15152
  type: transformVariadicParamType(declaration.node, declaration.node.d.category, adjustParamAnnotatedType(declaration.node, declaredType)),
15157
15153
  };
@@ -15186,12 +15182,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15186
15182
  }
15187
15183
  if (declaredType) {
15188
15184
  // If this is a declaration for a member variable within a method,
15189
- // we need to convert any "internal" TypeVars associated with the
15190
- // class to their "external" counterparts.
15185
+ // we need to convert any bound TypeVars associated with the
15186
+ // class to their free counterparts.
15191
15187
  if (declaration.isDefinedByMemberAccess) {
15192
15188
  const enclosingClass = ParseTreeUtils.getEnclosingClass(declaration.node);
15193
15189
  if (enclosingClass) {
15194
- declaredType = (0, typeUtils_1.updateTypeWithExternalTypeVars)(declaredType, [
15190
+ declaredType = (0, typeUtils_1.makeTypeVarsFree)(declaredType, [
15195
15191
  ParseTreeUtils.getScopeIdForNode(enclosingClass),
15196
15192
  ]);
15197
15193
  }
@@ -15242,6 +15238,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15242
15238
  const constraintType = getTypeOfExpressionExpectingType(constraint, {
15243
15239
  noNonTypeSpecialForms: true,
15244
15240
  forwardRefs: true,
15241
+ typeExpression: true,
15245
15242
  }).type;
15246
15243
  if ((0, typeUtils_1.requiresSpecialization)(constraintType, {
15247
15244
  ignorePseudoGeneric: true,
@@ -15942,6 +15939,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15942
15939
  if (types_1.FunctionType.isStubDefinition(type)) {
15943
15940
  return types_1.UnknownType.create();
15944
15941
  }
15942
+ // Don't infer the return type for a ParamSpec value.
15943
+ if (types_1.FunctionType.isParamSpecValue(type)) {
15944
+ return types_1.UnknownType.create();
15945
+ }
15945
15946
  // Don't infer the return type for an overloaded function (unless it's synthesized,
15946
15947
  // which is needed for proper operation of the __get__ method in properties).
15947
15948
  if (types_1.FunctionType.isOverloaded(type) && !types_1.FunctionType.isSynthesizedMethod(type)) {
@@ -15995,7 +15996,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15995
15996
  if ((_a = type.shared.methodClass) === null || _a === void 0 ? void 0 : _a.shared.typeVarScopeId) {
15996
15997
  typeVarScopes.push(type.shared.methodClass.shared.typeVarScopeId);
15997
15998
  }
15998
- returnType = (0, typeUtils_1.updateTypeWithExternalTypeVars)(returnType, typeVarScopes);
15999
+ returnType = (0, typeUtils_1.makeTypeVarsFree)(returnType, typeVarScopes);
15999
16000
  // Cache the type for next time.
16000
16001
  if (!isIncomplete) {
16001
16002
  type.priv.inferredReturnType = returnType;
@@ -16031,7 +16032,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16031
16032
  if ((_c = type.shared.declaration) === null || _c === void 0 ? void 0 : _c.node) {
16032
16033
  // Externalize any TypeVars that appear in the type.
16033
16034
  const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(type.shared.declaration.node);
16034
- returnType = (0, typeUtils_1.updateTypeWithExternalTypeVars)(returnType, liveScopeIds);
16035
+ returnType = (0, typeUtils_1.makeTypeVarsFree)(returnType, liveScopeIds);
16035
16036
  }
16036
16037
  }
16037
16038
  }
@@ -16061,8 +16062,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16061
16062
  if (returnTypeInferenceContextStack.some((context) => context.functionNode === functionNode)) {
16062
16063
  return undefined;
16063
16064
  }
16064
- const functionType = getTypeOfFunction(functionNode);
16065
- if (!functionType) {
16065
+ const functionTypeResult = getTypeOfFunction(functionNode);
16066
+ if (!functionTypeResult) {
16066
16067
  return undefined;
16067
16068
  }
16068
16069
  // Very complex functions with many arguments can take a long time to analyze,
@@ -16113,11 +16114,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16113
16114
  else if (index === 0) {
16114
16115
  // If this is an instance or class method, use the implied
16115
16116
  // parameter type for the "self" or "cls" parameter.
16116
- if (types_1.FunctionType.isInstanceMethod(functionType.functionType) ||
16117
- types_1.FunctionType.isClassMethod(functionType.functionType)) {
16118
- if (functionType.functionType.shared.parameters.length > 0) {
16117
+ if (types_1.FunctionType.isInstanceMethod(functionTypeResult.functionType) ||
16118
+ types_1.FunctionType.isClassMethod(functionTypeResult.functionType)) {
16119
+ if (functionTypeResult.functionType.shared.parameters.length > 0) {
16119
16120
  if (functionNode.d.params[0].d.name) {
16120
- paramType = functionType.functionType.shared.parameters[0].type;
16121
+ paramType = types_1.FunctionType.getParamType(functionTypeResult.functionType, 0);
16121
16122
  }
16122
16123
  }
16123
16124
  }
@@ -16137,7 +16138,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16137
16138
  if (!allArgTypesAreUnknown) {
16138
16139
  // See if the return type is already cached. If so, skip the
16139
16140
  // inference step, which is potentially very expensive.
16140
- const cacheEntry = (_a = functionType.functionType.priv.callSiteReturnTypeCache) === null || _a === void 0 ? void 0 : _a.find((entry) => {
16141
+ const cacheEntry = (_a = functionTypeResult.functionType.priv.callSiteReturnTypeCache) === null || _a === void 0 ? void 0 : _a.find((entry) => {
16141
16142
  return (entry.paramTypes.length === paramTypes.length &&
16142
16143
  entry.paramTypes.every((t, i) => (0, types_1.isTypeSame)(t, paramTypes[i])));
16143
16144
  });
@@ -16159,14 +16160,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16159
16160
  contextualReturnType = (0, types_1.removeUnbound)(contextualReturnType);
16160
16161
  if (!isResultFromCache) {
16161
16162
  // Cache the resulting type.
16162
- if (!functionType.functionType.priv.callSiteReturnTypeCache) {
16163
- functionType.functionType.priv.callSiteReturnTypeCache = [];
16163
+ if (!functionTypeResult.functionType.priv.callSiteReturnTypeCache) {
16164
+ functionTypeResult.functionType.priv.callSiteReturnTypeCache = [];
16164
16165
  }
16165
- if (functionType.functionType.priv.callSiteReturnTypeCache.length >= maxCallSiteReturnTypeCacheSize) {
16166
- functionType.functionType.priv.callSiteReturnTypeCache =
16167
- functionType.functionType.priv.callSiteReturnTypeCache.slice(1);
16166
+ if (functionTypeResult.functionType.priv.callSiteReturnTypeCache.length >=
16167
+ maxCallSiteReturnTypeCacheSize) {
16168
+ functionTypeResult.functionType.priv.callSiteReturnTypeCache =
16169
+ functionTypeResult.functionType.priv.callSiteReturnTypeCache.slice(1);
16168
16170
  }
16169
- functionType.functionType.priv.callSiteReturnTypeCache.push({
16171
+ functionTypeResult.functionType.priv.callSiteReturnTypeCache.push({
16170
16172
  paramTypes,
16171
16173
  returnType: contextualReturnType,
16172
16174
  });
@@ -16238,7 +16240,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16238
16240
  isIncomplete: !!typeResult.isIncomplete,
16239
16241
  };
16240
16242
  }
16241
- function assignClass(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount, reportErrorsUsingObjType) {
16243
+ function assignClass(destType, srcType, diag, destConstraints, srcConstraints, flags, recursionCount, reportErrorsUsingObjType) {
16242
16244
  // If the source or dest types are partially evaluated (i.e. they are in the
16243
16245
  // process of being constructed), assume they are assignable rather than risk
16244
16246
  // emitting false positives.
@@ -16249,7 +16251,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16249
16251
  // checking, as defined in PEP 589.
16250
16252
  if (types_1.ClassType.isTypedDictClass(srcType)) {
16251
16253
  if (types_1.ClassType.isTypedDictClass(destType) && !types_1.ClassType.isSameGenericClass(destType, srcType)) {
16252
- if (!(0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount)) {
16254
+ if (!(0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, destType, srcType, diag, destConstraints, flags, recursionCount)) {
16253
16255
  return false;
16254
16256
  }
16255
16257
  if (types_1.ClassType.isFinal(destType) !== types_1.ClassType.isFinal(srcType)) {
@@ -16263,7 +16265,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16263
16265
  if ((flags & 1 /* AssignTypeFlags.EnforceInvariance */) !== 0) {
16264
16266
  return (0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, srcType, destType,
16265
16267
  /* diag */ undefined,
16266
- /* typeVarContext */ undefined, flags, recursionCount);
16268
+ /* constraints */ undefined, flags, recursionCount);
16267
16269
  }
16268
16270
  return true;
16269
16271
  }
@@ -16311,7 +16313,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16311
16313
  // derive from the source. We also need to use this path if we're
16312
16314
  // testing to see if the metaclass matches the protocol.
16313
16315
  if (types_1.ClassType.isProtocolClass(destType) && !isDerivedFrom) {
16314
- if (!(0, protocols_1.assignClassToProtocol)(evaluatorInterface, destType, types_1.ClassType.cloneAsInstance(srcType), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16316
+ if (!(0, protocols_1.assignClassToProtocol)(evaluatorInterface, destType, types_1.ClassType.cloneAsInstance(srcType), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
16315
16317
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.protocolIncompatible().format({
16316
16318
  sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
16317
16319
  destType: printType((0, typeUtils_1.convertToInstance)(destType)),
@@ -16330,7 +16332,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16330
16332
  if ((flags & 1 /* AssignTypeFlags.EnforceInvariance */) === 0 || types_1.ClassType.isSameGenericClass(srcType, destType)) {
16331
16333
  if (isDerivedFrom) {
16332
16334
  (0, debug_1.assert)(inheritanceChain.length > 0);
16333
- if (assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16335
+ if (assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
16334
16336
  return true;
16335
16337
  }
16336
16338
  }
@@ -16373,7 +16375,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16373
16375
  function assignClassToSelf(destType, srcType, assumedVariance, ignoreBaseClassVariance = true, recursionCount = 0) {
16374
16376
  (0, debug_1.assert)(types_1.ClassType.isSameGenericClass(destType, srcType));
16375
16377
  (0, debug_1.assert)(destType.shared.typeParams.length > 0);
16376
- const typeVarContext = new typeVarContext_1.TypeVarContext();
16378
+ srcType = (0, typeUtils_1.makeTypeVarsBound)(srcType, (0, typeUtils_1.getTypeVarScopeIds)(srcType));
16379
+ destType = (0, typeUtils_1.makeTypeVarsBound)(destType, (0, typeUtils_1.getTypeVarScopeIds)(destType));
16377
16380
  let isAssignable = true;
16378
16381
  // Use a try/catch block here to make sure that we reset
16379
16382
  // the assignClassToSelfClass to undefined if an exception occurs.
@@ -16400,8 +16403,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16400
16403
  (0, types_1.isClassInstance)(srcMemberType) &&
16401
16404
  types_1.ClassType.isPropertyClass(srcMemberType)) {
16402
16405
  if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
16403
- /* diag */ undefined, typeVarContext,
16404
- /* selfTypeVarContext */ undefined, recursionCount)) {
16406
+ /* diag */ undefined,
16407
+ /* constraints */ undefined,
16408
+ /* selfConstraints */ undefined, recursionCount)) {
16405
16409
  isAssignable = false;
16406
16410
  }
16407
16411
  }
@@ -16410,6 +16414,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16410
16414
  let flags = 0 /* AssignTypeFlags.Default */;
16411
16415
  if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ &&
16412
16416
  !isFinalVariableDeclaration(primaryDecl) &&
16417
+ !types_1.ClassType.isReadOnlyInstanceVariables(destType) &&
16413
16418
  !types_1.ClassType.isDataClassFrozen(destType)) {
16414
16419
  // Class and instance variables that are mutable need to
16415
16420
  // enforce invariance. We will exempt variables that are
@@ -16420,8 +16425,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16420
16425
  }
16421
16426
  }
16422
16427
  if (!assignType(destMemberType, srcMemberType,
16423
- /* diag */ undefined, typeVarContext,
16424
- /* srcTypeVarContext */ undefined, flags | 32768 /* AssignTypeFlags.SkipSelfClsParamCheck */, recursionCount)) {
16428
+ /* diag */ undefined,
16429
+ /* destConstraints */ undefined,
16430
+ /* srcConstraints */ undefined, flags | 32768 /* AssignTypeFlags.SkipSelfClsParamCheck */, recursionCount)) {
16425
16431
  isAssignable = false;
16426
16432
  }
16427
16433
  }
@@ -16476,7 +16482,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16476
16482
  }
16477
16483
  // Determines whether the specified type can be assigned to the
16478
16484
  // specified inheritance chain, taking into account its type arguments.
16479
- function assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
16485
+ function assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag, destConstraints, srcConstraints, flags, recursionCount) {
16480
16486
  let curSrcType = srcType;
16481
16487
  let prevSrcType;
16482
16488
  inferVarianceForClass(destType);
@@ -16540,7 +16546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16540
16546
  }
16541
16547
  // Handle tuple, which supports a variable number of type arguments.
16542
16548
  if (destType.priv.tupleTypeArgs && curSrcType.priv.tupleTypeArgs) {
16543
- return (0, tuples_1.assignTupleTypeArgs)(evaluatorInterface, destType, curSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16549
+ return (0, tuples_1.assignTupleTypeArgs)(evaluatorInterface, destType, curSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
16544
16550
  }
16545
16551
  if (destType.priv.typeArgs) {
16546
16552
  // If the dest type is specialized, make sure the specialized source
@@ -16549,9 +16555,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16549
16555
  // Don't emit a diag addendum if we're in an invariant context. It's
16550
16556
  // sufficient to simply indicate that the types are not the same
16551
16557
  // in this case. Adding more information is unnecessary and confusing.
16552
- (flags & 1 /* AssignTypeFlags.EnforceInvariance */) === 0 ? diag : undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16558
+ (flags & 1 /* AssignTypeFlags.EnforceInvariance */) === 0 ? diag : undefined, destConstraints, srcConstraints, flags, recursionCount);
16553
16559
  }
16554
- if (destTypeVarContext && curSrcType.priv.typeArgs && !destTypeVarContext.isLocked()) {
16560
+ if (destConstraints && curSrcType.priv.typeArgs && !destConstraints.isLocked()) {
16555
16561
  // Populate the typeVar map with type arguments of the source.
16556
16562
  const srcTypeArgs = curSrcType.priv.typeArgs;
16557
16563
  for (let i = 0; i < destType.shared.typeParams.length; i++) {
@@ -16564,10 +16570,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16564
16570
  else {
16565
16571
  typeArgType = i < srcTypeArgs.length ? srcTypeArgs[i] : types_1.UnknownType.create();
16566
16572
  }
16567
- if ((0, types_1.isParamSpec)(typeParam)) {
16568
- typeArgType = (0, typeUtils_1.convertTypeToParamSpecValue)(typeArgType);
16569
- }
16570
- (0, constraintSolver_1.updateTypeVarType)(evaluatorInterface, destTypeVarContext, typeParam, variance !== 4 /* Variance.Contravariant */ ? typeArgType : undefined, variance !== 3 /* Variance.Covariant */ ? typeArgType : undefined,
16573
+ (0, constraintSolver_1.updateTypeVarType)(evaluatorInterface, destConstraints, typeParam, variance !== 4 /* Variance.Contravariant */ ? typeArgType : undefined, variance !== 3 /* Variance.Covariant */ ? typeArgType : undefined,
16571
16574
  /* forceRetainLiterals */ true);
16572
16575
  }
16573
16576
  }
@@ -16583,7 +16586,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16583
16586
  }
16584
16587
  return undefined;
16585
16588
  }
16586
- function assignTypeArgs(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
16589
+ function assignTypeArgs(destType, srcType, diag, destConstraints, srcConstraints, flags, recursionCount) {
16587
16590
  var _a, _b, _c;
16588
16591
  (0, debug_1.assert)(types_1.ClassType.isSameGenericClass(destType, srcType));
16589
16592
  inferVarianceForClass(destType);
@@ -16637,7 +16640,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16637
16640
  // why two types are not the same.
16638
16641
  includeDiagAddendum = false;
16639
16642
  }
16640
- if (!assignType(variance === 4 /* Variance.Contravariant */ ? srcTypeArg : destTypeArg, variance === 4 /* Variance.Contravariant */ ? destTypeArg : srcTypeArg, assignmentDiag, variance === 4 /* Variance.Contravariant */ ? srcTypeVarContext : destTypeVarContext, variance === 4 /* Variance.Contravariant */ ? destTypeVarContext : srcTypeVarContext, effectiveFlags, recursionCount)) {
16643
+ if (!assignType(variance === 4 /* Variance.Contravariant */ ? srcTypeArg : destTypeArg, variance === 4 /* Variance.Contravariant */ ? destTypeArg : srcTypeArg, assignmentDiag, variance === 4 /* Variance.Contravariant */ ? srcConstraints : destConstraints, variance === 4 /* Variance.Contravariant */ ? destConstraints : srcConstraints, effectiveFlags, recursionCount)) {
16641
16644
  // Don't report errors with type variables in "pseudo-random"
16642
16645
  // classes since these type variables are not real.
16643
16646
  if (!types_1.ClassType.isPseudoGenericClass(destType)) {
@@ -16675,11 +16678,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16675
16678
  return isCompatible;
16676
16679
  }
16677
16680
  // Determines if the source type can be assigned to the dest type.
16678
- // If typeVarContext is provided, type variables within the destType are
16681
+ // If constraint are provided, type variables within the destType are
16679
16682
  // matched against existing type variables in the map. If a type variable
16680
16683
  // in the dest type is not in the type map already, it is assigned a type
16681
16684
  // and added to the map.
16682
- function assignType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags = 0 /* AssignTypeFlags.Default */, recursionCount = 0) {
16685
+ function assignType(destType, srcType, diag, destConstraints, srcConstraints, flags = 0 /* AssignTypeFlags.Default */, recursionCount = 0) {
16683
16686
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
16684
16687
  // Handle the case where the dest and src types are the same object.
16685
16688
  // We can normally shortcut this and say that they are compatible,
@@ -16724,7 +16727,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16724
16727
  const srcTypeArgs = srcAliasInfo.typeArgs;
16725
16728
  destAliasInfo.typeArgs.forEach((destTypeArg, index) => {
16726
16729
  const srcTypeArg = index < srcTypeArgs.length ? srcTypeArgs[index] : types_1.UnknownType.create();
16727
- if (!assignType(destTypeArg, srcTypeArg, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16730
+ if (!assignType(destTypeArg, srcTypeArg, diag, destConstraints, srcConstraints, flags, recursionCount)) {
16728
16731
  isAssignable = false;
16729
16732
  }
16730
16733
  });
@@ -16769,12 +16772,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16769
16772
  // TypeVar that we are attempting to match.
16770
16773
  if ((0, types_1.isTypeVar)(destType)) {
16771
16774
  if ((0, typeUtils_1.isTypeVarSame)(destType, srcType)) {
16772
- if (destType.priv.scopeId && (destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.hasSolveForScope(destType.priv.scopeId))) {
16773
- // If the dest TypeVar has no current value bound to it, bind itself.
16774
- if (!destTypeVarContext.getMainSolutionSet().getTypeVar(destType)) {
16775
- return (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount);
16776
- }
16777
- }
16778
16775
  return true;
16779
16776
  }
16780
16777
  // If the dest is a constrained or bound type variable and all of the
@@ -16789,7 +16786,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16789
16786
  if (types_1.TypeBase.isInstantiable(destType) === types_1.TypeBase.isInstantiable(srcType) &&
16790
16787
  ((_d = srcType.props) === null || _d === void 0 ? void 0 : _d.condition) &&
16791
16788
  srcType.props.condition.some((cond) => {
16792
- return (cond.typeVar.shared.constraints.length === 0 &&
16789
+ return (!types_1.TypeVarType.hasConstraints(cond.typeVar) &&
16793
16790
  cond.typeVar.priv.nameWithScope === destTypeVar.priv.nameWithScope);
16794
16791
  })) {
16795
16792
  return true;
@@ -16803,19 +16800,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16803
16800
  // Handle the special case where both types are Self types. We'll allow
16804
16801
  // them to be treated as equivalent to handle certain common idioms.
16805
16802
  if ((0, types_1.isTypeVar)(srcType) &&
16806
- srcType.shared.isSynthesizedSelf &&
16807
- srcType.shared.boundType &&
16808
- destType.shared.isSynthesizedSelf &&
16809
- destType.shared.boundType &&
16810
- types_1.TypeVarType.hasInternalScopeId(destType) === types_1.TypeVarType.hasInternalScopeId(srcType) &&
16803
+ types_1.TypeVarType.isSelf(srcType) &&
16804
+ types_1.TypeVarType.hasBound(srcType) &&
16805
+ types_1.TypeVarType.isSelf(destType) &&
16806
+ types_1.TypeVarType.hasBound(destType) &&
16807
+ types_1.TypeVarType.isBound(destType) === types_1.TypeVarType.isBound(srcType) &&
16811
16808
  types_1.TypeBase.isInstance(srcType) === types_1.TypeBase.isInstance(destType)) {
16812
- if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 && destTypeVarContext) {
16813
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount);
16809
+ if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 && destConstraints) {
16810
+ (0, constraintSolver_1.assignTypeVar)(evaluatorInterface, destType, srcType, diag, destConstraints, flags, recursionCount);
16814
16811
  }
16815
16812
  return true;
16816
16813
  }
16817
- // If the dest is a variadic type variable, and the source is a tuple
16818
- // with a single entry that is the same variadic type variable, it's a match.
16814
+ // If the dest is a TypeVarTuple, and the source is a tuple
16815
+ // with a single entry that is the same TypeVarTuple, it's a match.
16819
16816
  if ((0, types_1.isTypeVarTuple)(destType) &&
16820
16817
  (0, types_1.isClassInstance)(srcType) &&
16821
16818
  (0, typeUtils_1.isTupleClass)(srcType) &&
@@ -16826,8 +16823,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16826
16823
  }
16827
16824
  }
16828
16825
  if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 || !(0, types_1.isTypeVar)(srcType)) {
16829
- const targetTypeVarContext = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
16830
- if (!(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, targetTypeVarContext !== null && targetTypeVarContext !== void 0 ? targetTypeVarContext : new typeVarContext_1.TypeVarContext(), flags, recursionCount)) {
16826
+ const targetConstraints = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destConstraints : srcConstraints;
16827
+ if (!(0, constraintSolver_1.assignTypeVar)(evaluatorInterface, destType, srcType, diag, targetConstraints, flags, recursionCount)) {
16831
16828
  return false;
16832
16829
  }
16833
16830
  if ((0, types_1.isAnyOrUnknown)(srcType) && (flags & 16 /* AssignTypeFlags.OverloadOverlap */) !== 0) {
@@ -16839,30 +16836,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16839
16836
  if ((0, types_1.isTypeVar)(srcType)) {
16840
16837
  if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0) {
16841
16838
  // The caller has requested that we solve for source type variables
16842
- // rather than dest. If the type variable is not in the scope of the
16843
- // provided TypeVarContext, simply verify that the concrete types are
16844
- // compatible.
16845
- if ((flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */) === 0 &&
16846
- (!srcTypeVarContext || !srcTypeVarContext.hasSolveForScope((0, typeUtils_1.getTypeVarScopeId)(srcType)))) {
16839
+ // rather than dest.
16840
+ if (types_1.TypeVarType.isBound(srcType)) {
16847
16841
  return assignType(makeTopLevelTypeVarsConcrete(destType), makeTopLevelTypeVarsConcrete(srcType), diag,
16848
- /* destTypeVarContext */ undefined,
16849
- /* srcTypeVarContext */ undefined, flags, recursionCount);
16842
+ /* destConstraints */ undefined,
16843
+ /* srcConstraints */ undefined, flags, recursionCount);
16850
16844
  }
16851
- else {
16852
- if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destType, diag, srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext(), flags, recursionCount)) {
16853
- return true;
16854
- }
16855
- // If the dest type is a union, only one of the subtypes needs to match.
16856
- let isAssignable = false;
16857
- if ((0, types_1.isUnion)(destType)) {
16858
- (0, typeUtils_1.doForEachSubtype)(destType, (destSubtype) => {
16859
- if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destSubtype, diag, srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext(), flags, recursionCount)) {
16860
- isAssignable = true;
16861
- }
16862
- });
16863
- }
16864
- return isAssignable;
16845
+ if ((0, constraintSolver_1.assignTypeVar)(evaluatorInterface, srcType, destType, diag, srcConstraints, flags, recursionCount)) {
16846
+ return true;
16865
16847
  }
16848
+ // If the dest type is a union, only one of the subtypes needs to match.
16849
+ let isAssignable = false;
16850
+ if ((0, types_1.isUnion)(destType)) {
16851
+ (0, typeUtils_1.doForEachSubtype)(destType, (destSubtype) => {
16852
+ if ((0, constraintSolver_1.assignTypeVar)(evaluatorInterface, srcType, destSubtype, diag, srcConstraints, flags, recursionCount)) {
16853
+ isAssignable = true;
16854
+ }
16855
+ });
16856
+ }
16857
+ return isAssignable;
16866
16858
  }
16867
16859
  if ((flags & 1 /* AssignTypeFlags.EnforceInvariance */) !== 0) {
16868
16860
  if ((0, types_1.isAnyOrUnknown)(destType)) {
@@ -16898,13 +16890,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16898
16890
  return true;
16899
16891
  }
16900
16892
  if ((0, types_1.isAnyOrUnknown)(srcType) && !((_e = srcType.props) === null || _e === void 0 ? void 0 : _e.specialForm)) {
16901
- const targetTypeVarContext = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
16902
- if (targetTypeVarContext) {
16893
+ const targetConstraints = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destConstraints : srcConstraints;
16894
+ if (targetConstraints) {
16903
16895
  // If it's an ellipsis type, convert it to a regular "Any"
16904
16896
  // type. These are functionally equivalent, but "Any" looks
16905
16897
  // better in the text representation.
16906
16898
  const typeVarSubstitution = (0, typeUtils_1.isEllipsisType)(srcType) ? types_1.AnyType.create() : srcType;
16907
- (0, typeUtils_1.setTypeArgsRecursive)(destType, typeVarSubstitution, targetTypeVarContext, recursionCount);
16899
+ (0, typeUtils_1.setTypeArgsRecursive)(destType, typeVarSubstitution, targetConstraints, recursionCount);
16908
16900
  }
16909
16901
  if ((flags & 16 /* AssignTypeFlags.OverloadOverlap */) === 0) {
16910
16902
  return true;
@@ -16918,9 +16910,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16918
16910
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16919
16911
  return false;
16920
16912
  }
16921
- const targetTypeVarContext = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
16922
- if (targetTypeVarContext) {
16923
- (0, typeUtils_1.setTypeArgsRecursive)(destType, types_1.UnknownType.create(), targetTypeVarContext, recursionCount);
16913
+ const targetConstraints = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destConstraints : srcConstraints;
16914
+ if (targetConstraints) {
16915
+ (0, typeUtils_1.setTypeArgsRecursive)(destType, types_1.UnknownType.create(), targetConstraints, recursionCount);
16924
16916
  }
16925
16917
  return true;
16926
16918
  }
@@ -16929,27 +16921,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16929
16921
  // special-case logic to handle this case.
16930
16922
  if ((0, types_1.isUnion)(srcType)) {
16931
16923
  return assignFromUnionType(destType, srcType,
16932
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16924
+ /* diag */ undefined, destConstraints, srcConstraints, flags, recursionCount);
16933
16925
  }
16934
- const clonedDestTypeVarContext = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone();
16935
- const clonedSrcTypeVarContext = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone();
16926
+ const clonedDestConstraints = destConstraints === null || destConstraints === void 0 ? void 0 : destConstraints.clone();
16927
+ const clonedSrcConstraints = srcConstraints === null || srcConstraints === void 0 ? void 0 : srcConstraints.clone();
16936
16928
  if (assignToUnionType(destType, srcType,
16937
- /* diag */ undefined, clonedDestTypeVarContext, clonedSrcTypeVarContext, flags, recursionCount)) {
16938
- if (destTypeVarContext && clonedDestTypeVarContext) {
16939
- destTypeVarContext.copyFromClone(clonedDestTypeVarContext);
16929
+ /* diag */ undefined, clonedDestConstraints, clonedSrcConstraints, flags, recursionCount)) {
16930
+ if (destConstraints && clonedDestConstraints) {
16931
+ destConstraints.copyFromClone(clonedDestConstraints);
16940
16932
  }
16941
- if (srcTypeVarContext && clonedSrcTypeVarContext) {
16942
- srcTypeVarContext.copyFromClone(clonedSrcTypeVarContext);
16933
+ if (srcConstraints && clonedSrcConstraints) {
16934
+ srcConstraints.copyFromClone(clonedSrcConstraints);
16943
16935
  }
16944
16936
  return true;
16945
16937
  }
16946
16938
  }
16947
16939
  const expandedSrcType = makeTopLevelTypeVarsConcrete(srcType);
16948
16940
  if ((0, types_1.isUnion)(expandedSrcType)) {
16949
- return assignFromUnionType(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16941
+ return assignFromUnionType(destType, expandedSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
16950
16942
  }
16951
16943
  if ((0, types_1.isUnion)(destType)) {
16952
- return assignToUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16944
+ return assignToUnionType(destType, srcType, diag, destConstraints, srcConstraints, flags, recursionCount);
16953
16945
  }
16954
16946
  // Is the src a specialized "type" object?
16955
16947
  if ((0, types_1.isClassInstance)(expandedSrcType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
@@ -16967,7 +16959,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16967
16959
  }
16968
16960
  }
16969
16961
  else if ((0, types_1.isClassInstance)(typeTypeArg) || (0, types_1.isTypeVar)(typeTypeArg)) {
16970
- if (assignType(destType, (0, typeUtils_1.convertToInstantiable)(typeTypeArg), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16962
+ if (assignType(destType, (0, typeUtils_1.convertToInstantiable)(typeTypeArg), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
16971
16963
  return true;
16972
16964
  }
16973
16965
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
@@ -16994,10 +16986,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16994
16986
  }
16995
16987
  if (isSpecialFormClass(expandedSrcType, flags)) {
16996
16988
  if ((_h = destType.props) === null || _h === void 0 ? void 0 : _h.specialForm) {
16997
- return assignType(destType.props.specialForm, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
16989
+ return assignType(destType.props.specialForm, expandedSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
16998
16990
  }
16999
16991
  }
17000
- else if (assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
16992
+ else if (assignClass(destType, expandedSrcType, diag, destConstraints, srcConstraints, flags, recursionCount,
17001
16993
  /* reportErrorsUsingObjType */ false)) {
17002
16994
  return true;
17003
16995
  }
@@ -17009,7 +17001,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17009
17001
  // the metaclass of the instantiable dest type.
17010
17002
  const destMetaclass = destType.shared.effectiveMetaclass;
17011
17003
  if (destMetaclass && (0, types_1.isInstantiableClass)(destMetaclass)) {
17012
- if (assignClass(types_1.ClassType.cloneAsInstance(destMetaclass), expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17004
+ if (assignClass(types_1.ClassType.cloneAsInstance(destMetaclass), expandedSrcType, diag, destConstraints, srcConstraints, flags, recursionCount,
17013
17005
  /* reportErrorsUsingObjType */ false)) {
17014
17006
  return true;
17015
17007
  }
@@ -17029,7 +17021,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17029
17021
  const destTypeArgs = destType.priv.typeArgs;
17030
17022
  if (destTypeArgs && destTypeArgs.length >= 1) {
17031
17023
  if (types_1.TypeBase.isInstance(destTypeArgs[0]) && types_1.TypeBase.isInstantiable(srcType)) {
17032
- return assignType(destTypeArgs[0], (0, typeUtils_1.convertToInstance)(srcType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17024
+ return assignType(destTypeArgs[0], (0, typeUtils_1.convertToInstance)(srcType), diag, destConstraints, srcConstraints, flags, recursionCount);
17033
17025
  }
17034
17026
  }
17035
17027
  // Is the dest a "type" object? Assume that all instantiable
@@ -17041,6 +17033,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17041
17033
  }
17042
17034
  let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
17043
17035
  if ((0, types_1.isClass)(concreteSrcType) && types_1.TypeBase.isInstance(concreteSrcType)) {
17036
+ // Handle enum literals that are assignable to another (non-Enum) literal.
17037
+ // This can happen for IntEnum and StrEnum members.
17038
+ if (types_1.ClassType.isEnumClass(concreteSrcType) &&
17039
+ concreteSrcType.priv.literalValue instanceof types_1.EnumLiteral &&
17040
+ concreteSrcType.shared.mro.some((base) => (0, types_1.isClass)(base) && types_1.ClassType.isBuiltIn(base, ['int', 'str', 'bytes'])) &&
17041
+ (0, types_1.isClassInstance)(concreteSrcType.priv.literalValue.itemType) &&
17042
+ (0, typeUtils_1.isLiteralType)(concreteSrcType.priv.literalValue.itemType) &&
17043
+ assignType(destType, concreteSrcType.priv.literalValue.itemType)) {
17044
+ return true;
17045
+ }
17044
17046
  if (destType.priv.literalValue !== undefined) {
17045
17047
  const srcLiteral = concreteSrcType.priv.literalValue;
17046
17048
  if (srcLiteral === undefined || !types_1.ClassType.isLiteralValueSame(concreteSrcType, destType)) {
@@ -17067,7 +17069,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17067
17069
  (flags & 1 /* AssignTypeFlags.EnforceInvariance */) === 0) {
17068
17070
  concreteSrcType = types_1.ClassType.cloneAsInstance(strClass);
17069
17071
  }
17070
- if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17072
+ if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, destConstraints, srcConstraints, flags, recursionCount,
17071
17073
  /* reportErrorsUsingObjType */ true)) {
17072
17074
  return false;
17073
17075
  }
@@ -17077,14 +17079,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17077
17079
  // Is the destination a callback protocol (defined in PEP 544)?
17078
17080
  const destCallbackType = getCallbackProtocolType(destType, recursionCount);
17079
17081
  if (destCallbackType) {
17080
- if (destTypeVarContext) {
17081
- destTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(destCallbackType));
17082
- }
17083
- return assignType(destCallbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17082
+ return assignType(destCallbackType, concreteSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
17084
17083
  }
17085
17084
  // All functions are considered instances of "builtins.function".
17086
17085
  if (functionClass) {
17087
- return assignType(destType, (0, typeUtils_1.convertToInstance)(functionClass), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17086
+ return assignType(destType, (0, typeUtils_1.convertToInstance)(functionClass), diag, destConstraints, srcConstraints, flags, recursionCount);
17088
17087
  }
17089
17088
  }
17090
17089
  else if ((0, types_1.isModule)(concreteSrcType)) {
@@ -17093,7 +17092,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17093
17092
  return true;
17094
17093
  }
17095
17094
  if (types_1.ClassType.isProtocolClass(destType)) {
17096
- return (0, protocols_1.assignModuleToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), concreteSrcType, diag, destTypeVarContext, flags, recursionCount);
17095
+ return (0, protocols_1.assignModuleToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), concreteSrcType, diag, destConstraints, flags, recursionCount);
17097
17096
  }
17098
17097
  }
17099
17098
  else if ((0, types_1.isInstantiableClass)(concreteSrcType)) {
@@ -17101,12 +17100,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17101
17100
  // class that is effectively a function.
17102
17101
  const callbackType = getCallbackProtocolType(destType, recursionCount);
17103
17102
  if (callbackType) {
17104
- return assignType(callbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17103
+ return assignType(callbackType, concreteSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
17105
17104
  }
17106
17105
  // If the destType is an instantiation of a Protocol,
17107
17106
  // see if the class type itself satisfies the protocol.
17108
17107
  if (types_1.ClassType.isProtocolClass(destType)) {
17109
- return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17108
+ return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), concreteSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
17110
17109
  }
17111
17110
  // Determine if the metaclass can be assigned to the object.
17112
17111
  const metaclass = concreteSrcType.shared.effectiveMetaclass;
@@ -17115,7 +17114,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17115
17114
  return true;
17116
17115
  }
17117
17116
  else {
17118
- return assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17117
+ return assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass, diag, destConstraints, srcConstraints, flags, recursionCount,
17119
17118
  /* reportErrorsUsingObjType */ false);
17120
17119
  }
17121
17120
  }
@@ -17124,7 +17123,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17124
17123
  return (flags & 16 /* AssignTypeFlags.OverloadOverlap */) === 0;
17125
17124
  }
17126
17125
  else if ((0, types_1.isUnion)(concreteSrcType)) {
17127
- return assignType(destType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17126
+ return assignType(destType, concreteSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
17128
17127
  }
17129
17128
  }
17130
17129
  if ((0, types_1.isFunction)(destType)) {
@@ -17145,7 +17144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17145
17144
  // The constructor conversion may result in a union of the
17146
17145
  // __init__ and __new__ callables.
17147
17146
  if ((0, types_1.isUnion)(concreteSrcType)) {
17148
- return assignType(destType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17147
+ return assignType(destType, concreteSrcType, diag, destConstraints, srcConstraints, flags, recursionCount);
17149
17148
  }
17150
17149
  }
17151
17150
  }
@@ -17153,6 +17152,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17153
17152
  return (flags & 16 /* AssignTypeFlags.OverloadOverlap */) === 0;
17154
17153
  }
17155
17154
  if ((0, types_1.isOverloadedFunction)(concreteSrcType)) {
17155
+ // If this is the first pass of an argument assignment, skip
17156
+ // all attempts to assign an overloaded function to a function
17157
+ // because we probably don't have enough information to properly
17158
+ // filter the overloads at this time. We will do this work on
17159
+ // subsequent passes.
17160
+ if ((flags & 8 /* AssignTypeFlags.ArgAssignmentFirstPass */) !== 0) {
17161
+ return true;
17162
+ }
17156
17163
  // Find all of the overloaded functions that match the parameters.
17157
17164
  const overloads = types_1.OverloadedFunctionType.getOverloads(concreteSrcType);
17158
17165
  const filteredOverloads = [];
@@ -17161,16 +17168,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17161
17168
  overloads.forEach((overload) => {
17162
17169
  var _a;
17163
17170
  const overloadScopeId = (_a = (0, typeUtils_1.getTypeVarScopeId)(overload)) !== null && _a !== void 0 ? _a : '';
17164
- const destTypeVarContextClone = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.cloneWithSignature(overloadScopeId);
17165
- const srcTypeVarContextClone = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.cloneWithSignature(overloadScopeId);
17171
+ const destConstraintsClone = destConstraints === null || destConstraints === void 0 ? void 0 : destConstraints.cloneWithSignature(overloadScopeId);
17172
+ const srcConstraintsClone = srcConstraints === null || srcConstraints === void 0 ? void 0 : srcConstraints.cloneWithSignature(overloadScopeId);
17166
17173
  if (assignType(destType, overload,
17167
- /* diag */ undefined, destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
17174
+ /* diag */ undefined, destConstraintsClone, srcConstraintsClone, flags, recursionCount)) {
17168
17175
  filteredOverloads.push(overload);
17169
- if (destTypeVarContextClone) {
17170
- (0, collectionUtils_1.appendArray)(destTypeVarSignatures, destTypeVarContextClone.getSolutionSets());
17176
+ if (destConstraintsClone) {
17177
+ (0, collectionUtils_1.appendArray)(destTypeVarSignatures, destConstraintsClone.getConstraintSets());
17171
17178
  }
17172
- if (srcTypeVarContextClone) {
17173
- (0, collectionUtils_1.appendArray)(srcTypeVarSignatures, srcTypeVarContextClone.getSolutionSets());
17179
+ if (srcConstraintsClone) {
17180
+ (0, collectionUtils_1.appendArray)(srcTypeVarSignatures, srcConstraintsClone.getConstraintSets());
17174
17181
  }
17175
17182
  }
17176
17183
  });
@@ -17178,16 +17185,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17178
17185
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.noOverloadAssignable().format({ type: printType(destType) }));
17179
17186
  return false;
17180
17187
  }
17181
- if (destTypeVarContext) {
17182
- destTypeVarContext.addSolutionSets(destTypeVarSignatures);
17183
- }
17184
- if (srcTypeVarContext) {
17185
- srcTypeVarContext.addSolutionSets(srcTypeVarSignatures);
17188
+ if (filteredOverloads.length === 1 || (flags & 8 /* AssignTypeFlags.ArgAssignmentFirstPass */) === 0) {
17189
+ if (destConstraints) {
17190
+ destConstraints.addConstraintSets(destTypeVarSignatures);
17191
+ }
17192
+ if (srcConstraints) {
17193
+ srcConstraints.addConstraintSets(srcTypeVarSignatures);
17194
+ }
17186
17195
  }
17187
17196
  return true;
17188
17197
  }
17189
17198
  if ((0, types_1.isFunction)(concreteSrcType)) {
17190
- if (assignFunction(destType, concreteSrcType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(destType)), srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(concreteSrcType)), flags, recursionCount)) {
17199
+ if (assignFunction(destType, concreteSrcType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints !== null && destConstraints !== void 0 ? destConstraints : new constraintTracker_1.ConstraintTracker(), srcConstraints !== null && srcConstraints !== void 0 ? srcConstraints : new constraintTracker_1.ConstraintTracker(), flags, recursionCount)) {
17191
17200
  return true;
17192
17201
  }
17193
17202
  }
@@ -17205,17 +17214,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17205
17214
  if (destOverloads.every((destOverload, index) => {
17206
17215
  const srcOverload = srcOverloads[index];
17207
17216
  return assignType(destOverload, srcOverload,
17208
- /* diag */ undefined, destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(destOverload)), srcTypeVarContext, flags, recursionCount);
17217
+ /* diag */ undefined, destConstraints, srcConstraints, flags, recursionCount);
17209
17218
  })) {
17210
17219
  return true;
17211
17220
  }
17212
17221
  }
17213
17222
  }
17214
17223
  const isAssignable = destOverloads.every((destOverload) => {
17215
- if (destTypeVarContext) {
17216
- destTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(destOverload));
17217
- }
17218
- const result = assignType(destOverload, srcType, overloadDiag === null || overloadDiag === void 0 ? void 0 : overloadDiag.createAddendum(), destTypeVarContext !== null && destTypeVarContext !== void 0 ? destTypeVarContext : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(destOverload)), srcTypeVarContext, flags, recursionCount);
17224
+ const result = assignType(destOverload, srcType, overloadDiag === null || overloadDiag === void 0 ? void 0 : overloadDiag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount);
17219
17225
  return result;
17220
17226
  });
17221
17227
  if (!isAssignable) {
@@ -17239,7 +17245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17239
17245
  // Are we trying to assign None to a protocol?
17240
17246
  if ((0, typeUtils_1.isNoneInstance)(srcType) && (0, types_1.isClassInstance)(destType) && types_1.ClassType.isProtocolClass(destType)) {
17241
17247
  if (noneTypeClass && (0, types_1.isInstantiableClass)(noneTypeClass)) {
17242
- return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(noneTypeClass), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17248
+ return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(noneTypeClass), diag, destConstraints, srcConstraints, flags, recursionCount);
17243
17249
  }
17244
17250
  }
17245
17251
  if ((0, typeUtils_1.isNoneInstance)(destType)) {
@@ -17249,7 +17255,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17249
17255
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
17250
17256
  return false;
17251
17257
  }
17252
- function assignFromUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17258
+ function assignFromUnionType(destType, srcType, diag, destConstraints, srcConstraints, flags, recursionCount) {
17253
17259
  // Start by checking for an exact match. This is needed to handle unions
17254
17260
  // that contain recursive type aliases.
17255
17261
  if ((0, types_1.isTypeSame)(srcType, destType, {}, recursionCount)) {
@@ -17267,7 +17273,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17267
17273
  const nonAnySubtypes = destType.priv.subtypes.filter((t) => !(0, types_1.isAnyOrUnknown)(t));
17268
17274
  if (nonAnySubtypes.length === 1 && (0, types_1.isTypeVar)(nonAnySubtypes[0])) {
17269
17275
  assignType(nonAnySubtypes[0], srcType,
17270
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17276
+ /* diag */ undefined, destConstraints, srcConstraints, flags, recursionCount);
17271
17277
  // This always succeeds because the destination contains Any.
17272
17278
  return true;
17273
17279
  }
@@ -17308,8 +17314,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17308
17314
  if (types_1.ClassType.isTypedDictClass(srcSubtype) && types_1.ClassType.isTypedDictClass(destSubtype)) {
17309
17315
  if (assignType(srcSubtype, destSubtype,
17310
17316
  /* diag */ undefined,
17311
- /* destTypeVarContext */ undefined,
17312
- /* srcTypeVarContext */ undefined, flags, recursionCount)) {
17317
+ /* destConstraints */ undefined,
17318
+ /* srcConstraints */ undefined, flags, recursionCount)) {
17313
17319
  return true;
17314
17320
  }
17315
17321
  }
@@ -17323,7 +17329,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17323
17329
  });
17324
17330
  if (destTypeIndex >= 0) {
17325
17331
  if (assignType(remainingDestSubtypes[destTypeIndex], srcSubtype,
17326
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17332
+ /* diag */ undefined, destConstraints, srcConstraints, flags, recursionCount)) {
17327
17333
  // Note that we have matched at least one subtype indicating
17328
17334
  // there is at least some overlap.
17329
17335
  matchedSomeSubtypes = true;
@@ -17360,7 +17366,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17360
17366
  for (let srcIndex = 0; srcIndex < remainingSrcSubtypes.length; srcIndex++) {
17361
17367
  let foundMatchForSrc = false;
17362
17368
  for (let destIndex = 0; destIndex < reorderedDestSubtypes.length; destIndex++) {
17363
- if (assignType(reorderedDestSubtypes[destIndex], remainingSrcSubtypes[srcIndex], diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17369
+ if (assignType(reorderedDestSubtypes[destIndex], remainingSrcSubtypes[srcIndex], diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17364
17370
  foundMatchForSrc = true;
17365
17371
  // Move the matched dest TypeVar to the end of the list so the other
17366
17372
  // dest TypeVars have a better chance of being assigned to.
@@ -17383,7 +17389,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17383
17389
  // dest TypeVars.
17384
17390
  remainingDestSubtypes.forEach((destSubtype) => {
17385
17391
  assignType(destSubtype, srcType,
17386
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17392
+ /* diag */ undefined, destConstraints, srcConstraints, flags, recursionCount);
17387
17393
  });
17388
17394
  }
17389
17395
  // If we've assigned all of the source subtypes but one or more dest
@@ -17392,7 +17398,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17392
17398
  else {
17393
17399
  // Try to assign a union of the remaining source types to
17394
17400
  // the first destination TypeVar.
17395
- if (!assignType(isReversed ? (0, types_1.combineTypes)(remainingDestSubtypes) : remainingDestSubtypes[0], isReversed ? remainingSrcSubtypes[0] : (0, types_1.combineTypes)(remainingSrcSubtypes), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17401
+ if (!assignType(isReversed ? (0, types_1.combineTypes)(remainingDestSubtypes) : remainingDestSubtypes[0], isReversed ? remainingSrcSubtypes[0] : (0, types_1.combineTypes)(remainingSrcSubtypes), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17396
17402
  canUseFastPath = false;
17397
17403
  }
17398
17404
  }
@@ -17412,14 +17418,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17412
17418
  return;
17413
17419
  }
17414
17420
  if (!assignType(destType, subtype,
17415
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17421
+ /* diag */ undefined, destConstraints, srcConstraints, flags, recursionCount)) {
17416
17422
  // Determine if the current subtype is subsumed by another subtype
17417
17423
  // in the same union. If so, we can ignore this.
17418
17424
  const isSubtypeSubsumed = isTypeSubsumedByOtherType(subtype, srcType,
17419
17425
  /* allowAnyToSubsume */ false, recursionCount);
17420
17426
  // Try again with a concrete version of the subtype.
17421
17427
  if (!isSubtypeSubsumed &&
17422
- !assignType(destType, subtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17428
+ !assignType(destType, subtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17423
17429
  isIncompatible = true;
17424
17430
  }
17425
17431
  }
@@ -17486,14 +17492,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17486
17492
  }
17487
17493
  return (assignType(destType, srcType,
17488
17494
  /* diag */ undefined,
17489
- /* destTypeVarContext */ undefined,
17490
- /* srcTypeVarContext */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount) &&
17495
+ /* destConstraints */ undefined,
17496
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount) &&
17491
17497
  !assignType(srcType, destType,
17492
17498
  /* diag */ undefined,
17493
- /* destTypeVarContext */ undefined,
17494
- /* srcTypeVarContext */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount));
17499
+ /* destConstraints */ undefined,
17500
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount));
17495
17501
  }
17496
- function assignToUnionType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17502
+ function assignToUnionType(destType, srcType, diag, destConstraints, srcConstraints, flags, recursionCount) {
17497
17503
  // If we need to enforce invariance, the source needs to be compatible
17498
17504
  // with all subtypes in the dest, unless those subtypes are subclasses
17499
17505
  // of other subtypes.
@@ -17501,18 +17507,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17501
17507
  let isIncompatible = false;
17502
17508
  (0, typeUtils_1.doForEachSubtype)(destType, (subtype, index) => {
17503
17509
  if (!isIncompatible &&
17504
- !assignType(subtype, srcType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17505
- // Determine whether this subtype is assignable to
17506
- // another subtype elsewhere in the union. If so, we can ignore
17507
- // the incompatibility.
17510
+ !assignType(subtype, srcType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17511
+ // Determine whether this subtype is subsumed by some other
17512
+ // subtype in the union. If so, we can ignore the incompatibility.
17508
17513
  let skipSubtype = false;
17509
17514
  if (!(0, types_1.isAnyOrUnknown)(subtype)) {
17515
+ const adjSubtype = (0, typeUtils_1.makeTypeVarsBound)(subtype, /* scopeIds */ undefined);
17510
17516
  (0, typeUtils_1.doForEachSubtype)(destType, (otherSubtype, otherIndex) => {
17511
17517
  if (index !== otherIndex && !skipSubtype) {
17512
- if (assignType(otherSubtype, subtype,
17518
+ const adjOtherSubtype = (0, typeUtils_1.makeTypeVarsBound)(otherSubtype, /* scopeIds */ undefined);
17519
+ if (assignType(adjOtherSubtype, adjSubtype,
17513
17520
  /* diag */ undefined,
17514
- /* destTypeVarContext */ undefined,
17515
- /* srcTypeVarContext */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount)) {
17521
+ /* destConstraints */ undefined,
17522
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount)) {
17516
17523
  skipSubtype = true;
17517
17524
  }
17518
17525
  }
@@ -17536,7 +17543,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17536
17543
  // If so, we need to use a slower path.
17537
17544
  if (!(0, typeUtils_1.requiresSpecialization)(destType)) {
17538
17545
  for (const subtype of destType.priv.subtypes) {
17539
- if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17546
+ if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17540
17547
  foundMatch = true;
17541
17548
  break;
17542
17549
  }
@@ -17551,9 +17558,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17551
17558
  foundMatch = true;
17552
17559
  }
17553
17560
  else {
17554
- let bestDestTypeVarContext;
17555
- let bestSrcTypeVarContext;
17556
- let bestTypeVarContextScore;
17561
+ let bestDestConstraints;
17562
+ let bestSrcConstraints;
17563
+ let bestConstraintsScore;
17564
+ let nakedTypeVarMatches = 0;
17557
17565
  // If the srcType is a literal, try to use the fast-path lookup
17558
17566
  // in case the destType is a union with hundreds of literals.
17559
17567
  if ((0, types_1.isClassInstance)(srcType) &&
@@ -17562,44 +17570,61 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17562
17570
  return true;
17563
17571
  }
17564
17572
  (0, typeUtils_1.doForEachSubtype)(destType, (subtype) => {
17565
- // Make a temporary clone of the typeVarContext. We don't want to modify
17566
- // the original typeVarContext until we find the "optimal" typeVar mapping.
17567
- const destTypeVarContextClone = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone();
17568
- const srcTypeVarContextClone = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone();
17569
- if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
17573
+ // Make a temporary clone of the constraints. We don't want to modify
17574
+ // the original constraints until we find the "optimal" typeVar mapping.
17575
+ const destConstraintsClone = destConstraints === null || destConstraints === void 0 ? void 0 : destConstraints.clone();
17576
+ const srcConstraintsClone = srcConstraints === null || srcConstraints === void 0 ? void 0 : srcConstraints.clone();
17577
+ if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destConstraintsClone, srcConstraintsClone, flags, recursionCount)) {
17570
17578
  foundMatch = true;
17571
- if (destTypeVarContextClone) {
17572
- // Ask the typeVarContext to compute a "score" for the current
17579
+ if (destConstraintsClone) {
17580
+ // Ask the constraints to compute a "score" for the current
17573
17581
  // contents of the table.
17574
- let typeVarContextScore = destTypeVarContextClone.getScore();
17582
+ let constraintsScore = destConstraintsClone.getScore();
17583
+ if ((0, types_1.isTypeVar)(subtype)) {
17584
+ if (!(destConstraints === null || destConstraints === void 0 ? void 0 : destConstraints.getMainConstraintSet().getTypeVar(subtype))) {
17585
+ nakedTypeVarMatches++;
17586
+ // Handicap the solution slightly so another type var with
17587
+ // existing constraints will be preferred.
17588
+ constraintsScore += 0.001;
17589
+ }
17590
+ }
17575
17591
  // If the type matches exactly, prefer it over other types.
17576
17592
  if ((0, types_1.isTypeSame)(subtype, stripLiteralValue(srcType))) {
17577
- typeVarContextScore = Number.POSITIVE_INFINITY;
17593
+ constraintsScore = Number.POSITIVE_INFINITY;
17578
17594
  }
17579
- if (bestTypeVarContextScore === undefined ||
17580
- bestTypeVarContextScore <= typeVarContextScore) {
17595
+ if (bestConstraintsScore === undefined || bestConstraintsScore <= constraintsScore) {
17581
17596
  // We found a typeVar mapping with a higher score than before.
17582
- bestTypeVarContextScore = typeVarContextScore;
17583
- bestDestTypeVarContext = destTypeVarContextClone;
17584
- bestSrcTypeVarContext = srcTypeVarContextClone;
17597
+ bestConstraintsScore = constraintsScore;
17598
+ bestDestConstraints = destConstraintsClone;
17599
+ bestSrcConstraints = srcConstraintsClone;
17585
17600
  }
17586
17601
  }
17587
17602
  }
17588
- });
17589
- // If we found a winning type var mapping, copy it back to typeVarContext.
17590
- if (destTypeVarContext && bestDestTypeVarContext) {
17591
- destTypeVarContext.copyFromClone(bestDestTypeVarContext);
17603
+ },
17604
+ /* sortSubtypes */ true);
17605
+ // If we saw more than one "naked" type vars that have no
17606
+ // previous constraints recorded, it's dangerous for us to
17607
+ // assign a value to any of these type vars at this time.
17608
+ // Typically, they will receive some constraints via some
17609
+ // later argument assignment.
17610
+ if (nakedTypeVarMatches > 1 && (flags & 8 /* AssignTypeFlags.ArgAssignmentFirstPass */) !== 0) {
17611
+ bestDestConstraints = undefined;
17612
+ bestSrcConstraints = undefined;
17613
+ }
17614
+ // If we found a winning type var mapping, copy it back to constraints.
17615
+ if (destConstraints && bestDestConstraints) {
17616
+ destConstraints.copyFromClone(bestDestConstraints);
17592
17617
  }
17593
- if (srcTypeVarContext && bestSrcTypeVarContext) {
17594
- srcTypeVarContext.copyFromClone(bestSrcTypeVarContext);
17618
+ if (srcConstraints && bestSrcConstraints) {
17619
+ srcConstraints.copyFromClone(bestSrcConstraints);
17595
17620
  }
17596
17621
  }
17597
17622
  }
17598
17623
  // If the source is a constrained TypeVar, see if we can assign all of the
17599
17624
  // constraints to the union.
17600
17625
  if (!foundMatch) {
17601
- if ((0, types_1.isTypeVar)(srcType) && srcType.shared.constraints.length > 0) {
17602
- foundMatch = assignType(destType, makeTopLevelTypeVarsConcrete(srcType), diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17626
+ if ((0, types_1.isTypeVar)(srcType) && types_1.TypeVarType.hasConstraints(srcType)) {
17627
+ foundMatch = assignType(destType, makeTopLevelTypeVarsConcrete(srcType), diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destConstraints, srcConstraints, flags, recursionCount);
17603
17628
  }
17604
17629
  }
17605
17630
  if (!foundMatch) {
@@ -17635,15 +17660,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17635
17660
  (0, debug_1.assert)(condition.constraintIndex === 0, 'Expected constraint for bound TypeVar to have index of 0');
17636
17661
  return assignType(destType.shared.boundType, srcSubtype,
17637
17662
  /* diag */ undefined,
17638
- /* destTypeVarContext */ undefined,
17639
- /* srcTypeVarContext */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount);
17663
+ /* destConstraints */ undefined,
17664
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount);
17640
17665
  }
17641
- if (destType.shared.constraints.length > 0) {
17666
+ if (types_1.TypeVarType.hasConstraints(destType)) {
17642
17667
  (0, debug_1.assert)(condition.constraintIndex < destType.shared.constraints.length, 'Constraint for constrained TypeVar is out of bounds');
17643
17668
  return assignType(destType.shared.constraints[condition.constraintIndex], srcSubtype,
17644
17669
  /* diag */ undefined,
17645
- /* destTypeVarContext */ undefined,
17646
- /* srcTypeVarContext */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount);
17670
+ /* destConstraints */ undefined,
17671
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount);
17647
17672
  }
17648
17673
  // This is a non-bound and non-constrained type variable with a matching condition.
17649
17674
  return true;
@@ -17681,7 +17706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17681
17706
  }
17682
17707
  return getBoundMagicMethod(objType, '__call__', /* selfType */ undefined, /* diag */ undefined, recursionCount);
17683
17708
  }
17684
- function assignParam(destType, srcType, paramIndex, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17709
+ function assignParam(destType, srcType, paramIndex, diag, destConstraints, srcConstraints, flags, recursionCount) {
17685
17710
  // Handle the special case where the dest type is a synthesized
17686
17711
  // "self" for a protocol class.
17687
17712
  if ((0, types_1.isTypeVar)(destType) &&
@@ -17698,28 +17723,39 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17698
17723
  let specializedDestType = destType;
17699
17724
  let doSpecializationStep = false;
17700
17725
  if ((flags & 16 /* AssignTypeFlags.OverloadOverlap */) === 0) {
17726
+ const isFirstPass = (flags & 8 /* AssignTypeFlags.ArgAssignmentFirstPass */) !== 0;
17701
17727
  if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0) {
17702
- specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext, { useLowerBoundOnly: true });
17728
+ if (!isFirstPass) {
17729
+ specializedDestType = solveAndApplyConstraints(destType, destConstraints,
17730
+ /* applyOptions */ undefined, {
17731
+ useLowerBoundOnly: true,
17732
+ });
17733
+ }
17703
17734
  doSpecializationStep = (0, typeUtils_1.requiresSpecialization)(specializedDestType);
17704
17735
  }
17705
17736
  else {
17706
- specializedSrcType = (0, typeUtils_1.applySolvedTypeVars)(srcType, srcTypeVarContext, { useLowerBoundOnly: true });
17737
+ if (!isFirstPass) {
17738
+ specializedSrcType = solveAndApplyConstraints(srcType, srcConstraints,
17739
+ /* applyOptions */ undefined, {
17740
+ useLowerBoundOnly: true,
17741
+ });
17742
+ }
17707
17743
  doSpecializationStep = (0, typeUtils_1.requiresSpecialization)(specializedSrcType);
17708
17744
  }
17709
17745
  }
17710
17746
  // Is an additional specialization step required?
17711
17747
  if (doSpecializationStep) {
17712
17748
  if (assignType(specializedSrcType, specializedDestType,
17713
- /* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */, recursionCount)) {
17749
+ /* diag */ undefined, srcConstraints, destConstraints, (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */, recursionCount)) {
17714
17750
  if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0) {
17715
- specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext);
17751
+ specializedDestType = solveAndApplyConstraints(destType, destConstraints);
17716
17752
  }
17717
17753
  else {
17718
- specializedSrcType = (0, typeUtils_1.applySolvedTypeVars)(srcType, srcTypeVarContext);
17754
+ specializedSrcType = solveAndApplyConstraints(srcType, srcConstraints);
17719
17755
  }
17720
17756
  }
17721
17757
  }
17722
- if (!assignType(specializedSrcType, specializedDestType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext, destTypeVarContext, flags, recursionCount)) {
17758
+ if (!assignType(specializedSrcType, specializedDestType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcConstraints, destConstraints, flags, recursionCount)) {
17723
17759
  if (diag && paramIndex !== undefined) {
17724
17760
  diag.addMessage(localize_1.LocAddendum.paramAssignment().format({
17725
17761
  index: paramIndex + 1,
@@ -17778,7 +17814,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17778
17814
  }
17779
17815
  }
17780
17816
  else {
17781
- srcTupleTypes.push({ type: entry.type, isUnbounded: false, isOptional: !!entry.param.defaultType });
17817
+ srcTupleTypes.push({ type: entry.type, isUnbounded: false, isOptional: !!entry.defaultType });
17782
17818
  }
17783
17819
  });
17784
17820
  if (srcTupleTypes.length !== 1 || !(0, types_1.isTypeVarTuple)(srcTupleTypes[0].type)) {
@@ -17791,6 +17827,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17791
17827
  {
17792
17828
  param: types_1.FunctionParam.create(1 /* ParamCategory.ArgsList */, srcPositionalsType, types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, '_arg_combined'),
17793
17829
  type: srcPositionalsType,
17830
+ declaredType: srcPositionalsType,
17794
17831
  index: -1,
17795
17832
  kind: parameterUtils_1.ParamKind.Positional,
17796
17833
  },
@@ -17802,12 +17839,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17802
17839
  srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
17803
17840
  const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.kind === parameterUtils_1.ParamKind.Keyword);
17804
17841
  srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
17805
- srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.kind !== parameterUtils_1.ParamKind.Positional ||
17806
- p.param.category !== 0 /* ParamCategory.Simple */ ||
17807
- !!p.param.defaultType));
17842
+ srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.kind !== parameterUtils_1.ParamKind.Positional || p.param.category !== 0 /* ParamCategory.Simple */ || !!p.defaultType));
17808
17843
  }
17809
17844
  }
17810
- function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17845
+ function assignFunction(destType, srcType, diag, destConstraints, srcConstraints, flags, recursionCount) {
17811
17846
  var _a, _b, _c, _d, _e, _f, _g, _h;
17812
17847
  let canAssign = true;
17813
17848
  const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipReturnTypeCheck */) === 0;
@@ -17869,9 +17904,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17869
17904
  }
17870
17905
  }
17871
17906
  }
17872
- if (destParam.param.defaultType &&
17873
- !srcParam.param.defaultType &&
17874
- paramIndex !== srcParamDetails.argsIndex) {
17907
+ if (destParam.defaultType && !srcParam.defaultType && paramIndex !== srcParamDetails.argsIndex) {
17875
17908
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
17876
17909
  name: srcParamName,
17877
17910
  }));
@@ -17891,7 +17924,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17891
17924
  if ((0, types_1.isUnpacked)(srcParamType)) {
17892
17925
  canAssign = false;
17893
17926
  }
17894
- else if (!assignParam(destParamType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17927
+ else if (!assignParam(destParamType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17895
17928
  // Handle the special case where the source parameter is a synthesized
17896
17929
  // TypeVar for "self" or "cls".
17897
17930
  if ((flags & 512 /* AssignTypeFlags.SkipSelfClsTypeCheck */) === 0 ||
@@ -17928,7 +17961,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17928
17961
  if (destParamDetails.argsIndex !== undefined) {
17929
17962
  const destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
17930
17963
  const srcParamType = srcParamDetails.params[i].type;
17931
- if (!assignParam(destArgsType, srcParamType, i, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17964
+ if (!assignParam(destArgsType, srcParamType, i, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17932
17965
  canAssign = false;
17933
17966
  }
17934
17967
  continue;
@@ -17936,14 +17969,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17936
17969
  // If The source parameter has a default value, it is OK for the
17937
17970
  // corresponding dest parameter to be missing.
17938
17971
  const srcParam = srcParamDetails.params[i];
17939
- if (srcParam.param.defaultType) {
17972
+ if (srcParam.defaultType) {
17940
17973
  // Assign default arg value in case it is needed for
17941
17974
  // populating TypeVar constraints.
17942
17975
  const paramInfo = srcParamDetails.params[i];
17943
- const defaultArgType = (_f = paramInfo.defaultArgType) !== null && _f !== void 0 ? _f : paramInfo.param.defaultType;
17976
+ const defaultArgType = (_f = paramInfo.defaultType) !== null && _f !== void 0 ? _f : paramInfo.defaultType;
17944
17977
  if (defaultArgType &&
17945
- !assignType(paramInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
17946
- /* destTypeVarContext */ undefined, flags, recursionCount)) {
17978
+ !assignType(paramInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcConstraints,
17979
+ /* destConstraints */ undefined, flags, recursionCount)) {
17947
17980
  canAssign = false;
17948
17981
  }
17949
17982
  continue;
@@ -17958,7 +17991,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17958
17991
  if (srcParam.param.category === 1 /* ParamCategory.ArgsList */) {
17959
17992
  continue;
17960
17993
  }
17961
- const nonDefaultSrcParamCount = srcParamDetails.params.filter((p) => !!p.param.name && !p.param.defaultType && p.param.category === 0 /* ParamCategory.Simple */).length;
17994
+ const nonDefaultSrcParamCount = srcParamDetails.params.filter((p) => !!p.param.name && !p.defaultType && p.param.category === 0 /* ParamCategory.Simple */).length;
17962
17995
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
17963
17996
  expected: nonDefaultSrcParamCount,
17964
17997
  received: destPositionalCount,
@@ -17982,7 +18015,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17982
18015
  canAssign = false;
17983
18016
  }
17984
18017
  else {
17985
- if (!assignParam(destParamType, srcArgsType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18018
+ if (!assignParam(destParamType, srcArgsType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
17986
18019
  canAssign = false;
17987
18020
  }
17988
18021
  if (destParamDetails.params[paramIndex].kind !== parameterUtils_1.ParamKind.Positional &&
@@ -18024,7 +18057,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18024
18057
  if (!(0, types_1.isUnpacked)(srcArgsType)) {
18025
18058
  srcArgsType = makeTupleObject([{ type: srcArgsType, isUnbounded: true }], /* isUnpackedTuple */ true);
18026
18059
  }
18027
- if (!assignParam(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18060
+ if (!assignParam(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
18028
18061
  canAssign = false;
18029
18062
  }
18030
18063
  }
@@ -18072,7 +18105,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18072
18105
  const paramDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
18073
18106
  const srcParamType = srcParamInfo.type;
18074
18107
  if (!destParamInfo) {
18075
- if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.defaultType) {
18108
+ if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.defaultType) {
18076
18109
  if (paramDiag) {
18077
18110
  paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
18078
18111
  name: srcParamInfo.param.name,
@@ -18082,28 +18115,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18082
18115
  }
18083
18116
  else if (destParamDetails.kwargsIndex !== undefined) {
18084
18117
  // Make sure we can assign the type to the Kwargs.
18085
- if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamType, destParamDetails.params[destParamDetails.kwargsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18118
+ if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamType, destParamDetails.params[destParamDetails.kwargsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
18086
18119
  canAssign = false;
18087
18120
  }
18088
18121
  }
18089
- else if (srcParamInfo.param.defaultType) {
18122
+ else if (srcParamInfo.defaultType) {
18090
18123
  // Assign default arg values in case they are needed for
18091
18124
  // populating TypeVar constraints.
18092
- const defaultArgType = (_a = srcParamInfo.defaultArgType) !== null && _a !== void 0 ? _a : srcParamInfo.param.defaultType;
18125
+ const defaultArgType = (_a = srcParamInfo.defaultType) !== null && _a !== void 0 ? _a : srcParamInfo.defaultType;
18093
18126
  if (defaultArgType &&
18094
- !assignType(srcParamInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
18095
- /* destTypeVarContext */ undefined, flags, recursionCount)) {
18127
+ !assignType(srcParamInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcConstraints,
18128
+ /* destConstraints */ undefined, flags, recursionCount)) {
18096
18129
  canAssign = false;
18097
18130
  }
18098
18131
  }
18099
18132
  }
18100
18133
  else {
18101
18134
  const destParamType = destParamInfo.type;
18102
- const specializedDestParamType = destTypeVarContext
18103
- ? (0, typeUtils_1.applySolvedTypeVars)(destParamType, destTypeVarContext)
18135
+ const specializedDestParamType = destConstraints
18136
+ ? solveAndApplyConstraints(destParamType, destConstraints)
18104
18137
  : destParamType;
18105
18138
  if (!assignParam(destParamInfo.type, srcParamType,
18106
- /* paramIndex */ undefined, paramDiag === null || paramDiag === void 0 ? void 0 : paramDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18139
+ /* paramIndex */ undefined, paramDiag === null || paramDiag === void 0 ? void 0 : paramDiag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
18107
18140
  if (paramDiag) {
18108
18141
  paramDiag.addMessage(localize_1.LocAddendum.namedParamTypeMismatch().format({
18109
18142
  name: srcParamInfo.param.name,
@@ -18113,7 +18146,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18113
18146
  }
18114
18147
  canAssign = false;
18115
18148
  }
18116
- if (destParamInfo.param.defaultType && !srcParamInfo.param.defaultType) {
18149
+ if (destParamInfo.defaultType && !srcParamInfo.defaultType) {
18117
18150
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
18118
18151
  name: srcParamInfo.param.name,
18119
18152
  }));
@@ -18129,7 +18162,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18129
18162
  destParamMap.forEach((destParamInfo, paramName) => {
18130
18163
  if (srcParamDetails.kwargsIndex !== undefined && destParamInfo.param.name) {
18131
18164
  // Make sure the src kwargs type is compatible.
18132
- if (!assignParam(destParamInfo.param.type, srcParamDetails.params[srcParamDetails.kwargsIndex].type, destParamInfo.index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18165
+ if (!assignParam(destParamInfo.type, srcParamDetails.params[srcParamDetails.kwargsIndex].type, destParamInfo.index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
18133
18166
  canAssign = false;
18134
18167
  }
18135
18168
  destParamMap.delete(paramName);
@@ -18141,7 +18174,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18141
18174
  });
18142
18175
  // If both src and dest have a "**kwargs" parameter, make sure their types are compatible.
18143
18176
  if (srcParamDetails.kwargsIndex !== undefined && destParamDetails.kwargsIndex !== undefined) {
18144
- if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamDetails.params[srcParamDetails.kwargsIndex].type, destParamDetails.params[destParamDetails.kwargsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18177
+ if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamDetails.params[srcParamDetails.kwargsIndex].type, destParamDetails.params[destParamDetails.kwargsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
18145
18178
  canAssign = false;
18146
18179
  }
18147
18180
  }
@@ -18164,14 +18197,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18164
18197
  canAssign = false;
18165
18198
  }
18166
18199
  }
18167
- const effectiveSrcTypeVarContext = reverseMatching ? destTypeVarContext : srcTypeVarContext;
18168
18200
  // If the target function was generic and we solved some of the type variables
18169
18201
  // in that generic type, assign them back to the destination typeVar.
18170
- const solutionSet = effectiveSrcTypeVarContext.getMainSolutionSet();
18171
- solutionSet.getTypeVars().forEach((typeVarEntry) => {
18172
- assignType(typeVarEntry.typeVar, solutionSet.getTypeVarType(typeVarEntry.typeVar),
18173
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, 0 /* AssignTypeFlags.Default */, recursionCount);
18174
- });
18202
+ const effectiveSrcConstraints = reverseMatching ? destConstraints : srcConstraints;
18203
+ if (!effectiveSrcConstraints.isEmpty()) {
18204
+ const srcConstraintSet = effectiveSrcConstraints.getMainConstraintSet();
18205
+ const solutionSet = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, effectiveSrcConstraints).getMainSolutionSet();
18206
+ srcConstraintSet.doForEachTypeVar((entry) => {
18207
+ const solvedValue = solutionSet.getType(entry.typeVar);
18208
+ if (solvedValue) {
18209
+ assignType(entry.typeVar, solvedValue,
18210
+ /* diag */ undefined, destConstraints, srcConstraints, 0 /* AssignTypeFlags.Default */, recursionCount);
18211
+ }
18212
+ });
18213
+ }
18175
18214
  // Are we assigning to a function with a ParamSpec?
18176
18215
  if (targetIncludesParamSpec) {
18177
18216
  const effectiveSrcType = reverseMatching ? destType : srcType;
@@ -18179,11 +18218,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18179
18218
  const effectiveSrcParamSpec = reverseMatching ? destParamSpec : srcParamSpec;
18180
18219
  const effectiveDestParamSpec = reverseMatching ? srcParamSpec : destParamSpec;
18181
18220
  if (effectiveDestParamSpec) {
18182
- const requiredMatchParamCount = effectiveDestType.shared.parameters.filter((p) => {
18221
+ const requiredMatchParamCount = effectiveDestType.shared.parameters.filter((p, i) => {
18183
18222
  if (!p.name) {
18184
18223
  return false;
18185
18224
  }
18186
- if (p.category === 0 /* ParamCategory.Simple */ && (0, types_1.isParamSpec)(p.type)) {
18225
+ const paramType = types_1.FunctionType.getParamType(effectiveDestType, i);
18226
+ if (p.category === 0 /* ParamCategory.Simple */ && (0, types_1.isParamSpec)(paramType)) {
18187
18227
  return false;
18188
18228
  }
18189
18229
  return true;
@@ -18204,7 +18244,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18204
18244
  // is the first remaining param.
18205
18245
  }
18206
18246
  else {
18207
- remainingParams.push(types_1.FunctionParam.create(p.category, types_1.FunctionType.getEffectiveParamType(effectiveSrcType, index), p.flags, p.name, p.defaultType ? types_1.AnyType.create(/* isEllipsis */ true) : undefined));
18247
+ remainingParams.push(types_1.FunctionParam.create(p.category, types_1.FunctionType.getParamType(effectiveSrcType, index), p.flags, p.name, types_1.FunctionType.getParamDefaultType(effectiveSrcType, index)
18248
+ ? types_1.AnyType.create(/* isEllipsis */ true)
18249
+ : undefined));
18208
18250
  }
18209
18251
  });
18210
18252
  // If there are remaining parameters and the source and dest do not contain
@@ -18223,16 +18265,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18223
18265
  if (effectiveSrcParamSpec) {
18224
18266
  types_1.FunctionType.addParamSpecVariadics(remainingFunction, (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec));
18225
18267
  }
18226
- types_1.FunctionType.addHigherOrderTypeVarScopeIds(remainingFunction, effectiveSrcType.priv.higherOrderTypeVarScopeIds);
18227
18268
  if (!assignType(effectiveDestParamSpec, remainingFunction,
18228
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
18269
+ /* diag */ undefined, destConstraints, srcConstraints, flags)) {
18229
18270
  // If we couldn't assign the function to the ParamSpec, see if we can
18230
18271
  // assign only the ParamSpec. This is possible if there were no
18231
18272
  // remaining parameters.
18232
18273
  if (remainingParams.length > 0 ||
18233
18274
  !effectiveSrcParamSpec ||
18234
18275
  !assignType((0, typeUtils_1.convertToInstance)(effectiveDestParamSpec), (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec),
18235
- /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
18276
+ /* diag */ undefined, destConstraints, srcConstraints, flags)) {
18236
18277
  canAssign = false;
18237
18278
  }
18238
18279
  }
@@ -18243,7 +18284,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18243
18284
  if (checkReturnType) {
18244
18285
  const destReturnType = getFunctionEffectiveReturnType(destType);
18245
18286
  if (!(0, types_1.isAnyOrUnknown)(destReturnType)) {
18246
- const srcReturnType = (0, typeUtils_1.applySolvedTypeVars)(getFunctionEffectiveReturnType(srcType), srcTypeVarContext);
18287
+ const srcReturnType = solveAndApplyConstraints(getFunctionEffectiveReturnType(srcType), srcConstraints);
18247
18288
  const returnDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
18248
18289
  let isReturnTypeCompatible = false;
18249
18290
  let effectiveFlags = flags;
@@ -18254,7 +18295,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18254
18295
  (0, typeUtils_1.containsLiteralType)(srcType.shared.declaredReturnType, /* includeTypeArgs */ true)) {
18255
18296
  effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
18256
18297
  }
18257
- if (assignType(destReturnType, srcReturnType, returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, effectiveFlags, recursionCount)) {
18298
+ if (assignType(destReturnType, srcReturnType, returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destConstraints, srcConstraints, effectiveFlags, recursionCount)) {
18258
18299
  isReturnTypeCompatible = true;
18259
18300
  }
18260
18301
  else {
@@ -18265,7 +18306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18265
18306
  types_1.ClassType.isBuiltIn(srcReturnType, ['TypeGuard', 'TypeIs']) &&
18266
18307
  boolClass &&
18267
18308
  (0, types_1.isInstantiableClass)(boolClass)) {
18268
- if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClass), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18309
+ if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClass), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destConstraints, srcConstraints, flags, recursionCount)) {
18269
18310
  isReturnTypeCompatible = true;
18270
18311
  }
18271
18312
  }
@@ -18283,7 +18324,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18283
18324
  }
18284
18325
  // Apply any solved source TypeVars to the dest TypeVar solutions. This
18285
18326
  // allows for higher-order functions to accept generic callbacks.
18286
- (0, typeUtils_1.applySourceContextTypeVars)(destTypeVarContext, srcTypeVarContext);
18327
+ (0, typeUtils_1.applySourceContextTypeVars)(destConstraints, (0, constraintSolver_1.solveConstraints)(evaluatorInterface, srcConstraints));
18287
18328
  return canAssign;
18288
18329
  }
18289
18330
  // If the declaredType contains type arguments that are "Any" and
@@ -18300,12 +18341,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18300
18341
  assignedType.priv.typeArgs &&
18301
18342
  assignedType.priv.typeArgs.length <= assignedType.shared.typeParams.length &&
18302
18343
  !assignedType.priv.tupleTypeArgs) {
18303
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
18304
- (0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.specialize(assignedType, /* typeArgs */ undefined), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start);
18344
+ const constraints = new constraintTracker_1.ConstraintTracker();
18345
+ (0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.specialize(assignedType, /* typeArgs */ undefined), declaredType, constraints, ParseTreeUtils.getTypeVarScopesForNode(node), node.start);
18305
18346
  let replacedTypeArg = false;
18347
+ const solution = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints).getMainSolutionSet();
18306
18348
  const newTypeArgs = assignedType.priv.typeArgs.map((typeArg, index) => {
18307
18349
  const typeParam = assignedType.shared.typeParams[index];
18308
- const expectedTypeArgType = typeVarContext.getMainSolutionSet().getTypeVarType(typeParam);
18350
+ const expectedTypeArgType = solution.getType(typeParam);
18309
18351
  if (expectedTypeArgType) {
18310
18352
  if ((0, types_1.isAnyOrUnknown)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
18311
18353
  replacedTypeArg = true;
@@ -18536,10 +18578,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18536
18578
  const childSelfOrClsType = types_1.FunctionType.isInstanceMethod(baseMethod)
18537
18579
  ? types_1.ClassType.cloneAsInstance(childClass)
18538
18580
  : childClass;
18539
- return assignType(baseParamType.type, childSelfOrClsType,
18581
+ return assignType(baseParamDetails.params[0].type, childSelfOrClsType,
18540
18582
  /* diag */ undefined,
18541
- /* destTypeVarContext */ undefined,
18542
- /* srcTypeVarContext */ undefined, 8 /* AssignTypeFlags.SkipSolveTypeVars */);
18583
+ /* destConstraints */ undefined,
18584
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */);
18543
18585
  }
18544
18586
  // Determines whether the override method is compatible with the overridden method.
18545
18587
  // This is used both for parent/child overrides and implicit overrides for peer
@@ -18584,7 +18626,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18584
18626
  else {
18585
18627
  const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18586
18628
  for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
18587
- if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
18629
+ if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
18630
+ /* destConstraints */ undefined,
18631
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
18588
18632
  localize_1.LocAddendum.overrideParamType().format({
18589
18633
  index: i + 1,
18590
18634
  baseType: printType(baseParamDetails.params[i].type),
@@ -18603,7 +18647,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18603
18647
  const overrideParam = overrideParamDetails.params[i].param;
18604
18648
  if (overrideParam.category === 0 /* ParamCategory.Simple */ &&
18605
18649
  overrideParam.name &&
18606
- !overrideParam.defaultType) {
18650
+ !overrideParamDetails.params[i].defaultType) {
18607
18651
  foundParamCountMismatch = true;
18608
18652
  }
18609
18653
  }
@@ -18672,7 +18716,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18672
18716
  const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.shared.isSynthesized;
18673
18717
  if (!exemptSelfClsParam || (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar)) {
18674
18718
  if (baseParam.category !== overrideParam.category ||
18675
- !assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
18719
+ !assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
18720
+ /* destConstraints */ undefined,
18721
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
18676
18722
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamType().format({
18677
18723
  index: i + 1,
18678
18724
  baseType: printType(baseParamType),
@@ -18681,8 +18727,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18681
18727
  canOverride = false;
18682
18728
  }
18683
18729
  }
18684
- if (baseParamDetails.params[i].param.defaultType &&
18685
- !overrideParamDetails.params[i].param.defaultType) {
18730
+ if (baseParamDetails.params[i].defaultType && !overrideParamDetails.params[i].defaultType) {
18686
18731
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNoDefault().format({
18687
18732
  index: i + 1,
18688
18733
  }));
@@ -18715,8 +18760,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18715
18760
  else {
18716
18761
  const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18717
18762
  const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
18718
- if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
18719
- /* srcTypeVarContext */ undefined, 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
18763
+ if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
18764
+ /* destConstraints */ undefined,
18765
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
18720
18766
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
18721
18767
  name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
18722
18768
  baseType: printType(baseParamType),
@@ -18743,7 +18789,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18743
18789
  if (!targetParamType) {
18744
18790
  targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
18745
18791
  }
18746
- if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
18792
+ if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
18793
+ /* destConstraints */ undefined,
18794
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
18747
18795
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordType().format({
18748
18796
  name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
18749
18797
  baseType: printType(paramInfo.type),
@@ -18752,7 +18800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18752
18800
  canOverride = false;
18753
18801
  }
18754
18802
  if (overrideParamInfo) {
18755
- if (paramInfo.param.defaultType && !overrideParamInfo.param.defaultType) {
18803
+ if (paramInfo.defaultType && !overrideParamInfo.defaultType) {
18756
18804
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamKeywordNoDefault().format({
18757
18805
  name: (_c = overrideParamInfo.param.name) !== null && _c !== void 0 ? _c : '?',
18758
18806
  }));
@@ -18768,7 +18816,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18768
18816
  const baseParamInfo = baseKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
18769
18817
  if (!baseParamInfo) {
18770
18818
  if (baseParamDetails.kwargsIndex === undefined) {
18771
- if (!paramInfo.param.defaultType) {
18819
+ if (!paramInfo.defaultType) {
18772
18820
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNameExtra().format({
18773
18821
  name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
18774
18822
  }));
@@ -18801,7 +18849,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18801
18849
  // Now check the return type.
18802
18850
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
18803
18851
  const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);
18804
- if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
18852
+ if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
18853
+ /* destConstraints */ undefined,
18854
+ /* srcConstraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
18805
18855
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideReturnType().format({
18806
18856
  baseType: printType(baseReturnType),
18807
18857
  overrideType: printType(overrideReturnType),
@@ -18833,8 +18883,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18833
18883
  // If there's a bound type, make sure the source is derived from it.
18834
18884
  if (destType.shared.boundType && !(0, typeUtils_1.isTypeAliasPlaceholder)(effectiveSrcType)) {
18835
18885
  if (!assignType(destType.shared.boundType, effectiveSrcType, diag.createAddendum(),
18836
- /* destTypeVarContext */ undefined,
18837
- /* srcTypeVarContext */ undefined)) {
18886
+ /* destConstraints */ undefined,
18887
+ /* srcConstraints */ undefined)) {
18838
18888
  // Avoid adding a message that will confuse users if the TypeVar was
18839
18889
  // synthesized for internal purposes.
18840
18890
  if (!destType.shared.isSynthesized) {
@@ -18875,7 +18925,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18875
18925
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(srcType)) {
18876
18926
  return srcType;
18877
18927
  }
18878
- if ((0, types_1.isTypeVar)(srcType) && srcType.shared.constraints.length > 0) {
18928
+ if ((0, types_1.isTypeVar)(srcType) && types_1.TypeVarType.hasConstraints(srcType)) {
18879
18929
  // Make sure all the source constraint types map to constraint types in the dest.
18880
18930
  if (srcType.shared.constraints.every((sourceConstraint) => {
18881
18931
  return constraints.some((destConstraint) => assignType(destConstraint, sourceConstraint));
@@ -18961,18 +19011,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18961
19011
  else if (memberClass && (0, typeUtils_1.isInstantiableMetaclass)(memberClass)) {
18962
19012
  stripFirstParam = true;
18963
19013
  }
18964
- return partiallySpecializeBoundMethod(baseType, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : types_1.ClassType.cloneAsInstantiable(baseObj), diag, recursionCount, selfType !== null && selfType !== void 0 ? selfType : baseObj, stripFirstParam);
19014
+ return partiallySpecializeBoundMethod(baseType, functionType, diag, recursionCount, selfType !== null && selfType !== void 0 ? selfType : baseObj, stripFirstParam);
18965
19015
  }
18966
19016
  if (types_1.FunctionType.isClassMethod(functionType) ||
18967
19017
  (treatConstructorAsClassMethod && types_1.FunctionType.isConstructorMethod(functionType))) {
18968
19018
  const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
18969
19019
  const clsType = selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : undefined;
18970
- return partiallySpecializeBoundMethod(baseClass, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : baseClass, diag, recursionCount, clsType !== null && clsType !== void 0 ? clsType : baseClass,
19020
+ return partiallySpecializeBoundMethod(baseClass, functionType, diag, recursionCount, clsType !== null && clsType !== void 0 ? clsType : baseClass,
18971
19021
  /* stripFirstParam */ true);
18972
19022
  }
18973
19023
  if (types_1.FunctionType.isStaticMethod(functionType)) {
18974
19024
  const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
18975
- return partiallySpecializeBoundMethod(baseClass, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : baseClass, diag, recursionCount,
19025
+ return partiallySpecializeBoundMethod(baseClass, functionType, diag, recursionCount,
18976
19026
  /* firstParamType */ undefined,
18977
19027
  /* stripFirstParam */ false);
18978
19028
  }
@@ -18982,16 +19032,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18982
19032
  // Specializes the specified function for the specified class,
18983
19033
  // optionally stripping the first first parameter (the "self" or "cls")
18984
19034
  // off of the specialized function in the process. The baseType
18985
- // is the type used to reference the member, and the memberClass
18986
- // is the class that provided the member (could be an ancestor of
18987
- // the baseType's class).
18988
- function partiallySpecializeBoundMethod(baseType, memberType, memberClass, diag, recursionCount, firstParamType, stripFirstParam = true) {
18989
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(memberClass));
19035
+ // is the type used to reference the member.
19036
+ function partiallySpecializeBoundMethod(baseType, memberType, diag, recursionCount, firstParamType, stripFirstParam = true) {
19037
+ const constraints = new constraintTracker_1.ConstraintTracker();
18990
19038
  if (firstParamType && memberType.shared.parameters.length > 0) {
18991
19039
  const memberTypeFirstParam = memberType.shared.parameters[0];
18992
- const memberTypeFirstParamType = types_1.FunctionType.getEffectiveParamType(memberType, 0);
18993
- // Fill out the typeVarContext for the "self" or "cls" parameter.
18994
- typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(memberType));
19040
+ const memberTypeFirstParamType = types_1.FunctionType.getParamType(memberType, 0);
18995
19041
  if ((0, types_1.isTypeVar)(memberTypeFirstParamType) &&
18996
19042
  memberTypeFirstParamType.shared.boundType &&
18997
19043
  (0, types_1.isClassInstance)(memberTypeFirstParamType.shared.boundType) &&
@@ -19000,16 +19046,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19000
19046
  // contain references to themselves or their subclasses, so if
19001
19047
  // we attempt to call assignType, we'll risk infinite recursion.
19002
19048
  // Instead, we'll assume it's assignable.
19003
- if (!typeVarContext.isLocked()) {
19004
- (0, typeUtils_1.setTypeVarType)(typeVarContext, memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
19049
+ if (!constraints.isLocked()) {
19050
+ constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
19005
19051
  ? (0, typeUtils_1.convertToInstance)(firstParamType)
19006
19052
  : firstParamType);
19007
19053
  }
19008
19054
  }
19009
19055
  else {
19010
19056
  const subDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
19011
- if (!assignType(memberTypeFirstParamType, firstParamType, subDiag === null || subDiag === void 0 ? void 0 : subDiag.createAddendum(), typeVarContext,
19012
- /* srcTypeVarContext */ undefined, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArgs */, recursionCount)) {
19057
+ if (!assignType(memberTypeFirstParamType, firstParamType, subDiag === null || subDiag === void 0 ? void 0 : subDiag.createAddendum(), constraints,
19058
+ /* srcConstraints */ undefined, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArgs */, recursionCount)) {
19013
19059
  if (memberTypeFirstParam.name &&
19014
19060
  !types_1.FunctionParam.isNameSynthesized(memberTypeFirstParam) &&
19015
19061
  types_1.FunctionParam.isTypeDeclared(memberTypeFirstParam)) {
@@ -19028,14 +19074,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19028
19074
  // Get the effective return type, which will have the side effect of lazily
19029
19075
  // evaluating (and caching) the inferred return type if there is no defined return type.
19030
19076
  getFunctionEffectiveReturnType(memberType);
19031
- const specializedFunction = (0, typeUtils_1.applySolvedTypeVars)(memberType, typeVarContext);
19032
- // If this is a constructor method, provide the base type's TypeVar scope ID
19033
- // so any TypeVars in this type can be solved.
19034
- let baseTypeTypeVarScopeId;
19035
- if (types_1.FunctionType.isConstructorMethod(specializedFunction) || specializedFunction.shared.name === '__init__') {
19036
- baseTypeTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(baseType);
19037
- }
19038
- return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType, baseTypeTypeVarScopeId);
19077
+ const specializedFunction = solveAndApplyConstraints(memberType, constraints);
19078
+ return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType);
19039
19079
  }
19040
19080
  function isFinalVariable(symbol) {
19041
19081
  return symbol.getDeclarations().some((decl) => isFinalVariableDeclaration(decl));
@@ -19257,18 +19297,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19257
19297
  function printControlFlowGraph(flowNode, reference, callName, logger) {
19258
19298
  return codeFlowEngine.printControlFlowGraph(flowNode, reference, callName, logger);
19259
19299
  }
19260
- function printTypeVarContext(typeVarContext) {
19261
- const solutionSets = typeVarContext.getSolutionSets();
19262
- solutionSets.forEach((context, index) => {
19263
- if (solutionSets.length > 1) {
19264
- console.log(`Solution set ${index + 1}:`);
19265
- }
19266
- context.getTypeVars().forEach((typeVarEntry) => {
19267
- const type = context.getTypeVarType(typeVarEntry.typeVar);
19268
- console.log(` ${typeVarEntry.typeVar.shared.name}: ${type ? printType(type) : '<none>'}`);
19269
- });
19270
- });
19271
- }
19272
19300
  // Track these apis internal usages when logging is on. otherwise, it should be noop.
19273
19301
  const getFunctionInferredReturnType = wrapWithLogger(_getFunctionInferredReturnType);
19274
19302
  const evaluatorInterface = {
@@ -19295,6 +19323,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19295
19323
  removeTruthinessFromType,
19296
19324
  removeFalsinessFromType,
19297
19325
  stripTypeGuard,
19326
+ solveAndApplyConstraints,
19298
19327
  verifyRaiseExceptionType,
19299
19328
  verifyDeleteExpression,
19300
19329
  validateOverloadedArgTypes,
@@ -19375,7 +19404,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19375
19404
  setTypeResultForNode,
19376
19405
  checkForCancellation,
19377
19406
  printControlFlowGraph,
19378
- printTypeVarContext,
19379
19407
  };
19380
19408
  const codeFlowEngine = (0, codeFlowEngine_1.getCodeFlowEngine)(evaluatorInterface, speculativeTypeTracker);
19381
19409
  return evaluatorInterface;