@zzzen/pyright-internal 1.2.0-dev.20241201 → 1.2.0-dev.20241215
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/checker.d.ts +2 -0
- package/dist/analyzer/checker.js +49 -0
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/dataClasses.js +24 -8
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +15 -12
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +0 -1
- package/dist/analyzer/parseTreeUtils.js +0 -8
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +7 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +48 -15
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -2
- package/dist/analyzer/typeUtils.js +9 -0
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/streamUtils.d.ts +2 -0
- package/dist/common/streamUtils.js +29 -0
- package/dist/common/streamUtils.js.map +1 -0
- package/dist/pyright.js +4 -4
- package/dist/pyright.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +12 -0
- package/dist/tests/typeEvaluator4.test.js.map +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
@@ -97,6 +97,8 @@ export declare class Checker extends ParseTreeWalker {
|
|
97
97
|
private _validateSymbolTables;
|
98
98
|
private _reportInvalidOverload;
|
99
99
|
private _reportFinalInLoop;
|
100
|
+
private _reportOverwriteOfImportedFinal;
|
101
|
+
private _reportOverwriteOfBuiltinsFinal;
|
100
102
|
private _reportMultipleFinalDeclarations;
|
101
103
|
private _reportMultipleTypeAliasDeclarations;
|
102
104
|
private _reportIncompatibleDeclarations;
|
package/dist/analyzer/checker.js
CHANGED
@@ -2058,6 +2058,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2058
2058
|
scope.symbolTable.forEach((symbol, name) => {
|
2059
2059
|
this._conditionallyReportUnusedSymbol(name, symbol, scope.type, dependentFileInfo);
|
2060
2060
|
this._reportIncompatibleDeclarations(name, symbol);
|
2061
|
+
this._reportOverwriteOfImportedFinal(name, symbol);
|
2062
|
+
this._reportOverwriteOfBuiltinsFinal(name, symbol, scope);
|
2061
2063
|
this._reportMultipleFinalDeclarations(name, symbol, scope.type);
|
2062
2064
|
this._reportFinalInLoop(symbol);
|
2063
2065
|
this._reportMultipleTypeAliasDeclarations(name, symbol);
|
@@ -2189,6 +2191,53 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2189
2191
|
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalInLoop(), decls[0].node);
|
2190
2192
|
}
|
2191
2193
|
}
|
2194
|
+
// If a variable that is marked Final in one module is imported by another
|
2195
|
+
// module, an attempt to overwrite the imported symbol should generate an
|
2196
|
+
// error.
|
2197
|
+
_reportOverwriteOfImportedFinal(name, symbol) {
|
2198
|
+
if (this._evaluator.isFinalVariable(symbol)) {
|
2199
|
+
return;
|
2200
|
+
}
|
2201
|
+
const decls = symbol.getDeclarations();
|
2202
|
+
const finalImportDecl = decls.find((decl) => {
|
2203
|
+
if (decl.type === 8 /* DeclarationType.Alias */) {
|
2204
|
+
const resolvedDecl = this._evaluator.resolveAliasDeclaration(decl, /* resolveLocalNames */ true);
|
2205
|
+
if (resolvedDecl && (0, declaration_1.isVariableDeclaration)(resolvedDecl) && resolvedDecl.isFinal) {
|
2206
|
+
return true;
|
2207
|
+
}
|
2208
|
+
}
|
2209
|
+
return false;
|
2210
|
+
});
|
2211
|
+
if (!finalImportDecl) {
|
2212
|
+
return;
|
2213
|
+
}
|
2214
|
+
decls.forEach((decl) => {
|
2215
|
+
var _a;
|
2216
|
+
if (decl !== finalImportDecl) {
|
2217
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(decl)) !== null && _a !== void 0 ? _a : decl.node);
|
2218
|
+
}
|
2219
|
+
});
|
2220
|
+
}
|
2221
|
+
// If the builtins module (or any implicitly chained module) defines a
|
2222
|
+
// Final variable, an attempt to overwrite it should generate an error.
|
2223
|
+
_reportOverwriteOfBuiltinsFinal(name, symbol, scope) {
|
2224
|
+
if (scope.type !== 4 /* ScopeType.Module */ || !scope.parent) {
|
2225
|
+
return;
|
2226
|
+
}
|
2227
|
+
const shadowedSymbolInfo = scope.parent.lookUpSymbolRecursive(name);
|
2228
|
+
if (!shadowedSymbolInfo) {
|
2229
|
+
return;
|
2230
|
+
}
|
2231
|
+
if (!this._evaluator.isFinalVariable(shadowedSymbolInfo.symbol)) {
|
2232
|
+
return;
|
2233
|
+
}
|
2234
|
+
const decls = symbol.getDeclarations();
|
2235
|
+
decls.forEach((decl) => {
|
2236
|
+
var _a;
|
2237
|
+
this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name }), (_a = (0, declarationUtils_1.getNameNodeForDeclaration)(decl)) !== null && _a !== void 0 ? _a : decl.node);
|
2238
|
+
});
|
2239
|
+
}
|
2240
|
+
// If a variable is marked Final, it should receive only one assigned value.
|
2192
2241
|
_reportMultipleFinalDeclarations(name, symbol, scopeType) {
|
2193
2242
|
if (!this._evaluator.isFinalVariable(symbol)) {
|
2194
2243
|
return;
|