@zzzen/pyright-internal 1.2.0-dev.20240915 → 1.2.0-dev.20240929

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 (130) hide show
  1. package/dist/analyzer/binder.d.ts +1 -0
  2. package/dist/analyzer/binder.js +19 -0
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.d.ts +0 -1
  5. package/dist/analyzer/checker.js +70 -88
  6. package/dist/analyzer/checker.js.map +1 -1
  7. package/dist/analyzer/codeFlowEngine.js +21 -3
  8. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  9. package/dist/analyzer/commentUtils.js +2 -2
  10. package/dist/analyzer/commentUtils.js.map +1 -1
  11. package/dist/analyzer/constraintSolver.js +8 -23
  12. package/dist/analyzer/constraintSolver.js.map +1 -1
  13. package/dist/analyzer/constraintTracker.d.ts +0 -4
  14. package/dist/analyzer/constraintTracker.js +0 -21
  15. package/dist/analyzer/constraintTracker.js.map +1 -1
  16. package/dist/analyzer/constructors.js +14 -7
  17. package/dist/analyzer/constructors.js.map +1 -1
  18. package/dist/analyzer/importResolver.js +1 -1
  19. package/dist/analyzer/importResolver.js.map +1 -1
  20. package/dist/analyzer/operations.js +42 -28
  21. package/dist/analyzer/operations.js.map +1 -1
  22. package/dist/analyzer/packageTypeVerifier.js +4 -4
  23. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  24. package/dist/analyzer/patternMatching.js +7 -4
  25. package/dist/analyzer/patternMatching.js.map +1 -1
  26. package/dist/analyzer/protocols.js +2 -2
  27. package/dist/analyzer/protocols.js.map +1 -1
  28. package/dist/analyzer/service.d.ts +1 -2
  29. package/dist/analyzer/service.js +40 -29
  30. package/dist/analyzer/service.js.map +1 -1
  31. package/dist/analyzer/sourceMapper.js +5 -3
  32. package/dist/analyzer/sourceMapper.js.map +1 -1
  33. package/dist/analyzer/symbol.d.ts +3 -0
  34. package/dist/analyzer/symbol.js +6 -0
  35. package/dist/analyzer/symbol.js.map +1 -1
  36. package/dist/analyzer/tracePrinter.js +5 -5
  37. package/dist/analyzer/tracePrinter.js.map +1 -1
  38. package/dist/analyzer/typeEvaluator.js +212 -142
  39. package/dist/analyzer/typeEvaluator.js.map +1 -1
  40. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -1
  41. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  42. package/dist/analyzer/typeGuards.js +14 -4
  43. package/dist/analyzer/typeGuards.js.map +1 -1
  44. package/dist/analyzer/typePrinter.js +16 -12
  45. package/dist/analyzer/typePrinter.js.map +1 -1
  46. package/dist/analyzer/typeUtils.d.ts +1 -0
  47. package/dist/analyzer/typeUtils.js +16 -4
  48. package/dist/analyzer/typeUtils.js.map +1 -1
  49. package/dist/analyzer/types.d.ts +7 -3
  50. package/dist/analyzer/types.js +6 -0
  51. package/dist/analyzer/types.js.map +1 -1
  52. package/dist/backgroundAnalysisBase.js +2 -1
  53. package/dist/backgroundAnalysisBase.js.map +1 -1
  54. package/dist/common/commandLineOptions.d.ts +1 -0
  55. package/dist/common/commandLineOptions.js.map +1 -1
  56. package/dist/common/configOptions.d.ts +3 -1
  57. package/dist/common/configOptions.js +17 -4
  58. package/dist/common/configOptions.js.map +1 -1
  59. package/dist/common/fileSystem.d.ts +8 -1
  60. package/dist/common/fileSystem.js +10 -1
  61. package/dist/common/fileSystem.js.map +1 -1
  62. package/dist/common/memUtils.js +3 -0
  63. package/dist/common/memUtils.js.map +1 -1
  64. package/dist/common/pathUtils.d.ts +3 -3
  65. package/dist/common/realFileSystem.js +2 -0
  66. package/dist/common/realFileSystem.js.map +1 -1
  67. package/dist/languageService/analyzerServiceExecutor.js +1 -1
  68. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  69. package/dist/languageService/autoImporter.d.ts +9 -7
  70. package/dist/languageService/autoImporter.js +32 -34
  71. package/dist/languageService/autoImporter.js.map +1 -1
  72. package/dist/languageService/completionProvider.js +1 -1
  73. package/dist/languageService/completionProvider.js.map +1 -1
  74. package/dist/languageService/completionProviderUtils.js +1 -1
  75. package/dist/languageService/completionProviderUtils.js.map +1 -1
  76. package/dist/languageService/hoverProvider.d.ts +1 -1
  77. package/dist/languageService/hoverProvider.js +12 -12
  78. package/dist/languageService/hoverProvider.js.map +1 -1
  79. package/dist/languageService/symbolIndexer.d.ts +8 -1
  80. package/dist/languageService/symbolIndexer.js +17 -2
  81. package/dist/languageService/symbolIndexer.js.map +1 -1
  82. package/dist/localization/localize.d.ts +1 -0
  83. package/dist/localization/localize.js +1 -0
  84. package/dist/localization/localize.js.map +1 -1
  85. package/dist/localization/package.nls.cs.json +2 -0
  86. package/dist/localization/package.nls.de.json +2 -0
  87. package/dist/localization/package.nls.en-us.json +4 -0
  88. package/dist/localization/package.nls.es.json +2 -0
  89. package/dist/localization/package.nls.fr.json +2 -0
  90. package/dist/localization/package.nls.it.json +2 -0
  91. package/dist/localization/package.nls.ja.json +2 -0
  92. package/dist/localization/package.nls.ko.json +2 -0
  93. package/dist/localization/package.nls.pl.json +2 -0
  94. package/dist/localization/package.nls.pt-br.json +2 -0
  95. package/dist/localization/package.nls.qps-ploc.json +2 -0
  96. package/dist/localization/package.nls.ru.json +2 -0
  97. package/dist/localization/package.nls.tr.json +49 -47
  98. package/dist/localization/package.nls.zh-cn.json +2 -0
  99. package/dist/localization/package.nls.zh-tw.json +2 -0
  100. package/dist/parser/unicode.js +136 -8
  101. package/dist/parser/unicode.js.map +1 -1
  102. package/dist/readonlyAugmentedFileSystem.js +2 -1
  103. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  104. package/dist/tests/config.test.js +40 -3
  105. package/dist/tests/config.test.js.map +1 -1
  106. package/dist/tests/harness/fourslash/testLanguageService.d.ts +0 -1
  107. package/dist/tests/harness/fourslash/testLanguageService.js +0 -3
  108. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  109. package/dist/tests/harness/fourslash/testState.d.ts +1 -2
  110. package/dist/tests/harness/fourslash/testState.js +0 -7
  111. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  112. package/dist/tests/harness/vfs/filesystem.js +8 -3
  113. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  114. package/dist/tests/sourceMapperUtils.test.js +2 -2
  115. package/dist/tests/sourceMapperUtils.test.js.map +1 -1
  116. package/dist/tests/typeEvaluator2.test.js +4 -0
  117. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  118. package/dist/tests/typeEvaluator3.test.js +10 -0
  119. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  120. package/dist/tests/typeEvaluator4.test.js +4 -0
  121. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  122. package/dist/tests/typeEvaluator6.test.js +6 -2
  123. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  124. package/dist/tests/typeEvaluator7.test.js +4 -0
  125. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  126. package/dist/tests/typeEvaluator8.test.js +7 -1
  127. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  128. package/dist/workspaceFactory.js +1 -1
  129. package/dist/workspaceFactory.js.map +1 -1
  130. package/package.json +8 -8
@@ -209,6 +209,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
209
209
  let intClass;
210
210
  let strClass;
211
211
  let dictClass;
212
+ let moduleTypeClass;
212
213
  let typedDictPrivateClass;
213
214
  let supportsKeysAndGetItemClass;
214
215
  let mappingClass;
