Skip to content

Commit cc77773

Browse files
committed
Revert #56753 but keep tests
1 parent c3efeb9 commit cc77773

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

src/compiler/checker.ts

+10-30
Original file line numberDiff line numberDiff line change
@@ -11808,7 +11808,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1180811808
// contextual type or, if the element itself is a binding pattern, with the type implied by that binding
1180911809
// pattern.
1181011810
const contextualType = isBindingPattern(element.name) ? getTypeFromBindingPattern(element.name, /*includePatternInType*/ true, /*reportErrors*/ false) : unknownType;
11811-
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, reportErrors ? CheckMode.Normal : CheckMode.Contextual, contextualType)));
11811+
return addOptionality(widenTypeInferredFromInitializer(element, checkDeclarationInitializer(element, CheckMode.Normal, contextualType)));
1181211812
}
1181311813
if (isBindingPattern(element.name)) {
1181411814
return getTypeFromBindingPattern(element.name, includePatternInType, reportErrors);
@@ -11985,24 +11985,24 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1198511985
return false;
1198611986
}
1198711987

11988-
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol, checkMode?: CheckMode): Type {
11988+
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol): Type {
1198911989
const links = getSymbolLinks(symbol);
1199011990
if (!links.type) {
11991-
const type = getTypeOfVariableOrParameterOrPropertyWorker(symbol, checkMode);
11991+
const type = getTypeOfVariableOrParameterOrPropertyWorker(symbol);
1199211992
// For a contextually typed parameter it is possible that a type has already
1199311993
// been assigned (in assignTypeToParameterAndFixTypeParameters), and we want
1199411994
// to preserve this type. In fact, we need to _prefer_ that type, but it won't
1199511995
// be assigned until contextual typing is complete, so we need to defer in
1199611996
// cases where contextual typing may take place.
11997-
if (!links.type && !isParameterOfContextSensitiveSignature(symbol) && !checkMode) {
11997+
if (!links.type && !isParameterOfContextSensitiveSignature(symbol)) {
1199811998
links.type = type;
1199911999
}
1200012000
return type;
1200112001
}
1200212002
return links.type;
1200312003
}
1200412004

12005-
function getTypeOfVariableOrParameterOrPropertyWorker(symbol: Symbol, checkMode?: CheckMode): Type {
12005+
function getTypeOfVariableOrParameterOrPropertyWorker(symbol: Symbol): Type {
1200612006
// Handle prototype property
1200712007
if (symbol.flags & SymbolFlags.Prototype) {
1200812008
return getTypeOfPrototypeProperty(symbol);
@@ -12045,16 +12045,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1204512045
if (symbol.flags & SymbolFlags.ValueModule && !(symbol.flags & SymbolFlags.Assignment)) {
1204612046
return getTypeOfFuncClassEnumModule(symbol);
1204712047
}
12048-
12049-
// When trying to get the *contextual* type of a binding element, it's possible to fall in a loop and therefore
12050-
// end up in a circularity-like situation. This is not a true circularity so we should not report such an error.
12051-
// For example, here the looping could happen when trying to get the type of `a` (binding element):
12052-
//
12053-
// const { a, b = a } = { a: 0 }
12054-
//
12055-
if (isBindingElement(declaration) && checkMode === CheckMode.Contextual) {
12056-
return errorType;
12057-
}
1205812048
return reportCircularityError(symbol);
1205912049
}
1206012050
let type: Type;
@@ -12127,16 +12117,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1212712117
if (symbol.flags & SymbolFlags.ValueModule && !(symbol.flags & SymbolFlags.Assignment)) {
1212812118
return getTypeOfFuncClassEnumModule(symbol);
1212912119
}
12130-
12131-
// When trying to get the *contextual* type of a binding element, it's possible to fall in a loop and therefore
12132-
// end up in a circularity-like situation. This is not a true circularity so we should not report such an error.
12133-
// For example, here the looping could happen when trying to get the type of `a` (binding element):
12134-
//
12135-
// const { a, b = a } = { a: 0 }
12136-
//
12137-
if (isBindingElement(declaration) && checkMode === CheckMode.Contextual) {
12138-
return type;
12139-
}
1214012120
return reportCircularityError(symbol);
1214112121
}
1214212122
return type;
@@ -12419,7 +12399,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1241912399
return getTypeOfSymbol(symbol);
1242012400
}
1242112401

12422-
function getTypeOfSymbol(symbol: Symbol, checkMode?: CheckMode): Type {
12402+
function getTypeOfSymbol(symbol: Symbol): Type {
1242312403
const checkFlags = getCheckFlags(symbol);
1242412404
if (checkFlags & CheckFlags.DeferredType) {
1242512405
return getTypeOfSymbolWithDeferredType(symbol);
@@ -12434,7 +12414,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1243412414
return getTypeOfReverseMappedSymbol(symbol as ReverseMappedSymbol);
1243512415
}
1243612416
if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) {
12437-
return getTypeOfVariableOrParameterOrProperty(symbol, checkMode);
12417+
return getTypeOfVariableOrParameterOrProperty(symbol);
1243812418
}
1243912419
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) {
1244012420
return getTypeOfFuncClassEnumModule(symbol);
@@ -30072,8 +30052,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3007230052
}
3007330053
}
3007430054

30075-
function getNarrowedTypeOfSymbol(symbol: Symbol, location: Identifier, checkMode?: CheckMode) {
30076-
const type = getTypeOfSymbol(symbol, checkMode);
30055+
function getNarrowedTypeOfSymbol(symbol: Symbol, location: Identifier) {
30056+
const type = getTypeOfSymbol(symbol);
3007730057
const declaration = symbol.valueDeclaration;
3007830058
if (declaration) {
3007930059
// If we have a non-rest binding element with no initializer declared as a const variable or a const-like
@@ -30256,7 +30236,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3025630236
const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
3025730237
let declaration = localOrExportSymbol.valueDeclaration;
3025830238

30259-
let type = getNarrowedTypeOfSymbol(localOrExportSymbol, node, checkMode);
30239+
let type = getNarrowedTypeOfSymbol(localOrExportSymbol, node);
3026030240
const assignmentKind = getAssignmentTargetKind(node);
3026130241

3026230242
if (assignmentKind) {

0 commit comments

Comments
 (0)