Skip to content

Don't avoid caching variable types resolved using CheckMode.TypeOnly #59075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11985,7 +11985,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return false;
}

function getTypeOfVariableOrParameterOrProperty(symbol: Symbol, checkMode?: CheckMode): Type {
function getTypeOfVariableOrParameterOrProperty(symbol: Symbol, checkMode = CheckMode.Normal): Type {
const links = getSymbolLinks(symbol);
if (!links.type) {
const type = getTypeOfVariableOrParameterOrPropertyWorker(symbol, checkMode);
Expand All @@ -11994,7 +11994,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// to preserve this type. In fact, we need to _prefer_ that type, but it won't
// be assigned until contextual typing is complete, so we need to defer in
// cases where contextual typing may take place.
if (!links.type && !isParameterOfContextSensitiveSignature(symbol) && !checkMode) {
if (!links.type && !isParameterOfContextSensitiveSignature(symbol) && !(checkMode & ~CheckMode.TypeOnly)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cache suppression was introduced in #56753 and its original PR #50586 was first created before CheckMode.TypeOnly was even a thing (that was introduced in #54380 )

It would be an easy thing to miss either way but partially the bug was born because that PR was long-lived and a new concept was introduced to the checker in the meantime.

links.type = type;
}
return type;
Expand Down
21 changes: 21 additions & 0 deletions tests/cases/fourslash/quickInfoCircularityInLoop1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />

// @strict: true

// @Filename: user.ts
//// declare const line: string;
//// let test: string | null = null;
////
//// for (let i = 0; i < line.length; i++) {
//// const char = line[i];
//// if (test === char) {}
//// const [|alsoChar/*1*/|] = char;
//// test = alsoChar;
//// }

// if this circularity error ever goes awayt a different input code should be used here
verify.getSemanticDiagnostics([{
code: 7022,
message: "'alsoChar' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.",
}]);
verify.quickInfoAt("1", "const alsoChar: any");