@@ -390,7 +391,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
390
391
  // context, logging any errors in the process. This may require the
391
392
  // type of surrounding statements to be evaluated.
392
393
  function getType(node) {
393
- var _a, _b;
394
+ var _a, _b, _c, _d;
394
395
  initializePrefetchedTypes(node);
395
396
  let type = (_a = evaluateTypeForSubnode(node, () => {
396
397
  evaluateTypesForExpressionInContext(node);
@@ -405,8 +406,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
405
406
  if (classTypeResult) {
406
407
  inferVarianceForClass(classTypeResult.classType);
407
408
  const typeParam = classTypeResult.classType.shared.typeParams.find((param) => (0, types_1.isTypeSame)(param, typeVarType, { ignoreTypeFlags: true }));
408
- if (typeParam) {
409
- type = types_1.TypeBase.isInstance(type) ? types_1.TypeVarType.cloneAsInstance(typeParam) : typeParam;
409
+ if ((typeParam === null || typeParam === void 0 ? void 0 : typeParam.priv.computedVariance) !== undefined) {
410
+ type = types_1.TypeVarType.cloneWithComputedVariance(type, typeParam.priv.computedVariance);
411
+ }
412
+ }
413
+ }
414
+ else if (((_c = typeParamListNode === null || typeParamListNode === void 0 ? void 0 : typeParamListNode.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 77 /* ParseNodeType.TypeAlias */) {
415
+ const typeAliasType = getTypeOfTypeAlias(typeParamListNode.parent);
416
+ const typeParamIndex = typeParamListNode.d.params.findIndex((param) => param.d.name === node);
417
+ if (typeParamIndex >= 0) {
418
+ inferVarianceForTypeAlias(typeAliasType);
419
+ const typeAliasInfo = (_d = typeAliasType.props) === null || _d === void 0 ? void 0 : _d.typeAliasInfo;
420
+ if (typeAliasInfo === null || typeAliasInfo === void 0 ? void 0 : typeAliasInfo.shared.computedVariance) {
421
+ const computedVariance = typeAliasInfo.shared.computedVariance[typeParamIndex];
422
+ type = types_1.TypeVarType.cloneWithComputedVariance(type, computedVariance);
410
423
  }
411
424
  }
412
425
  }
@@ -490,6 +503,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
490
503
  intClass = getBuiltInType(node, 'int');
491
504
  strClass = getBuiltInType(node, 'str');
492
505
  dictClass = getBuiltInType(node, 'dict');
506
+ moduleTypeClass = getTypingType(node, 'ModuleType');
493
507
  typedDictPrivateClass = getTypingType(node, '_TypedDict');
494
508
  awaitableClass = getTypingType(node, 'Awaitable');
495
509
  mappingClass = getTypingType(node, 'Mapping');
@@ -992,7 +1006,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
992
1006
  updatedFlags |= 524288 /* EvalFlags.NotParsed */;
993
1007
  }
994
1008
  updatedFlags &= ~1073741824 /* EvalFlags.TypeFormArg */;
995
- if (node.d.annotation) {
1009
+ if (node.d.annotation && (flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
996
1010
  return getTypeOfExpression(node.d.annotation, updatedFlags);
997
1011
  }
998
1012
  if (node.d.strings.length === 1) {
@@ -1724,6 +1738,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1724
1738
  function getDeclaredTypeForExpression(expression, usage) {
1725
1739
  var _a, _b;
1726
1740
  let symbol;
1741
+ let selfType;
1727
1742
  let classOrObjectBase;
1728
1743
  let memberAccessClass;
1729
1744
  let bindFunction = true;
@@ -1756,11 +1771,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1756
1771
  return getDeclaredTypeForExpression(expression.d.valueExpr, usage);
1757
1772
  }
1758
1773
  case 35 /* ParseNodeType.MemberAccess */: {
1759
- const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.d.leftExpr, 2 /* EvalFlags.MemberAccessBaseDefaults */).type);
1774
+ const baseType = getTypeOfExpression(expression.d.leftExpr, 2 /* EvalFlags.MemberAccessBaseDefaults */).type;
1775
+ const baseTypeConcrete = makeTopLevelTypeVarsConcrete(baseType);
1760
1776
  let classMemberInfo;
1761
- if ((0, types_1.isClassInstance)(baseType)) {
1762
- classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.d.member.d.value, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
1763
- classOrObjectBase = baseType;
1777
+ if ((0, types_1.isClassInstance)(baseTypeConcrete)) {
1778
+ classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseTypeConcrete, expression.d.member.d.value, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
1779
+ classOrObjectBase = baseTypeConcrete;
1764
1780
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1765
1781
  // If this is an instance member (e.g. a dataclass field), don't
1766
1782
  // bind it to the object if it's a function.
@@ -1769,11 +1785,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1769
1785
  }
1770
1786
  useDescriptorSetterType = true;
1771
1787
  }
1772
- else if ((0, types_1.isInstantiableClass)(baseType)) {
1773
- classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.d.member.d.value, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
1774
- classOrObjectBase = baseType;
1788
+ else if ((0, types_1.isInstantiableClass)(baseTypeConcrete)) {
1789
+ classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseTypeConcrete, expression.d.member.d.value, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
1790
+ classOrObjectBase = baseTypeConcrete;
1775
1791
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1776
1792
  }
1793
+ if ((0, types_1.isTypeVar)(baseType)) {
1794
+ selfType = baseType;
1795
+ }
1777
1796
  if (classMemberInfo) {
1778
1797
  symbol = classMemberInfo.symbol;
1779
1798
  }
@@ -1814,11 +1833,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1814
1833
  }
1815
1834
  if (classOrObjectBase) {
1816
1835
  if (memberAccessClass && (0, types_1.isInstantiableClass)(memberAccessClass)) {
1817
- declaredType = (0, typeUtils_1.partiallySpecializeType)(declaredType, memberAccessClass, getTypeClassType());
1836
+ declaredType = (0, typeUtils_1.partiallySpecializeType)(declaredType, memberAccessClass, getTypeClassType(), selfType);
1818
1837
  }
1819
1838
  if ((0, types_1.isFunction)(declaredType) || (0, types_1.isOverloaded)(declaredType)) {
1820
1839
  if (bindFunction) {
1821
- declaredType = bindFunctionToClassOrObject(classOrObjectBase, declaredType);
1840
+ declaredType = bindFunctionToClassOrObject(classOrObjectBase, declaredType,
1841
+ /* memberClass */ undefined,
1842
+ /* treatConstructorAsClassMethod */ undefined, selfType);
1822
1843
  }
1823
1844
  }
1824
1845
  }
@@ -3236,17 +3257,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3236
3257
  }
3237
3258
  // If the value is a special form (like a TypeVar or `Any`) and is being
3238
3259
  // evaluated in a value expression context, convert it from its special
3239
- // meaning to its runtime value.
3240
- function convertSpecialFormToRuntimeValue(type, flags) {
3260
+ // meaning to its runtime value. If convertModule is true, a module is
3261
+ // converted to an instance of types.ModuleType.
3262
+ function convertSpecialFormToRuntimeValue(type, flags, convertModule = false) {
3241
3263
  var _a, _b, _c, _d;
3242
3264
  const exemptFlags = 256 /* EvalFlags.TypeExpression */ | 128 /* EvalFlags.InstantiableType */ | 33554432 /* EvalFlags.NoConvertSpecialForm */;
3243
3265
  if ((flags & exemptFlags) !== 0) {
3244
3266
  return type;
3245
3267
  }
3268
+ if (convertModule && (0, types_1.isModule)(type) && moduleTypeClass && (0, types_1.isInstantiableClass)(moduleTypeClass)) {
3269
+ return types_1.ClassType.cloneAsInstance(moduleTypeClass);
3270
+ }
3246
3271
  // Isinstance treats traditional (non-PEP 695) type aliases that are unions
3247
3272
  // as tuples of classes rather than unions.
3248
3273
  if ((flags & 536870912 /* EvalFlags.IsinstanceArg */) !== 0) {
3249
- if ((0, types_1.isUnion)(type) && ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) && !type.props.typeAliasInfo.isPep695Syntax) {
3274
+ if ((0, types_1.isUnion)(type) && ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) && !type.props.typeAliasInfo.shared.isPep695Syntax) {
3250
3275
  return type;
3251
3276
  }
3252
3277
  }
@@ -3594,7 +3619,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3594
3619
  }
3595
3620
  }
3596
3621
  return {
3597
- type: types_1.TypeVarType.cloneForScopeId(type, leftType.shared.recursiveAlias.scopeId, leftType.shared.recursiveAlias.name, 2 /* TypeVarScopeType.TypeAlias */),
3622
+ type: types_1.TypeVarType.cloneForScopeId(type, leftType.shared.recursiveAlias.typeVarScopeId, leftType.shared.recursiveAlias.name, 2 /* TypeVarScopeType.TypeAlias */),
3598
3623
  scopeNode,
3599
3624
  foundInterveningClass: false,
3600
3625
  };
@@ -4270,8 +4295,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4270
4295
  else {
4271
4296
  accessMethodName = '__delete__';
4272
4297
  }
4298
+ const subDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
4273
4299
  const methodTypeResult = getTypeOfBoundMember(errorNode, concreteMemberType, accessMethodName,
4274
- /* usage */ undefined, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */);
4300
+ /* usage */ undefined, subDiag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */);
4275
4301
  if (!methodTypeResult || methodTypeResult.typeErrors) {
4276
4302
  // Provide special error messages for properties.
4277
4303
  if (types_1.ClassType.isPropertyClass(concreteMemberType) && usage.method !== 'get') {
@@ -4287,6 +4313,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4287
4313
  const methodClassType = methodTypeResult.classType;
4288
4314
  let methodType = methodTypeResult.type;
4289
4315
  if (methodTypeResult.typeErrors || !methodClassType) {
4316
+ if (diag && subDiag) {
4317
+ diag.addAddendum(subDiag);
4318
+ }
4290
4319
  return { type: types_1.UnknownType.create(), typeErrors: true };
4291
4320
  }
4292
4321
  if (!(0, types_1.isFunction)(methodType) && !(0, types_1.isOverloaded)(methodType)) {
@@ -4804,13 +4833,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4804
4833
  return type;
4805
4834
  }
4806
4835
  // Is this a generic type alias that needs specializing?
4807
- if (!aliasInfo.typeParams || aliasInfo.typeParams.length === 0 || aliasInfo.typeArgs) {
4836
+ if (!aliasInfo.shared.typeParams || aliasInfo.shared.typeParams.length === 0 || aliasInfo.typeArgs) {
4808
4837
  return type;
4809
4838
  }
4810
4839
  let reportDiag = false;
4811
4840
  const defaultTypeArgs = [];
4812
4841
  const constraints = new constraintTracker_1.ConstraintTracker();
4813
- aliasInfo.typeParams.forEach((param) => {
4842
+ aliasInfo.shared.typeParams.forEach((param) => {
4814
4843
  if (!param.shared.isDefaultExplicit) {
4815
4844
  reportDiag = true;
4816
4845
  }
@@ -4818,7 +4847,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4818
4847
  if (param.shared.isDefaultExplicit || (0, types_1.isParamSpec)(param)) {
4819
4848
  defaultType = solveAndApplyConstraints(param, constraints, {
4820
4849
  replaceUnsolved: {
4821
- scopeIds: [aliasInfo.typeVarScopeId],
4850
+ scopeIds: [aliasInfo.shared.typeVarScopeId],
4822
4851
  tupleClassType: getTupleClassType(),
4823
4852
  },
4824
4853
  });
@@ -4835,12 +4864,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4835
4864
  });
4836
4865
  if (reportDiag && errorNode) {
4837
4866
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.typeArgsMissingForAlias().format({
4838
- name: aliasInfo.name,
4867
+ name: aliasInfo.shared.name,
4839
4868
  }), errorNode);
4840
4869
  }
4841
4870
  type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(type, constraints, {
4842
4871
  replaceUnsolved: {
4843
- scopeIds: [aliasInfo.typeVarScopeId],
4872
+ scopeIds: [aliasInfo.shared.typeVarScopeId],
4844
4873
  tupleClassType: getTupleClassType(),
4845
4874
  },
4846
4875
  }), { ...aliasInfo, typeArgs: defaultTypeArgs });
@@ -4856,7 +4885,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4856
4885
  aliasInfo = (_d = (_c = baseType.props.typeForm) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.typeAliasInfo;
4857
4886
  aliasBaseType = (0, typeUtils_1.convertToInstantiable)(baseType.props.typeForm);
4858
4887
  }
4859
- if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) || (aliasInfo.typeParams.length === 0 && aliasInfo.typeArgs)) {
4888
+ if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.shared.typeParams) || (aliasInfo.shared.typeParams.length === 0 && aliasInfo.typeArgs)) {
4860
4889
  return undefined;
4861
4890
  }
4862
4891
  // If this is not instantiable, then the index expression isn't a specialization.
@@ -4867,7 +4896,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4867
4896
  if (aliasInfo.typeArgs) {
4868
4897
  return undefined;
4869
4898
  }
4870
- const typeParams = aliasInfo.typeParams;
4899
+ inferVarianceForTypeAlias(baseType);
4900
+ const typeParams = aliasInfo.shared.typeParams;
4871
4901
  let typeArgs = adjustTypeArgsForTypeVarTuple(getTypeArgs(node, flags), typeParams, node);
4872
4902
  let reportedError = false;
4873
4903
  // PEP 612 says that if the class has only one type parameter consisting
@@ -4975,7 +5005,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4975
5005
  else if (param.shared.isDefaultExplicit) {
4976
5006
  typeArgType = solveAndApplyConstraints(param, constraints, {
4977
5007
  replaceUnsolved: {
4978
- scopeIds: [aliasInfo.typeVarScopeId],
5008
+ scopeIds: [aliasInfo.shared.typeVarScopeId],
4979
5009
  tupleClassType: getTupleClassType(),
4980
5010
  },
4981
5011
  });
@@ -5012,7 +5042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5012
5042
  }
5013
5043
  const solutionSet = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints).getMainSolutionSet();
5014
5044
  const aliasTypeArgs = [];
5015
- (_f = aliasInfo.typeParams) === null || _f === void 0 ? void 0 : _f.forEach((typeParam) => {
5045
+ (_f = aliasInfo.shared.typeParams) === null || _f === void 0 ? void 0 : _f.forEach((typeParam) => {
5016
5046
  let typeVarType = solutionSet.getType(typeParam);
5017
5047
  // Fill in any unsolved type arguments with unknown.
5018
5048
  if (!typeVarType) {
@@ -5051,7 +5081,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5051
5081
  types_1.ClassType.isBuiltIn(baseTypeResult.type, 'TypeAliasType') &&
5052
5082
  ((_b = baseTypeResult.type.props) === null || _b === void 0 ? void 0 : _b.typeForm)) {
5053
5083
  const typeAliasInfo = (_c = baseTypeResult.type.props.typeForm.props) === null || _c === void 0 ? void 0 : _c.typeAliasInfo;
5054
- if (typeAliasInfo && typeAliasInfo.typeParams) {
5084
+ if (typeAliasInfo && typeAliasInfo.shared.typeParams) {
5055
5085
  const origTypeAlias = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.convertToInstantiable)(baseTypeResult.type.props.typeForm), { ...typeAliasInfo, typeArgs: undefined });
5056
5086
  const typeFormType = createSpecializedTypeAlias(node, origTypeAlias, flags);
5057
5087
  if (typeFormType) {
@@ -5064,14 +5094,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5064
5094
  if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
5065
5095
  const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
5066
5096
  const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, {
5067
- name: baseTypeResult.type.shared.recursiveAlias.name,
5068
- fullName: '',
5069
- moduleName: '',
5070
- fileUri: uri_1.Uri.empty(),
5071
- typeVarScopeId: baseTypeResult.type.shared.recursiveAlias.scopeId,
5072
- isPep695Syntax: !!baseTypeResult.type.shared.recursiveAlias.isPep695Syntax,
5073
- typeParams: baseTypeResult.type.shared.recursiveAlias.typeParams,
5074
- usageVariance: undefined,
5097
+ shared: baseTypeResult.type.shared.recursiveAlias,
5075
5098
  typeArgs: typeArgTypes,
5076
5099
  });
5077
5100
  return { type };
@@ -5239,31 +5262,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5239
5262
  var _a;
5240
5263
  const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
5241
5264
  // If this isn't a generic type alias, there's nothing to do.
5242
- if (!aliasInfo || !aliasInfo.typeParams) {
5265
+ if (!aliasInfo || !aliasInfo.shared.typeParams) {
5243
5266
  return undefined;
5244
5267
  }
5245
- // Is the usage variance info already cached?
5246
- if (aliasInfo.usageVariance) {
5247
- return aliasInfo.usageVariance;
5268
+ // Is the computed variance info already cached?
5269
+ if (aliasInfo.shared.computedVariance) {
5270
+ return aliasInfo.shared.computedVariance;
5248
5271
  }
5249
- const typeParams = aliasInfo.typeParams;
5272
+ const typeParams = aliasInfo.shared.typeParams;
5250
5273
  // Start with all of the usage variances unknown.
5251
5274
  const usageVariances = typeParams.map(() => 1 /* Variance.Unknown */);
5252
5275
  // Prepopulate the cached value for the type alias to handle
5253
5276
  // recursive type aliases.
5254
- aliasInfo.usageVariance = usageVariances;
5277
+ aliasInfo.shared.computedVariance = usageVariances;
5255
5278
  // Traverse the type alias type definition and adjust the usage
5256
5279
  // variances accordingly.
5257
- updateUsageVariancesRecursive(type, typeParams, usageVariances);
5280
+ updateUsageVariancesRecursive(type, typeParams, usageVariances, 3 /* Variance.Covariant */);
5258
5281
  return usageVariances;
5259
5282
  }
5260
5283
  // Looks at uses of the type parameters within the type and adjusts the
5261
5284
  // variances accordingly. For example, if the type is `Mapping[T1, T2]`,
5262
5285
  // then T1 will be set to invariant and T2 will be set to covariant.
5263
- function updateUsageVariancesRecursive(type, typeAliasTypeParams, usageVariances, recursionCount = 0) {
5286
+ function updateUsageVariancesRecursive(type, typeAliasTypeParams, usageVariances, varianceContext, recursionCount = 0) {
5264
5287
  if (recursionCount > types_1.maxTypeRecursionCount) {
5265
5288
  return;
5266
5289
  }
5290
+ const transformedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
5291
+ // If this is a recursive type alias, use a lower recursion limit.
5292
+ if (transformedType !== type) {
5293
+ if (recursionCount > maxRecursiveTypeAliasRecursionCount) {
5294
+ return;
5295
+ }
5296
+ }
5267
5297
  recursionCount++;
5268
5298
  // Define a helper function that performs the actual usage variant update.
5269
5299
  function updateUsageVarianceForType(type, variance) {
@@ -5273,20 +5303,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5273
5303
  usageVariances[typeParamIndex] = (0, typeUtils_1.combineVariances)(usageVariances[typeParamIndex], variance);
5274
5304
  }
5275
5305
  else {
5276
- updateUsageVariancesRecursive(subtype, typeAliasTypeParams, usageVariances, recursionCount);
5306
+ updateUsageVariancesRecursive(subtype, typeAliasTypeParams, usageVariances, variance, recursionCount);
5277
5307
  }
5278
5308
  });
5279
5309
  }
5280
- (0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
5310
+ (0, typeUtils_1.doForEachSubtype)(transformedType, (subtype) => {
5281
5311
  if (subtype.category === 4 /* TypeCategory.Function */) {
5282
- if (subtype.priv.specializedTypes) {
5283
- subtype.priv.specializedTypes.parameterTypes.forEach((paramType) => {
5284
- updateUsageVarianceForType(paramType, 4 /* Variance.Contravariant */);
5285
- });
5286
- const returnType = subtype.priv.specializedTypes.returnType;
5287
- if (returnType) {
5288
- updateUsageVarianceForType(returnType, 3 /* Variance.Covariant */);
5289
- }
5312
+ subtype.shared.parameters.forEach((param, index) => {
5313
+ const paramType = types_1.FunctionType.getParamType(subtype, index);
5314
+ updateUsageVarianceForType(paramType, (0, typeUtils_1.invertVariance)(varianceContext));
5315
+ });
5316
+ const returnType = types_1.FunctionType.getEffectiveReturnType(subtype);
5317
+ if (returnType) {
5318
+ updateUsageVarianceForType(returnType, varianceContext);
5290
5319
  }
5291
5320
  }
5292
5321
  else if (subtype.category === 6 /* TypeCategory.Class */) {
@@ -5299,7 +5328,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5299
5328
  subtype.priv.typeArgs.forEach((typeArg, classParamIndex) => {
5300
5329
  var _a;
5301
5330
  if ((0, typeUtils_1.isTupleClass)(subtype)) {
5302
- updateUsageVarianceForType(typeArg, 3 /* Variance.Covariant */);
5331
+ updateUsageVarianceForType(typeArg, varianceContext);
5303
5332
  }
5304
5333
  else if (classParamIndex < subtype.shared.typeParams.length) {
5305
5334
  const classTypeParam = subtype.shared.typeParams[classParamIndex];
@@ -5309,7 +5338,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5309
5338
  });
5310
5339
  }
5311
5340
  else {
5312
- updateUsageVarianceForType(typeArg, (_a = classTypeParam.priv.computedVariance) !== null && _a !== void 0 ? _a : classTypeParam.shared.declaredVariance);
5341
+ const effectiveVariance = (_a = classTypeParam.priv.computedVariance) !== null && _a !== void 0 ? _a : classTypeParam.shared.declaredVariance;
5342
+ updateUsageVarianceForType(typeArg, varianceContext === 4 /* Variance.Contravariant */
5343
+ ? (0, typeUtils_1.invertVariance)(effectiveVariance)
5344
+ : effectiveVariance);
5313
5345
  }
5314
5346
  }
5315
5347
  });
@@ -5786,7 +5818,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5786
5818
  entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
5787
5819
  }
5788
5820
  else {
5789
- let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */);
5821
+ let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */,
5822
+ /* convertModule */ true);
5790
5823
  entryType = stripLiterals ? (0, typeUtils_1.stripTypeForm)(stripLiteralValue(entryType)) : entryType;
5791
5824
  entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
5792
5825
  }
@@ -6403,7 +6436,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6403
6436
  }
6404
6437
  // Clone the constraints so we don't modify the original.
6405
6438
  const effectiveConstraints = (_a = constraints === null || constraints === void 0 ? void 0 : constraints.clone()) !== null && _a !== void 0 ? _a : new constraintTracker_1.ConstraintTracker();
6406
- effectiveConstraints.unlock();
6407
6439
  // Use speculative mode so we don't output any diagnostics or
6408
6440
  // record any final types in the type cache.
6409
6441
  const callResult = useSpeculativeMode(speculativeNode, () => {
@@ -6515,7 +6547,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6515
6547
  // And run through the first expanded argument list one more time to
6516
6548
  // populate the type cache.
6517
6549
  const finalConstraints = constraints !== null && constraints !== void 0 ? constraints : matchedOverloads[0].constraints;
6518
- finalConstraints.unlock();
6519
6550
  const finalCallResult = validateArgTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalConstraints, skipUnknownArgCheck, inferenceContext);
6520
6551
  if (finalCallResult.isTypeIncomplete) {
6521
6552
  isTypeIncomplete = true;
@@ -6689,7 +6720,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6689
6720
  }
6690
6721
  }
6691
6722
  const effectiveConstraints = constraints !== null && constraints !== void 0 ? constraints : new constraintTracker_1.ConstraintTracker();
6692
- effectiveConstraints.unlock();
6693
6723
  return validateArgTypesWithContext(errorNode, bestMatch, effectiveConstraints, skipUnknownArgCheck, inferenceContext);
6694
6724
  }
6695
6725
  // If there is only one possible arg/param match among the overloads,
@@ -7083,7 +7113,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7083
7113
  // The one-parameter form of "type" returns the class
7084
7114
  // for the specified object.
7085
7115
  if (expandedCallType.shared.name === 'type' && argList.length === 1) {
7086
- const argType = getTypeOfArg(argList[0], /* inferenceContext */ undefined).type;
7116
+ const argTypeResult = getTypeOfArg(argList[0], /* inferenceContext */ undefined);
7117
+ const argType = argTypeResult.type;
7087
7118
  const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
7088
7119
  if ((0, types_1.isNever)(subtype)) {
7089
7120
  return subtype;
@@ -7100,7 +7131,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7100
7131
  types_1.UnknownType.create(),
7101
7132
  ]);
7102
7133
  });
7103
- return { returnType };
7134
+ return { returnType, isTypeIncomplete: argTypeResult.isIncomplete };
7104
7135
  }
7105
7136
  if (argList.length >= 2) {
7106
7137
  // The two-parameter form of a call to a metaclass returns a new class
@@ -7364,11 +7395,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7364
7395
  paramDetails.params.forEach((paramInfo) => {
7365
7396
  (0, debug_1.assert)(paramInfo !== undefined, 'paramInfo is undefined for param name map');
7366
7397
  const param = paramInfo.param;
7367
- if (param.name && param.category === 0 /* ParamCategory.Simple */) {
7398
+ if (param.name && param.category === 0 /* ParamCategory.Simple */ && paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
7368
7399
  paramMap.set(param.name, {
7369
7400
  argsNeeded: param.category === 0 /* ParamCategory.Simple */ && !paramInfo.defaultType ? 1 : 0,
7370
7401
  argsReceived: 0,
7371
- isPositionalOnly: paramInfo.kind === parameterUtils_1.ParamKind.Positional,
7372
7402
  });
7373
7403
  }
7374
7404
  });
@@ -7680,19 +7710,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7680
7710
  }
7681
7711
  }
7682
7712
  else {
7683
- const paramName = paramDetails.params[paramIndex].param.name;
7713
+ const paramInfo = paramDetails.params[paramIndex];
7714
+ const paramName = paramInfo.param.name;
7684
7715
  validateArgTypeParams.push({
7685
- paramCategory: paramDetails.params[paramIndex].param.category,
7716
+ paramCategory: paramInfo.param.category,
7686
7717
  paramType,
7687
7718
  requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
7688
7719
  argument: argList[argIndex],
7689
7720
  errorNode: argList[argIndex].valueExpression || errorNode,
7690
7721
  paramName,
7691
- isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(paramDetails.params[paramIndex].param),
7722
+ isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(paramInfo.param),
7692
7723
  });
7693
- trySetActive(argList[argIndex], paramDetails.params[paramIndex].param);
7724
+ trySetActive(argList[argIndex], paramInfo.param);
7694
7725
  // Note that the parameter has received an argument.
7695
- if (paramName && paramMap.has(paramName)) {
7726
+ if (paramName && paramMap.has(paramName) && paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
7696
7727
  paramMap.get(paramName).argsReceived++;
7697
7728
  }
7698
7729
  argIndex++;
@@ -7770,7 +7801,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7770
7801
  tdEntries.knownItems.forEach((entry, name) => {
7771
7802
  var _a, _b;
7772
7803
  const paramEntry = paramMap.get(name);
7773
- if (paramEntry && !paramEntry.isPositionalOnly) {
7804
+ if (paramEntry) {
7774
7805
  if (paramEntry.argsReceived > 0) {
7775
7806
  diag.addMessage(localize_1.LocMessage.paramAlreadyAssigned().format({ name }));
7776
7807
  }
@@ -7809,7 +7840,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7809
7840
  paramMap.set(name, {
7810
7841
  argsNeeded: 1,
7811
7842
  argsReceived: 1,
7812
- isPositionalOnly: false,
7813
7843
  });
7814
7844
  }
7815
7845
  else {
@@ -7928,7 +7958,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7928
7958
  if (paramName) {
7929
7959
  const paramNameValue = paramName.d.value;
7930
7960
  const paramEntry = paramMap.get(paramNameValue);
7931
- if (paramEntry && !paramEntry.isPositionalOnly) {
7961
+ if (paramEntry) {
7932
7962
  if (paramEntry.argsReceived > 0) {
7933
7963
  if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7934
7964
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramAlreadyAssigned().format({ name: paramNameValue }), paramName);
@@ -7937,7 +7967,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7937
7967
  }
7938
7968
  else {
7939
7969
  paramEntry.argsReceived++;
7940
- const paramInfoIndex = paramDetails.params.findIndex((paramInfo) => paramInfo.param.name === paramNameValue);
7970
+ const paramInfoIndex = paramDetails.params.findIndex((paramInfo) => paramInfo.param.name === paramNameValue &&
7971
+ paramInfo.kind !== parameterUtils_1.ParamKind.Positional);
7941
7972
  (0, debug_1.assert)(paramInfoIndex >= 0);
7942
7973
  const paramType = paramDetails.params[paramInfoIndex].type;
7943
7974
  validateArgTypeParams.push({
@@ -7975,7 +8006,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7975
8006
  paramMap.set(paramNameValue, {
7976
8007
  argsNeeded: 1,
7977
8008
  argsReceived: 1,
7978
- isPositionalOnly: false,
7979
8009
  });
7980
8010
  (0, debug_1.assert)(paramDetails.params[paramDetails.kwargsIndex], 'paramDetails.kwargsIndex params entry is undefined');
7981
8011
  }
@@ -8089,7 +8119,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8089
8119
  const param = paramInfo.param;
8090
8120
  if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
8091
8121
  const entry = paramMap.get(param.name);
8092
- if (entry.argsNeeded === 0 && entry.argsReceived === 0) {
8122
+ if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0) {
8093
8123
  const defaultArgType = paramInfo.defaultType;
8094
8124
  if (defaultArgType &&
8095
8125
  !(0, typeUtils_1.isEllipsisType)(defaultArgType) &&
@@ -8391,9 +8421,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8391
8421
  });
8392
8422
  });
8393
8423
  }
8394
- // Lock the type var map so it cannot be modified when revalidating
8395
- // the arguments in a second pass.
8396
- constraints.lock();
8397
8424
  }
8398
8425
  let sawParamSpecArgs = false;
8399
8426
  let sawParamSpecKwargs = false;
@@ -9697,8 +9724,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9697
9724
  typeErrors = true;
9698
9725
  }
9699
9726
  // Strip any literal values and TypeForm types.
9700
- const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags)));
9701
- const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags)));
9727
+ const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, /* convertModule */ true)));
9728
+ const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, /* convertModule */ true)));
9702
9729
  keyType = keyTypes.length > 0 ? (0, types_1.combineTypes)(keyTypes) : fallbackType;
