@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.
- package/dist/analyzer/binder.js +7 -4
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +2 -1
- package/dist/analyzer/checker.js +135 -83
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +4 -4
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolution.d.ts +21 -0
- package/dist/analyzer/constraintSolution.js +71 -0
- package/dist/analyzer/constraintSolution.js.map +1 -0
- package/dist/analyzer/constraintSolver.d.ts +9 -5
- package/dist/analyzer/constraintSolver.js +420 -322
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +44 -0
- package/dist/analyzer/constraintTracker.js +230 -0
- package/dist/analyzer/constraintTracker.js.map +1 -0
- package/dist/analyzer/constructorTransform.js +15 -15
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +1 -1
- package/dist/analyzer/constructors.js +59 -38
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +35 -32
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.js +1 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/functionTransform.js +1 -1
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/operations.d.ts +1 -2
- package/dist/analyzer/operations.js +95 -72
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +8 -4
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +3 -3
- package/dist/analyzer/parameterUtils.js +19 -21
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +21 -19
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.d.ts +3 -2
- package/dist/analyzer/properties.js +11 -11
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +3 -3
- package/dist/analyzer/protocols.js +50 -48
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +2 -2
- package/dist/analyzer/tuples.js +10 -9
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeComplexity.js +12 -4
- package/dist/analyzer/typeComplexity.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +806 -778
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +28 -8
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +46 -39
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +17 -15
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +32 -30
- package/dist/analyzer/typeUtils.js +331 -563
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +1 -1
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -2
- package/dist/analyzer/typedDicts.js +25 -25
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +24 -21
- package/dist/analyzer/types.js +110 -113
- package/dist/analyzer/types.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -2
- package/dist/languageServerBase.js +5 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.js +2 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/tests/checker.test.js +10 -2
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +12 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +4 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +1 -1
- package/dist/analyzer/typeVarContext.d.ts +0 -48
- package/dist/analyzer/typeVarContext.js +0 -288
- package/dist/analyzer/typeVarContext.js.map +0 -1
package/dist/analyzer/types.js
CHANGED
@@ -8,9 +8,10 @@
|
|
8
8
|
* Representation of types used during type analysis within Python.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
-
exports.removeUnbound = exports.removeUnknownFromUnion = exports.isTypeSame = exports.getTypeAliasInfo = exports.isOverloadedFunction = exports.isFunction = exports.isUnpacked = exports.isUnpackedClass = exports.isUnpackedTypeVarTuple = exports.isTypeVarTuple = exports.isParamSpec = exports.isTypeVar = exports.isModule = exports.isClassInstance = exports.isInstantiableClass = exports.isClass = exports.isPossiblyUnbound = exports.isUnion = exports.isUnbound = exports.isAnyOrUnknown = exports.isUnknown = exports.isAny = exports.isNever = exports.TypeVarType = exports.ParamSpecType = exports.TypeVarScopeType = exports.TypeVarKind = exports.Variance = exports.UnionType = exports.TypeCondition = exports.AnyType = exports.NeverType = exports.OverloadedFunctionType = exports.FunctionType = exports.FunctionTypeFlags = exports.isKeywordOnlySeparator = exports.isPositionOnlySeparator = exports.FunctionParam = exports.FunctionParamFlags = exports.ClassType = exports.ClassTypeFlags = exports.ModuleType = exports.UnknownType = exports.UnboundType = exports.TypeBase = exports.maxTypeRecursionCount = exports.EnumLiteral = exports.
|
11
|
+
exports.removeUnbound = exports.removeUnknownFromUnion = exports.isTypeSame = exports.getTypeAliasInfo = exports.isOverloadedFunction = exports.isFunction = exports.isUnpacked = exports.isUnpackedClass = exports.isUnpackedTypeVarTuple = exports.isTypeVarTuple = exports.isParamSpec = exports.isTypeVar = exports.isModule = exports.isClassInstance = exports.isInstantiableClass = exports.isClass = exports.isPossiblyUnbound = exports.isUnion = exports.isUnbound = exports.isAnyOrUnknown = exports.isUnknown = exports.isAny = exports.isNever = exports.TypeVarType = exports.ParamSpecType = exports.TypeVarScopeType = exports.TypeVarKind = exports.Variance = exports.UnionType = exports.TypeCondition = exports.AnyType = exports.NeverType = exports.OverloadedFunctionType = exports.FunctionType = exports.FunctionTypeFlags = exports.isKeywordOnlySeparator = exports.isPositionOnlySeparator = exports.FunctionParam = exports.FunctionParamFlags = exports.ClassType = exports.ClassTypeFlags = exports.ModuleType = exports.UnknownType = exports.UnboundType = exports.TypeBase = exports.maxTypeRecursionCount = exports.EnumLiteral = exports.UnificationScopeId = exports.TypeFlags = exports.TypeCategory = void 0;
|
12
12
|
exports.isSameWithoutLiteralValue = exports.combineTypes = exports.findSubtype = exports.removeFromUnion = void 0;
|
13
13
|
const debug_1 = require("../common/debug");
|
14
|
+
const typeUtils_1 = require("./typeUtils");
|
14
15
|
var TypeCategory;
|
15
16
|
(function (TypeCategory) {
|
16
17
|
// Name is not bound to a value of any type.
|
@@ -54,7 +55,7 @@ var TypeFlags;
|
|
54
55
|
// when comparing two types for equivalence.
|
55
56
|
TypeFlags[TypeFlags["TypeCompatibilityMask"] = 3] = "TypeCompatibilityMask";
|
56
57
|
})(TypeFlags || (exports.TypeFlags = TypeFlags = {}));
|
57
|
-
exports.
|
58
|
+
exports.UnificationScopeId = '-';
|
58
59
|
class EnumLiteral {
|
59
60
|
constructor(classFullName, className, itemName, itemType) {
|
60
61
|
this.classFullName = classFullName;
|
@@ -186,19 +187,9 @@ var TypeBase;
|
|
186
187
|
return newInstance;
|
187
188
|
}
|
188
189
|
TypeBase.cloneTypeAsInstantiable = cloneTypeAsInstantiable;
|
189
|
-
function cloneForTypeAlias(type,
|
190
|
+
function cloneForTypeAlias(type, aliasInfo) {
|
190
191
|
const typeClone = cloneType(type);
|
191
|
-
TypeBase.setTypeAliasInfo(typeClone,
|
192
|
-
name,
|
193
|
-
fullName,
|
194
|
-
moduleName,
|
195
|
-
fileUri,
|
196
|
-
typeVarScopeId,
|
197
|
-
isPep695Syntax,
|
198
|
-
typeParams: typeParams,
|
199
|
-
usageVariance: undefined,
|
200
|
-
typeArgs: typeArgs,
|
201
|
-
});
|
192
|
+
TypeBase.setTypeAliasInfo(typeClone, aliasInfo);
|
202
193
|
return typeClone;
|
203
194
|
}
|
204
195
|
TypeBase.cloneForTypeAlias = cloneForTypeAlias;
|
@@ -395,8 +386,7 @@ var ClassTypeFlags;
|
|
395
386
|
// class is generic, and therefore supports standard subscripting
|
396
387
|
// semantics.
|
397
388
|
ClassTypeFlags[ClassTypeFlags["HasCustomClassGetItem"] = 16384] = "HasCustomClassGetItem";
|
398
|
-
// The tuple class
|
399
|
-
// special-case handling of its type arguments.
|
389
|
+
// The tuple class requires special-case handling for its type arguments.
|
400
390
|
ClassTypeFlags[ClassTypeFlags["TupleClass"] = 32768] = "TupleClass";
|
401
391
|
// The class has a metaclass of EnumMeta or derives from
|
402
392
|
// a class that has this metaclass.
|
@@ -969,7 +959,7 @@ var FunctionParamFlags;
|
|
969
959
|
var FunctionParam;
|
970
960
|
(function (FunctionParam) {
|
971
961
|
function create(category, type, flags = FunctionParamFlags.None, name, defaultType) {
|
972
|
-
return { category,
|
962
|
+
return { category, flags, name, _type: type, _defaultType: defaultType };
|
973
963
|
}
|
974
964
|
FunctionParam.create = create;
|
975
965
|
function isNameSynthesized(param) {
|
@@ -1092,14 +1082,16 @@ var FunctionType;
|
|
1092
1082
|
}
|
1093
1083
|
// Creates a deep copy of the function type, including a fresh
|
1094
1084
|
// version of _functionDetails.
|
1095
|
-
function clone(type, stripFirstParam = false, boundToType
|
1085
|
+
function clone(type, stripFirstParam = false, boundToType) {
|
1096
1086
|
var _a, _b;
|
1097
1087
|
const newFunction = TypeBase.cloneType(type);
|
1098
1088
|
newFunction.shared = { ...type.shared };
|
1099
1089
|
newFunction.priv.preBoundFlags = newFunction.shared.flags;
|
1100
1090
|
newFunction.priv.boundToType = boundToType;
|
1101
|
-
if (
|
1102
|
-
|
1091
|
+
if (boundToType) {
|
1092
|
+
if (type.shared.name === '__new__' || type.shared.name === '__init__') {
|
1093
|
+
newFunction.priv.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(boundToType);
|
1094
|
+
}
|
1103
1095
|
}
|
1104
1096
|
if (stripFirstParam) {
|
1105
1097
|
if (type.shared.parameters.length > 0) {
|
@@ -1107,7 +1099,7 @@ var FunctionType;
|
|
1107
1099
|
if (type.shared.parameters.length > 0 && !FunctionParam.isTypeInferred(type.shared.parameters[0])) {
|
1108
1100
|
// Stash away the effective type of the first parameter if it
|
1109
1101
|
// wasn't synthesized.
|
1110
|
-
newFunction.priv.strippedFirstParamType =
|
1102
|
+
newFunction.priv.strippedFirstParamType = getParamType(type, 0);
|
1111
1103
|
}
|
1112
1104
|
newFunction.shared.parameters = type.shared.parameters.slice(1);
|
1113
1105
|
}
|
@@ -1128,9 +1120,9 @@ var FunctionType;
|
|
1128
1120
|
parameterTypes: stripFirstParam
|
1129
1121
|
? type.priv.specializedTypes.parameterTypes.slice(1)
|
1130
1122
|
: type.priv.specializedTypes.parameterTypes,
|
1131
|
-
|
1132
|
-
? (_b = type.priv.specializedTypes.
|
1133
|
-
: type.priv.specializedTypes.
|
1123
|
+
parameterDefaultTypes: stripFirstParam
|
1124
|
+
? (_b = type.priv.specializedTypes.parameterDefaultTypes) === null || _b === void 0 ? void 0 : _b.slice(1)
|
1125
|
+
: type.priv.specializedTypes.parameterDefaultTypes,
|
1134
1126
|
returnType: type.priv.specializedTypes.returnType,
|
1135
1127
|
};
|
1136
1128
|
}
|
@@ -1165,8 +1157,8 @@ var FunctionType;
|
|
1165
1157
|
function specialize(type, specializedTypes, specializedInferredReturnType) {
|
1166
1158
|
const newFunction = TypeBase.cloneType(type);
|
1167
1159
|
(0, debug_1.assert)(specializedTypes.parameterTypes.length === type.shared.parameters.length);
|
1168
|
-
if (specializedTypes.
|
1169
|
-
(0, debug_1.assert)(specializedTypes.
|
1160
|
+
if (specializedTypes.parameterDefaultTypes) {
|
1161
|
+
(0, debug_1.assert)(specializedTypes.parameterDefaultTypes.length === type.shared.parameters.length);
|
1170
1162
|
}
|
1171
1163
|
newFunction.priv.specializedTypes = specializedTypes;
|
1172
1164
|
newFunction.priv.inferredReturnType = specializedInferredReturnType;
|
@@ -1185,8 +1177,8 @@ var FunctionType;
|
|
1185
1177
|
const prevParams = Array.from(newFunction.shared.parameters);
|
1186
1178
|
newFunction.shared.parameters = [
|
1187
1179
|
...prevParams,
|
1188
|
-
...paramSpecValue.shared.parameters.map((param) => {
|
1189
|
-
return FunctionParam.create(param.category,
|
1180
|
+
...paramSpecValue.shared.parameters.map((param, index) => {
|
1181
|
+
return FunctionParam.create(param.category, FunctionType.getParamType(paramSpecValue, index), (param.flags & FunctionParamFlags.NameSynthesized) | FunctionParamFlags.TypeDeclared, param.name, FunctionType.getParamDefaultType(paramSpecValue, index));
|
1190
1182
|
}),
|
1191
1183
|
];
|
1192
1184
|
if (newFunction.shared.docString === undefined) {
|
@@ -1216,16 +1208,14 @@ var FunctionType;
|
|
1216
1208
|
// Update the specialized parameter types as well.
|
1217
1209
|
const specializedTypes = newFunction.priv.specializedTypes;
|
1218
1210
|
if (specializedTypes) {
|
1219
|
-
paramSpecValue.shared.parameters.forEach((
|
1211
|
+
paramSpecValue.shared.parameters.forEach((_, index) => {
|
1220
1212
|
var _a;
|
1221
|
-
specializedTypes.parameterTypes.push(
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1213
|
+
specializedTypes.parameterTypes.push(FunctionType.getParamType(paramSpecValue, index));
|
1214
|
+
if (specializedTypes.parameterDefaultTypes) {
|
1215
|
+
(_a = specializedTypes.parameterDefaultTypes) === null || _a === void 0 ? void 0 : _a.push(FunctionType.getParamDefaultType(paramSpecValue, index));
|
1216
|
+
}
|
1225
1217
|
});
|
1226
1218
|
}
|
1227
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.shared.typeVarScopeId);
|
1228
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.priv.higherOrderTypeVarScopeIds);
|
1229
1219
|
newFunction.priv.constructorTypeVarScopeId = paramSpecValue.priv.constructorTypeVarScopeId;
|
1230
1220
|
if (!newFunction.shared.methodClass && paramSpecValue.shared.methodClass) {
|
1231
1221
|
newFunction.shared.methodClass = paramSpecValue.shared.methodClass;
|
@@ -1248,7 +1238,6 @@ var FunctionType;
|
|
1248
1238
|
newFunction.shared.typeVarScopeId = newScopeId;
|
1249
1239
|
newFunction.priv.constructorTypeVarScopeId = newConstructorScopeId;
|
1250
1240
|
newFunction.shared.typeParams = typeParams;
|
1251
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, typeParams.map((t) => { var _a, _b; return (_b = (_a = t.priv.externalTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) !== null && _b !== void 0 ? _b : t.priv.scopeId; }));
|
1252
1241
|
return newFunction;
|
1253
1242
|
}
|
1254
1243
|
FunctionType.cloneWithNewTypeVarScopeId = cloneWithNewTypeVarScopeId;
|
@@ -1282,8 +1271,8 @@ var FunctionType;
|
|
1282
1271
|
if (argsParam.category !== 1 /* ParamCategory.ArgsList */ || kwargsParam.category !== 2 /* ParamCategory.KwargsDict */) {
|
1283
1272
|
return type;
|
1284
1273
|
}
|
1285
|
-
const argsType = FunctionType.
|
1286
|
-
const kwargsType = FunctionType.
|
1274
|
+
const argsType = FunctionType.getParamType(type, paramCount - 2);
|
1275
|
+
const kwargsType = FunctionType.getParamType(type, paramCount - 1);
|
1287
1276
|
if (!isParamSpec(argsType) || !isParamSpec(kwargsType) || !isTypeSame(argsType, kwargsType)) {
|
1288
1277
|
return type;
|
1289
1278
|
}
|
@@ -1304,9 +1293,9 @@ var FunctionType;
|
|
1304
1293
|
if (type.priv.specializedTypes) {
|
1305
1294
|
newFunction.priv.specializedTypes = { ...type.priv.specializedTypes };
|
1306
1295
|
newFunction.priv.specializedTypes.parameterTypes = newFunction.priv.specializedTypes.parameterTypes.slice(0, newFunction.priv.specializedTypes.parameterTypes.length - paramsToDrop);
|
1307
|
-
if (newFunction.priv.specializedTypes.
|
1308
|
-
newFunction.priv.specializedTypes.
|
1309
|
-
newFunction.priv.specializedTypes.
|
1296
|
+
if (newFunction.priv.specializedTypes.parameterDefaultTypes) {
|
1297
|
+
newFunction.priv.specializedTypes.parameterDefaultTypes =
|
1298
|
+
newFunction.priv.specializedTypes.parameterDefaultTypes.slice(0, newFunction.priv.specializedTypes.parameterDefaultTypes.length - paramsToDrop);
|
1310
1299
|
}
|
1311
1300
|
}
|
1312
1301
|
if (type.priv.inferredReturnType) {
|
@@ -1323,14 +1312,16 @@ var FunctionType;
|
|
1323
1312
|
return undefined;
|
1324
1313
|
}
|
1325
1314
|
const secondLastParam = params[params.length - 2];
|
1315
|
+
const secondLastParamType = FunctionType.getParamType(type, params.length - 2);
|
1326
1316
|
const lastParam = params[params.length - 1];
|
1317
|
+
const lastParamType = FunctionType.getParamType(type, params.length - 1);
|
1327
1318
|
if (secondLastParam.category === 1 /* ParamCategory.ArgsList */ &&
|
1328
|
-
isParamSpec(
|
1329
|
-
|
1319
|
+
isParamSpec(secondLastParamType) &&
|
1320
|
+
secondLastParamType.priv.paramSpecAccess === 'args' &&
|
1330
1321
|
lastParam.category === 2 /* ParamCategory.KwargsDict */ &&
|
1331
|
-
isParamSpec(
|
1332
|
-
|
1333
|
-
return TypeVarType.cloneForParamSpecAccess(
|
1322
|
+
isParamSpec(lastParamType) &&
|
1323
|
+
lastParamType.priv.paramSpecAccess === 'kwargs') {
|
1324
|
+
return TypeVarType.cloneForParamSpecAccess(secondLastParamType, /* access */ undefined);
|
1334
1325
|
}
|
1335
1326
|
return undefined;
|
1336
1327
|
}
|
@@ -1346,27 +1337,6 @@ var FunctionType;
|
|
1346
1337
|
});
|
1347
1338
|
}
|
1348
1339
|
FunctionType.addDefaultParams = addDefaultParams;
|
1349
|
-
function addHigherOrderTypeVarScopeIds(functionType, scopeIds) {
|
1350
|
-
if (!scopeIds) {
|
1351
|
-
return;
|
1352
|
-
}
|
1353
|
-
if (!Array.isArray(scopeIds)) {
|
1354
|
-
scopeIds = [scopeIds];
|
1355
|
-
}
|
1356
|
-
if (!functionType.priv.higherOrderTypeVarScopeIds) {
|
1357
|
-
functionType.priv.higherOrderTypeVarScopeIds = [];
|
1358
|
-
}
|
1359
|
-
// Add the scope IDs to the function if they're unique.
|
1360
|
-
scopeIds.forEach((scopeId) => {
|
1361
|
-
if (!scopeId || scopeId === functionType.shared.typeVarScopeId) {
|
1362
|
-
return;
|
1363
|
-
}
|
1364
|
-
if (!functionType.priv.higherOrderTypeVarScopeIds.some((id) => id === scopeId)) {
|
1365
|
-
functionType.priv.higherOrderTypeVarScopeIds.push(scopeId);
|
1366
|
-
}
|
1367
|
-
});
|
1368
|
-
}
|
1369
|
-
FunctionType.addHigherOrderTypeVarScopeIds = addHigherOrderTypeVarScopeIds;
|
1370
1340
|
function getDefaultParams(useUnknown = false) {
|
1371
1341
|
return [
|
1372
1342
|
FunctionParam.create(1 /* ParamCategory.ArgsList */, useUnknown ? UnknownType.create() : AnyType.create(), useUnknown ? FunctionParamFlags.None : FunctionParamFlags.TypeDeclared, 'args'),
|
@@ -1393,7 +1363,7 @@ var FunctionType;
|
|
1393
1363
|
else if (param.category === 2 /* ParamCategory.KwargsDict */) {
|
1394
1364
|
sawKwargs = true;
|
1395
1365
|
}
|
1396
|
-
if (!isAnyOrUnknown(FunctionType.
|
1366
|
+
if (!isAnyOrUnknown(FunctionType.getParamType(functionType, i))) {
|
1397
1367
|
return false;
|
1398
1368
|
}
|
1399
1369
|
}
|
@@ -1491,31 +1461,35 @@ var FunctionType;
|
|
1491
1461
|
return true;
|
1492
1462
|
}
|
1493
1463
|
FunctionType.isBuiltIn = isBuiltIn;
|
1494
|
-
function
|
1464
|
+
function getDeclaredParamType(type, index) {
|
1465
|
+
return type.shared.parameters[index]._type;
|
1466
|
+
}
|
1467
|
+
FunctionType.getDeclaredParamType = getDeclaredParamType;
|
1468
|
+
function getParamType(type, index) {
|
1495
1469
|
(0, debug_1.assert)(index < type.shared.parameters.length, 'Parameter types array overflow');
|
1496
1470
|
if (type.priv.specializedTypes && index < type.priv.specializedTypes.parameterTypes.length) {
|
1497
1471
|
return type.priv.specializedTypes.parameterTypes[index];
|
1498
1472
|
}
|
1499
|
-
return type.shared.parameters[index].
|
1473
|
+
return type.shared.parameters[index]._type;
|
1500
1474
|
}
|
1501
|
-
FunctionType.
|
1502
|
-
function
|
1475
|
+
FunctionType.getParamType = getParamType;
|
1476
|
+
function getParamDefaultType(type, index) {
|
1503
1477
|
var _a;
|
1504
1478
|
(0, debug_1.assert)(index < type.shared.parameters.length, 'Parameter types array overflow');
|
1505
|
-
if (((_a = type.priv.specializedTypes) === null || _a === void 0 ? void 0 : _a.
|
1506
|
-
index < type.priv.specializedTypes.
|
1507
|
-
const defaultArgType = type.priv.specializedTypes.
|
1479
|
+
if (((_a = type.priv.specializedTypes) === null || _a === void 0 ? void 0 : _a.parameterDefaultTypes) &&
|
1480
|
+
index < type.priv.specializedTypes.parameterDefaultTypes.length) {
|
1481
|
+
const defaultArgType = type.priv.specializedTypes.parameterDefaultTypes[index];
|
1508
1482
|
if (defaultArgType) {
|
1509
1483
|
return defaultArgType;
|
1510
1484
|
}
|
1511
1485
|
}
|
1512
|
-
return type.shared.parameters[index].
|
1486
|
+
return type.shared.parameters[index]._defaultType;
|
1513
1487
|
}
|
1514
|
-
FunctionType.
|
1488
|
+
FunctionType.getParamDefaultType = getParamDefaultType;
|
1515
1489
|
function addParam(type, param) {
|
1516
1490
|
type.shared.parameters.push(param);
|
1517
1491
|
if (type.priv.specializedTypes) {
|
1518
|
-
type.priv.specializedTypes.parameterTypes.push(param.
|
1492
|
+
type.priv.specializedTypes.parameterTypes.push(param._type);
|
1519
1493
|
}
|
1520
1494
|
}
|
1521
1495
|
FunctionType.addParam = addParam;
|
@@ -1895,8 +1869,8 @@ var TypeVarType;
|
|
1895
1869
|
if ((_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.specialForm) {
|
1896
1870
|
TypeBase.setSpecialForm(newInstance, undefined);
|
1897
1871
|
}
|
1898
|
-
if (newInstance.priv.
|
1899
|
-
newInstance.priv.
|
1872
|
+
if (newInstance.priv.freeTypeVar) {
|
1873
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneAsInstance(newInstance.priv.freeTypeVar);
|
1900
1874
|
}
|
1901
1875
|
return newInstance;
|
1902
1876
|
}
|
@@ -1907,8 +1881,8 @@ var TypeVarType;
|
|
1907
1881
|
return type.cached.typeBaseInstantiableType;
|
1908
1882
|
}
|
1909
1883
|
const newInstance = TypeBase.cloneTypeAsInstantiable(type, /* cache */ true);
|
1910
|
-
if (newInstance.priv.
|
1911
|
-
newInstance.priv.
|
1884
|
+
if (newInstance.priv.freeTypeVar) {
|
1885
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneAsInstantiable(newInstance.priv.freeTypeVar);
|
1912
1886
|
}
|
1913
1887
|
return newInstance;
|
1914
1888
|
}
|
@@ -1934,26 +1908,26 @@ var TypeVarType;
|
|
1934
1908
|
TypeVarType.cloneForScopeId = cloneForScopeId;
|
1935
1909
|
function cloneForUnpacked(type, isInUnion = false) {
|
1936
1910
|
const newInstance = TypeBase.cloneType(type);
|
1937
|
-
newInstance.priv.
|
1938
|
-
newInstance.priv.
|
1939
|
-
if (newInstance.priv.
|
1940
|
-
newInstance.priv.
|
1911
|
+
newInstance.priv.isUnpacked = true;
|
1912
|
+
newInstance.priv.isInUnion = isInUnion;
|
1913
|
+
if (newInstance.priv.freeTypeVar) {
|
1914
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneForUnpacked(newInstance.priv.freeTypeVar, isInUnion);
|
1941
1915
|
}
|
1942
1916
|
return newInstance;
|
1943
1917
|
}
|
1944
1918
|
TypeVarType.cloneForUnpacked = cloneForUnpacked;
|
1945
1919
|
function cloneForPacked(type) {
|
1946
1920
|
const newInstance = TypeBase.cloneType(type);
|
1947
|
-
newInstance.priv.
|
1948
|
-
newInstance.priv.
|
1949
|
-
if (newInstance.priv.
|
1950
|
-
newInstance.priv.
|
1921
|
+
newInstance.priv.isUnpacked = false;
|
1922
|
+
newInstance.priv.isInUnion = false;
|
1923
|
+
if (newInstance.priv.freeTypeVar) {
|
1924
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneForPacked(newInstance.priv.freeTypeVar);
|
1951
1925
|
}
|
1952
1926
|
return newInstance;
|
1953
1927
|
}
|
1954
1928
|
TypeVarType.cloneForPacked = cloneForPacked;
|
1955
1929
|
// Creates a "simplified" version of the TypeVar with invariance
|
1956
|
-
// and no bound or constraints. ParamSpecs and
|
1930
|
+
// and no bound or constraints. ParamSpecs and TypeVarTuples are left
|
1957
1931
|
// unmodified. So are auto-variant type variables.
|
1958
1932
|
function cloneAsInvariant(type) {
|
1959
1933
|
if (isParamSpec(type) || isTypeVarTuple(type)) {
|
@@ -1963,7 +1937,7 @@ var TypeVarType;
|
|
1963
1937
|
return type;
|
1964
1938
|
}
|
1965
1939
|
if (type.shared.declaredVariance === 2 /* Variance.Invariant */) {
|
1966
|
-
if (type
|
1940
|
+
if (!TypeVarType.hasBound(type) && !TypeVarType.hasConstraints(type)) {
|
1967
1941
|
return type;
|
1968
1942
|
}
|
1969
1943
|
}
|
@@ -1982,15 +1956,15 @@ var TypeVarType;
|
|
1982
1956
|
}
|
1983
1957
|
TypeVarType.cloneForParamSpecAccess = cloneForParamSpecAccess;
|
1984
1958
|
function cloneAsSpecializedSelf(type, specializedBoundType) {
|
1985
|
-
(0, debug_1.assert)(type
|
1959
|
+
(0, debug_1.assert)(TypeVarType.isSelf(type));
|
1986
1960
|
const newInstance = TypeBase.cloneType(type);
|
1987
1961
|
newInstance.shared = { ...newInstance.shared };
|
1988
1962
|
newInstance.shared.boundType = specializedBoundType;
|
1989
1963
|
return newInstance;
|
1990
1964
|
}
|
1991
1965
|
TypeVarType.cloneAsSpecializedSelf = cloneAsSpecializedSelf;
|
1992
|
-
function
|
1993
|
-
if (type
|
1966
|
+
function cloneAsUnificationVar(type, usageOffset) {
|
1967
|
+
if (TypeVarType.isUnification(type)) {
|
1994
1968
|
return type;
|
1995
1969
|
}
|
1996
1970
|
// If the caller specified a usage offset, append it to the TypeVar
|
@@ -2002,36 +1976,47 @@ var TypeVarType;
|
|
2002
1976
|
newNameWithScope = `${type.priv.nameWithScope}-${usageOffset}`;
|
2003
1977
|
}
|
2004
1978
|
const newInstance = TypeBase.cloneType(type);
|
2005
|
-
newInstance.priv.
|
2006
|
-
newInstance.priv.scopeId = exports.
|
1979
|
+
newInstance.priv.isUnificationVar = true;
|
1980
|
+
newInstance.priv.scopeId = exports.UnificationScopeId;
|
2007
1981
|
newInstance.priv.nameWithScope = newNameWithScope;
|
2008
1982
|
return newInstance;
|
2009
1983
|
}
|
2010
|
-
TypeVarType.
|
1984
|
+
TypeVarType.cloneAsUnificationVar = cloneAsUnificationVar;
|
2011
1985
|
function makeNameWithScope(name, scopeId) {
|
2012
1986
|
return `${name}.${scopeId}`;
|
2013
1987
|
}
|
2014
1988
|
TypeVarType.makeNameWithScope = makeNameWithScope;
|
2015
|
-
function
|
1989
|
+
function makeBoundScopeId(scopeId) {
|
2016
1990
|
if (!scopeId) {
|
2017
1991
|
return undefined;
|
2018
1992
|
}
|
1993
|
+
// Append an asterisk to denote a bound scope.
|
2019
1994
|
return `${scopeId}*`;
|
2020
1995
|
}
|
2021
|
-
TypeVarType.
|
2022
|
-
function
|
2023
|
-
if (type.priv.scopeId === undefined || type.priv.
|
1996
|
+
TypeVarType.makeBoundScopeId = makeBoundScopeId;
|
1997
|
+
function cloneAsBound(type) {
|
1998
|
+
if (type.priv.scopeId === undefined || type.priv.freeTypeVar) {
|
2024
1999
|
return type;
|
2025
2000
|
}
|
2026
|
-
const clone = TypeVarType.cloneForScopeId(type, TypeVarType.
|
2027
|
-
clone.priv.
|
2001
|
+
const clone = TypeVarType.cloneForScopeId(type, TypeVarType.makeBoundScopeId(type.priv.scopeId), type.priv.scopeName, type.priv.scopeType);
|
2002
|
+
clone.priv.freeTypeVar = type;
|
2028
2003
|
return clone;
|
2029
2004
|
}
|
2030
|
-
TypeVarType.
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2005
|
+
TypeVarType.cloneAsBound = cloneAsBound;
|
2006
|
+
// Indicates that the type var is a "free" or unbound type var. Free
|
2007
|
+
// type variables can be solved whereas bound type vars are already bound
|
2008
|
+
// to a value.
|
2009
|
+
function isBound(type) {
|
2010
|
+
// If the type var has an associated free type var, then it's
|
2011
|
+
// considered bound. If it has no associated free var, then it's
|
2012
|
+
// considered free.
|
2013
|
+
return !!type.priv.freeTypeVar;
|
2014
|
+
}
|
2015
|
+
TypeVarType.isBound = isBound;
|
2016
|
+
function isUnification(type) {
|
2017
|
+
return type.priv.isUnificationVar;
|
2018
|
+
}
|
2019
|
+
TypeVarType.isUnification = isUnification;
|
2035
2020
|
function create(name, kind, typeFlags) {
|
2036
2021
|
const newTypeVarType = {
|
2037
2022
|
category: 9 /* TypeCategory.TypeVar */,
|
@@ -2092,6 +2077,18 @@ var TypeVarType;
|
|
2092
2077
|
return !!type.shared.recursiveAlias && !type.shared.boundType;
|
2093
2078
|
}
|
2094
2079
|
TypeVarType.isTypeAliasPlaceholder = isTypeAliasPlaceholder;
|
2080
|
+
function isSelf(type) {
|
2081
|
+
return !!type.shared.isSynthesizedSelf;
|
2082
|
+
}
|
2083
|
+
TypeVarType.isSelf = isSelf;
|
2084
|
+
function hasConstraints(type) {
|
2085
|
+
return type.shared.constraints.length > 0;
|
2086
|
+
}
|
2087
|
+
TypeVarType.hasConstraints = hasConstraints;
|
2088
|
+
function hasBound(type) {
|
2089
|
+
return !!type.shared.boundType;
|
2090
|
+
}
|
2091
|
+
TypeVarType.hasBound = hasBound;
|
2095
2092
|
})(TypeVarType || (exports.TypeVarType = TypeVarType = {}));
|
2096
2093
|
function isNever(type) {
|
2097
2094
|
return type.category === 3 /* TypeCategory.Never */;
|
@@ -2162,7 +2159,7 @@ function isTypeVarTuple(type) {
|
|
2162
2159
|
}
|
2163
2160
|
exports.isTypeVarTuple = isTypeVarTuple;
|
2164
2161
|
function isUnpackedTypeVarTuple(type) {
|
2165
|
-
return isTypeVarTuple(type) && !!type.priv.
|
2162
|
+
return isTypeVarTuple(type) && !!type.priv.isUnpacked && !type.priv.isInUnion;
|
2166
2163
|
}
|
2167
2164
|
exports.isUnpackedTypeVarTuple = isUnpackedTypeVarTuple;
|
2168
2165
|
function isUnpackedClass(type) {
|
@@ -2315,8 +2312,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2315
2312
|
else if (isKeywordOnlySeparator(param1) && isKeywordOnlySeparator(param2)) {
|
2316
2313
|
continue;
|
2317
2314
|
}
|
2318
|
-
const param1Type = FunctionType.
|
2319
|
-
const param2Type = FunctionType.
|
2315
|
+
const param1Type = FunctionType.getParamType(type1, i);
|
2316
|
+
const param2Type = FunctionType.getParamType(functionType2, i);
|
2320
2317
|
if (!isTypeSame(param1Type, param2Type, { ...options, ignoreTypeFlags: false }, recursionCount)) {
|
2321
2318
|
return false;
|
2322
2319
|
}
|
@@ -2393,7 +2390,7 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2393
2390
|
}
|
2394
2391
|
}
|
2395
2392
|
if (isTypeVarTuple(type1) && isTypeVarTuple(type2TypeVar)) {
|
2396
|
-
if (!type1.priv.
|
2393
|
+
if (!type1.priv.isInUnion !== !type2TypeVar.priv.isInUnion) {
|
2397
2394
|
return false;
|
2398
2395
|
}
|
2399
2396
|
}
|