Control flow analysis for element access with variable constant-like index in for statements#60715
Control flow analysis for element access with variable constant-like index in for statements#60715Andarist wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…index in for statements
| function isSymbolAssignedInForStatementBody(symbol: Symbol) { | ||
| const forStatement = getRootDeclaration(symbol.valueDeclaration!).parent.parent; | ||
| Debug.assert(isForStatement(forStatement)); | ||
| return !isPastLastAssignment(symbol, forStatement.statement); | ||
| } | ||
|
|
||
| function isUsedInForStatementBody(symbol: Symbol, location: Node) { | ||
| const forStatement = getRootDeclaration(symbol.valueDeclaration!).parent.parent; | ||
| Debug.assert(isForStatement(forStatement)); | ||
| return location.pos >= forStatement.statement.pos && location.end <= forStatement.statement.end; | ||
| } |
There was a problem hiding this comment.
I'd love to combine those 2 but I've failed so far to figure out an elegant function name for a function that would do both 😅
|
@typescript-bot test it |
|
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jakebailey Here are the results of running the top 400 repos with tsc comparing Something interesting changed - please have a look. Details
|
|
The snabbdom break isn't harmful. It boils down to a code like this: declare function isPrimitive(s: any): s is string | number;
export function test() {
let c: any;
for (let i = 0; i < c.length; ++i) {
if (isPrimitive(c[i])) {
const target: string | undefined = c[i];
}
}
}The problem is that declare function isPrimitive(s: any): s is string | number;
declare const foo: any;
if (isPrimitive(foo)) {
foo; // string | number
}Since now this constant-like |
This is a small extension of #57847
closes #58803
letvariables in for loops are special, despite them being mutable and "shared" for the loop - each iteration gets its own unique copy of that variable. A mutation in the incrementor has no effect on the loop's body so, to the best of my understanding, it can safely be ignored.