9703
9730
  // If the value type differs and we're not using "strict inference mode",
9704
9731
  // we need to back off because we can't properly represent the mappings
@@ -10049,7 +10076,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10049
10076
  else {
10050
10077
  entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
10051
10078
  }
10052
- entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags));
10079
+ entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags, /* convertModule */ true));
10053
10080
  if (entryTypeResult.isIncomplete) {
10054
10081
  isIncomplete = true;
10055
10082
  }
@@ -11433,7 +11460,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11433
11460
  }
11434
11461
  return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
11435
11462
  }
11436
- function transformTypeForTypeAlias(type, name, errorNode, isPep695Syntax, isPep695TypeVarType, typeParams, typeParamNodes) {
11463
+ function transformTypeForTypeAlias(type, errorNode, typeAliasPlaceholder, isPep695TypeVarType, typeParamNodes) {
11437
11464
  var _a;
11438
11465
  if (!types_1.TypeBase.isInstantiable(type)) {
11439
11466
  return type;
@@ -11443,6 +11470,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11443
11470
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
11444
11471
  return type;
11445
11472
  }
11473
+ const sharedInfo = typeAliasPlaceholder.shared.recursiveAlias;
11474
+ (0, debug_1.assert)(sharedInfo !== undefined);
11475
+ let typeParams = sharedInfo.typeParams;
11446
11476
  if (!typeParams) {
11447
11477
  // Determine if there are any generic type parameters associated
11448
11478
  // with this type alias.
@@ -11467,10 +11497,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11467
11497
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithDefaultFollowsVariadic().format({
11468
11498
  typeVarName: typeParams[typeVarWithDefaultIndex].shared.name,
11469
11499
  variadicName: typeParams[firstTypeVarTupleIndex].shared.name,
11470
- }), typeParamNodes ? typeParamNodes[typeVarWithDefaultIndex].d.name : name);
11500
+ }), typeParamNodes ? typeParamNodes[typeVarWithDefaultIndex].d.name : errorNode);
11471
11501
  }
11472
11502
  }
11473
- const typeAliasScopeId = ParseTreeUtils.getScopeIdForNode(name);
11474
11503
  // Validate the default types for all type parameters.
11475
11504
  typeParams.forEach((typeParam, index) => {
11476
11505
  var _a;
@@ -11479,7 +11508,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11479
11508
  if (typeParamNodes && index < typeParamNodes.length) {
11480
11509
  bestErrorNode = (_a = typeParamNodes[index].d.defaultExpr) !== null && _a !== void 0 ? _a : typeParamNodes[index].d.name;
11481
11510
  }
11482
- validateTypeParamDefault(bestErrorNode, typeParam, typeParams.slice(0, index), typeAliasScopeId);
11511
+ validateTypeParamDefault(bestErrorNode, typeParam, typeParams.slice(0, index), sharedInfo.typeVarScopeId);
11483
11512
  });
11484
11513
  // Verify that we have at most one TypeVarTuple.
11485
11514
  const variadics = typeParams.filter((param) => (0, types_1.isTypeVarTuple)(param));
@@ -11488,29 +11517,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11488
11517
  names: variadics.map((v) => `"${v.shared.name}"`).join(', '),
11489
11518
  }), errorNode);
11490
11519
  }
11491
- if (!isPep695Syntax && !isPep695TypeVarType) {
11492
- const boundTypeVars = typeParams.filter((typeVar) => typeVar.priv.scopeId !== typeAliasScopeId && typeVar.priv.scopeType === 0 /* TypeVarScopeType.Class */);
11520
+ if (!sharedInfo.isPep695Syntax && !isPep695TypeVarType) {
11521
+ const boundTypeVars = typeParams.filter((typeVar) => typeVar.priv.scopeId !== sharedInfo.typeVarScopeId &&
11522
+ typeVar.priv.scopeType === 0 /* TypeVarScopeType.Class */);
11493
11523
  if (boundTypeVars.length > 0) {
11494
11524
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.genericTypeAliasBoundTypeVar().format({
11495
11525
  names: boundTypeVars.map((t) => `${t.shared.name}`).join(', '),
11496
11526
  }), errorNode);
11497
11527
  }
11498
11528
  }
11499
- const fileInfo = AnalyzerNodeInfo.getFileInfo(name);
11529
+ sharedInfo.typeParams = typeParams.length > 0 ? typeParams : undefined;
11500
11530
  let typeAlias = types_1.TypeBase.cloneForTypeAlias(type, {
11501
- name: name.d.value,
11502
- fullName: ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.d.value),
11503
- moduleName: fileInfo.moduleName,
11504
- fileUri: fileInfo.fileUri,
11505
- typeVarScopeId: typeAliasScopeId,
11506
- isPep695Syntax,
11507
- typeParams: typeParams.length > 0 ? typeParams : undefined,
11508
- usageVariance: undefined,
11531
+ shared: sharedInfo,
11509
11532
  typeArgs: undefined,
11510
11533
  });
11511
11534
  // All PEP 695 type aliases are special forms because they are
11512
11535
  // TypeAliasType objects at runtime.
11513
- if (isPep695Syntax || isPep695TypeVarType) {
11536
+ if (sharedInfo.isPep695Syntax || isPep695TypeVarType) {
11514
11537
  const typeAliasTypeClass = getTypingType(errorNode, 'TypeAliasType');
11515
11538
  if (typeAliasTypeClass && (0, types_1.isInstantiableClass)(typeAliasTypeClass)) {
11516
11539
  typeAlias = types_1.TypeBase.cloneAsSpecialForm(typeAlias, types_1.ClassType.cloneAsInstance(typeAliasTypeClass));
@@ -11641,7 +11664,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11641
11664
  typeParamVariance: 2 /* Variance.Invariant */,
11642
11665
  },
11643
11666
  ],
11644
- ['TypeForm', { alias: '', module: 'builtins', isSpecialForm: true, typeParamVariance: 3 /* Variance.Covariant */ }],
11667
+ [
11668
+ 'TypeForm',
11669
+ {
11670
+ alias: '',
11671
+ module: 'builtins',
11672
+ isSpecialForm: true,
11673
+ typeParamVariance: 3 /* Variance.Covariant */,
11674
+ isIllegalInIsinstance: true,
11675
+ },
11676
+ ],
11645
11677
  ]);
11646
11678
  const aliasMapEntry = specialTypes.get(assignedName);
11647
11679
  if (aliasMapEntry) {
@@ -11780,7 +11812,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11780
11812
  }
11781
11813
  }
11782
11814
  if (typeAliasNameNode) {
11783
- typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode);
11815
+ typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode, /* isPep695Syntax */ false);
11784
11816
  writeTypeCache(node, { type: typeAliasPlaceholder }, /* flags */ undefined);
11785
11817
  writeTypeCache(node.d.leftExpr, { type: typeAliasPlaceholder }, /* flags */ undefined);
11786
11818
  if (node.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
@@ -11801,8 +11833,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11801
11833
  if (typeAliasNameNode) {
11802
11834
  (0, debug_1.assert)(typeAliasPlaceholder !== undefined);
11803
11835
  // If this is a type alias, record its name based on the assignment target.
11804
- rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, typeAliasNameNode,
11805
- /* isPep695Syntax */ false,
11836
+ rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, typeAliasPlaceholder,
11806
11837
  /* isPep695TypeVarType */ false);
11807
11838
  if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasPlaceholder, rightHandType)) {
11808
11839
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
@@ -11815,7 +11846,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11815
11846
  typeAliasPlaceholder.shared.boundType = rightHandType;
11816
11847
  // Record the type parameters within the recursive type alias so it
11817
11848
  // can be specialized.
11818
- typeAliasPlaceholder.shared.recursiveAlias.typeParams = (_b = (_a = rightHandType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.typeParams;
11849
+ typeAliasPlaceholder.shared.recursiveAlias.typeParams =
11850
+ (_b = (_a = rightHandType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.shared.typeParams;
11819
11851
  }
11820
11852
  else {
11821
11853
  // If the RHS is a constant boolean expression, assign it a literal type.
@@ -11835,17 +11867,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11835
11867
  }
11836
11868
  // Synthesize a TypeVar that acts as a placeholder for a type alias. This allows
11837
11869
  // the type alias definition to refer to itself.
11838
- function synthesizeTypeAliasPlaceholder(nameNode) {
11870
+ function synthesizeTypeAliasPlaceholder(nameNode, isPep695Syntax) {
11839
11871
  const placeholder = types_1.TypeVarType.createInstantiable(`__type_alias_${nameNode.d.value}`);
11840
11872
  placeholder.shared.isSynthesized = true;
11841
- const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
11873
+ const typeVarScopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
11874
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(nameNode);
11842
11875
  placeholder.shared.recursiveAlias = {
11843
11876
  name: nameNode.d.value,
11844
- scopeId,
11845
- isPep695Syntax: false,
11877
+ fullName: ParseTreeUtils.getClassFullName(nameNode, fileInfo.moduleName, nameNode.d.value),
11878
+ moduleName: fileInfo.moduleName,
11879
+ fileUri: fileInfo.fileUri,
11880
+ typeVarScopeId,
11881
+ isPep695Syntax,
11846
11882
  typeParams: undefined,
11883
+ computedVariance: undefined,
11847
11884
  };
11848
- placeholder.priv.scopeId = scopeId;
11885
+ placeholder.priv.scopeId = typeVarScopeId;
11849
11886
  return placeholder;
11850
11887
  }
11851
11888
  // Evaluates the type of a type alias (i.e. "type") statement. This code
@@ -11870,7 +11907,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11870
11907
  }
11871
11908
  // Synthesize a type variable that represents the type alias while we're
11872
11909
  // evaluating it. This allows us to handle recursive definitions.
11873
- const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(nameNode);
11910
+ const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(nameNode, isPep695Syntax);
11874
11911
  // Write the type to the type cache to support recursive type alias definitions.
11875
11912
  writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
11876
11913
  // Set a partial type to handle recursive (self-referential) type aliases.
@@ -11893,8 +11930,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11893
11930
  if (aliasTypeResult.isIncomplete) {
11894
11931
  isIncomplete = true;
11895
11932
  }
11896
- aliasType = transformTypeForTypeAlias(aliasType, nameNode, nameNode, isPep695Syntax,
11897
- /* isPep695TypeVarType */ true, typeParams, typeParamNodes);
11933
+ aliasType = transformTypeForTypeAlias(aliasType, nameNode, typeAliasTypeVar,
11934
+ /* isPep695TypeVarType */ true, typeParamNodes);
11898
11935
  // See if the type alias relies on itself in a way that cannot be resolved.
11899
11936
  if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
11900
11937
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
@@ -11922,6 +11959,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11922
11959
  function createSubclass(errorNode, type1, type2) {
11923
11960
  var _a, _b;
11924
11961
  (0, debug_1.assert)((0, types_1.isInstantiableClass)(type1) && (0, types_1.isInstantiableClass)(type2));
11962
+ // If both classes are class objects (type[A] and type[B]), create a new
11963
+ // class object (type[A & B]) rather than "type[A] & type[B]".
11964
+ let createClassObject = false;
11965
+ if (types_1.TypeBase.getInstantiableDepth(type1) > 0 && types_1.TypeBase.getInstantiableDepth(type2) > 0) {
11966
+ type1 = types_1.ClassType.cloneAsInstance(type1);
11967
+ type2 = types_1.ClassType.cloneAsInstance(type2);
11968
+ createClassObject = true;
11969
+ }
11925
11970
  const className = `<subclass of ${printType((0, typeUtils_1.convertToInstance)(type1), {
11926
11971
  omitTypeArgsIfUnknown: true,
11927
11972
  })} and ${printType((0, typeUtils_1.convertToInstance)(type2), { omitTypeArgsIfUnknown: true })}>`;
@@ -11939,6 +11984,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11939
11984
  (0, typeUtils_1.computeMroLinearization)(newClassType);
11940
11985
  newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_a = type1.props) === null || _a === void 0 ? void 0 : _a.condition);
11941
11986
  newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_b = type2.props) === null || _b === void 0 ? void 0 : _b.condition);
11987
+ if (createClassObject) {
11988
+ newClassType = types_1.ClassType.cloneAsInstantiable(newClassType);
11989
+ }
11942
11990
  return newClassType;
11943
11991
  }
11944
11992
  function getTypeOfClass(node) {
@@ -12780,7 +12828,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12780
12828
  const paramMap = new Map();
12781
12829
  for (let i = paramListDetails.firstKeywordOnlyIndex; i < paramListDetails.params.length; i++) {
12782
12830
  const paramInfo = paramListDetails.params[i];
12783
- if (paramInfo.param.category === 0 /* ParamCategory.Simple */ && paramInfo.param.name) {
12831
+ if (paramInfo.param.category === 0 /* ParamCategory.Simple */ &&
12832
+ paramInfo.param.name &&
12833
+ paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
12784
12834
  paramMap.set(paramInfo.param.name, i);
12785
12835
  }
12786
12836
  }
@@ -13384,7 +13434,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13384
13434
  skipInference = true;
13385
13435
  }
13386
13436
  if (!skipInference) {
13387
- inferredParamType = convertSpecialFormToRuntimeValue(defaultValueType, 0 /* EvalFlags.None */);
13437
+ inferredParamType = convertSpecialFormToRuntimeValue(defaultValueType, 0 /* EvalFlags.None */,
13438
+ /* convertModule */ true);
13388
13439
  inferredParamType = (0, typeUtils_1.stripTypeForm)(inferredParamType);
13389
13440
  inferredParamType = stripLiteralValue(inferredParamType);
13390
13441
  }
@@ -14373,7 +14424,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14373
14424
  const typeAnnotation = ParseTreeUtils.getTypeAnnotationForParam(functionNode, paramIndex);
14374
14425
  if (typeAnnotation) {
14375
14426
  const param = functionNode.d.params[paramIndex];
14376
- const annotatedType = getTypeOfParamAnnotation(typeAnnotation, functionNode.d.params[paramIndex].d.category);
14427
+ let annotatedType = getTypeOfParamAnnotation(typeAnnotation, functionNode.d.params[paramIndex].d.category);
14428
+ const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(param);
14429
+ annotatedType = (0, typeUtils_1.makeTypeVarsBound)(annotatedType, liveTypeVarScopes);
14377
14430
  const adjType = transformVariadicParamType(node, node.d.category, adjustParamAnnotatedType(param, annotatedType));
14378
14431
  writeTypeCache(node.d.name, { type: adjType }, 0 /* EvalFlags.None */);
14379
14432
  return;
@@ -15420,7 +15473,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15420
15473
  else {
15421
15474
  const synthesizedType = symbol.getSynthesizedType();
15422
15475
  if (synthesizedType) {
15423
- synthesizedTypes.push(synthesizedType);
15476
+ synthesizedTypes.push({ type: synthesizedType, node });
15424
15477
  }
15425
15478
  else {
15426
15479
  (0, collectionUtils_1.appendArray)(declarations, symbol.getDeclarations());
@@ -15509,7 +15562,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15509
15562
  return { decls: declarations, synthesizedTypes };
15510
15563
  }
15511
15564
  function getTypeForDeclaration(declaration) {
15512
- var _a, _b;
15565
+ var _a, _b, _c;
15513
15566
  switch (declaration.type) {
15514
15567
  case 0 /* DeclarationType.Intrinsic */: {
15515
15568
  if (declaration.intrinsicType === 'Any') {
@@ -15570,12 +15623,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15570
15623
  return { type: getTypeOfTypeAlias(declaration.node) };
15571
15624
  }
15572
15625
  case 2 /* DeclarationType.Param */: {
15573
- let typeAnnotationNode = declaration.node.d.annotation || declaration.node.d.annotationComment;
15626
+ let typeAnnotationNode = (_a = declaration.node.d.annotation) !== null && _a !== void 0 ? _a : declaration.node.d.annotationComment;
15574
15627
  // If there wasn't an annotation, see if the parent function
15575
15628
  // has a function-level annotation comment that provides
15576
15629
  // this parameter's annotation type.
15577
15630
  if (!typeAnnotationNode) {
15578
- if (((_a = declaration.node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 31 /* ParseNodeType.Function */) {
15631
+ if (((_b = declaration.node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 31 /* ParseNodeType.Function */) {
15579
15632
  const functionNode = declaration.node.parent;
15580
15633
  if (functionNode.d.funcAnnotationComment &&
15581
15634
  !functionNode.d.funcAnnotationComment.d.isEllipsis) {
@@ -15609,7 +15662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15609
15662
  }
15610
15663
  else {
15611
15664
  const declNode = declaration.isDefinedByMemberAccess &&
15612
- ((_b = declaration.node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 35 /* ParseNodeType.MemberAccess */
15665
+ ((_c = declaration.node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 35 /* ParseNodeType.MemberAccess */
15613
15666
  ? declaration.node.parent
15614
15667
  : declaration.node;
15615
15668
  declaredType = getTypeOfAnnotation(typeAnnotationNode, {
@@ -15768,6 +15821,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15768
15821
  else {
15769
15822
  (0, debug_1.assert)(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */);
15770
15823
  scopeType = 2 /* TypeVarScopeType.TypeAlias */;
15824
+ typeVar.shared.declaredVariance = 0 /* Variance.Auto */;
15771
15825
  }
15772
15826
  typeVar = types_1.TypeVarType.cloneForScopeId(typeVar, ParseTreeUtils.getScopeIdForNode(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */ ? scopeNode.d.name : scopeNode), scopeNode.d.name.d.value, scopeType);
15773
15827
  }
@@ -15904,8 +15958,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15904
15958
  // in the event that its inferred type is instantiable or explicitly Any
15905
15959
  // (but not an ellipsis).
15906
15960
  if (isLegalImplicitTypeAliasType(inferredType)) {
15907
- inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node,
15908
- /* isPep695Syntax */ false,
15961
+ const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(resolvedDecl.typeAliasName,
15962
+ /* isPep695Syntax */ false);
15963
+ inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.node, typeAliasTypeVar,
15909
15964
  /* isPep695TypeVarType */ false);
15910
15965
  isUnambiguousType = true;
15911
15966
  }
@@ -16033,7 +16088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16033
16088
  includesVariableDecl: includesVariableTypeDecl(typedDecls),
16034
16089
  includesIllegalTypeAliasDecl: !typedDecls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
16035
16090
  includesSpeculativeResult: false,
16036
- isRecursiveDefinition: !declaredType,
16091
+ isRecursiveDefinition: !declaredType && !speculativeTypeTracker.isSpeculative(/* node */ undefined),
16037
16092
  };
16038
16093
  return result;
16039
16094
  }
@@ -16572,7 +16627,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16572
16627
  paramType = types_1.UnknownType.create();
16573
16628
  }
16574
16629
  if (stripLiteralArgTypes) {
16575
- paramType = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(paramType), 0 /* EvalFlags.None */));
16630
+ paramType = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(paramType), 0 /* EvalFlags.None */,
16631
+ /* convertModule */ true));
16576
16632
  }
16577
16633
  paramTypes.push(paramType);
16578
16634
  writeTypeCache(param.d.name, { type: paramType }, 0 /* EvalFlags.None */);
@@ -16979,7 +17035,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16979
17035
  // in this case. Adding more information is unnecessary and confusing.
16980
17036
  (flags & 1 /* AssignTypeFlags.Invariant */) === 0 ? diag : undefined, constraints, flags, recursionCount);
16981
17037
  }
16982
- if (constraints && curSrcType.priv.typeArgs && !constraints.isLocked()) {
17038
+ if (constraints && curSrcType.priv.typeArgs) {
16983
17039
  // Populate the typeVar map with type arguments of the source.
16984
17040
  const srcTypeArgs = curSrcType.priv.typeArgs;
16985
17041
  for (let i = 0; i < destType.shared.typeParams.length; i++) {
@@ -17151,16 +17207,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17151
17207
  // Do the source and dest refer to the same recursive type alias?
17152
17208
  if ((destAliasInfo === null || destAliasInfo === void 0 ? void 0 : destAliasInfo.typeArgs) &&
17153
17209
  (srcAliasInfo === null || srcAliasInfo === void 0 ? void 0 : srcAliasInfo.typeArgs) &&
17154
- destType.shared.recursiveAlias.scopeId === srcType.shared.recursiveAlias.scopeId) {
17155
- let isAssignable = true;
17156
- const srcTypeArgs = srcAliasInfo.typeArgs;
17157
- destAliasInfo.typeArgs.forEach((destTypeArg, index) => {
17158
- const srcTypeArg = index < srcTypeArgs.length ? srcTypeArgs[index] : types_1.UnknownType.create();
17159
- if (!assignType(destTypeArg, srcTypeArg, diag, constraints, flags, recursionCount)) {
17160
- isAssignable = false;
17161
- }
17162
- });
17163
- return isAssignable;
17210
+ destType.shared.recursiveAlias.typeVarScopeId === srcType.shared.recursiveAlias.typeVarScopeId) {
17211
+ return assignRecursiveTypeAliasToSelf(destAliasInfo, srcAliasInfo, diag, constraints, flags, recursionCount);
17164
17212
  }
17165
17213
  else {
17166
17214
  // Have we already recursed once?
@@ -17676,6 +17724,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17676
17724
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
17677
17725
  return false;
17678
17726
  }
17727
+ // Determines whether a recursive type alias can be assigned to itself
17728
+ // given the source and dest type args and computed variance for its
17729
+ // type params.
17730
+ function assignRecursiveTypeAliasToSelf(destAliasInfo, srcAliasInfo, diag, constraints, flags = 0 /* AssignTypeFlags.Default */, recursionCount = 0) {
17731
+ (0, debug_1.assert)(destAliasInfo.typeArgs !== undefined);
17732
+ (0, debug_1.assert)(srcAliasInfo.typeArgs !== undefined);
17733
+ let isAssignable = true;
17734
+ const srcTypeArgs = srcAliasInfo.typeArgs;
17735
+ const variances = destAliasInfo.shared.computedVariance;
17736
+ destAliasInfo.typeArgs.forEach((destTypeArg, index) => {
17737
+ const srcTypeArg = index < srcTypeArgs.length ? srcTypeArgs[index] : types_1.UnknownType.create();
17738
+ let adjFlags = flags;
17739
+ const variance = variances && index < variances.length ? variances[index] : 3 /* Variance.Covariant */;
17740
+ if (variance === 2 /* Variance.Invariant */) {
17741
+ adjFlags |= 1 /* AssignTypeFlags.Invariant */;
17742
+ }
17743
+ else if (variance === 4 /* Variance.Contravariant */) {
17744
+ adjFlags ^= 2 /* AssignTypeFlags.Contravariant */;
17745
+ }
17746
+ if (!assignType(destTypeArg, srcTypeArg, diag, constraints, adjFlags, recursionCount)) {
17747
+ isAssignable = false;
17748
+ }
17749
+ });
17750
+ return isAssignable;
17751
+ }
17679
17752
  // If the expected type is an explicit TypeForm type, see if the source
17680
17753
  // type has an implicit TypeForm type that can be assigned to it. If so,
17681
17754
  // convert to an explicit TypeForm type.
@@ -17921,9 +17994,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17921
17994
  // Finds unsolved type variables in the destType and establishes constraints
17922
17995
  // in the constraint tracker for them based on the srcType.
17923
17996
  function setConstraintsForFreeTypeVars(destType, srcType, constraints) {
17924
- if (constraints.isLocked()) {
17925
- return;
17926
- }
17927
17997
  const typeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(destType);
17928
17998
  typeVars.forEach((typeVar) => {
17929
17999
  if (!types_1.TypeVarType.isBound(typeVar) && !constraints.getMainConstraintSet().getTypeVar(typeVar)) {
@@ -18574,7 +18644,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18574
18644
  if (destParamDetails.firstKeywordOnlyIndex !== undefined) {
18575
18645
  destParamDetails.params.forEach((param, index) => {
18576
18646
  if (index >= destParamDetails.firstKeywordOnlyIndex) {
18577
- if (param.param.name && param.param.category === 0 /* ParamCategory.Simple */) {
18647
+ if (param.param.name &&
18648
+ param.param.category === 0 /* ParamCategory.Simple */ &&
18649
+ param.kind !== parameterUtils_1.ParamKind.Positional) {
18578
18650
  destParamMap.set(param.param.name, param);
18579
18651
  }
18580
18652
  }
@@ -19519,11 +19591,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19519
19591
  // contain references to themselves or their subclasses, so if
19520
19592
  // we attempt to call assignType, we'll risk infinite recursion.
19521
19593
  // Instead, we'll assume it's assignable.
19522
- if (!constraints.isLocked()) {
19523
- constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
19524
- ? (0, typeUtils_1.convertToInstance)(firstParamType)
19525
- : firstParamType);
19526
- }
19594
+ constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
19595
+ ? (0, typeUtils_1.convertToInstance)(firstParamType)
19596
+ : firstParamType);
19527
19597
  }
19528
19598
  else {
19529
19599
  const subDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();