microsoft / microsoft/TypeScript
CFA should consider branch flags
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
This is a suggestion to improve the CFA. It would be good if TypeScript considered branch flags when analysing code paths.
function f() {
let text: string;
let hasTakenVerySpecificBranch = false;
if (0.5 < Math.random()) {
if (0.5 < Math.random()) {
if (0.5 < Math.random()) {
hasTakenVerySpecificBranch = true;
text = '';
}
}
}
if (!hasTakenVerySpecificBranch) {
text = ''
}
console.log(text); // Error 'text' is used before assigned.
}
We assign text on all possible code paths above. And it shouldn't error above.
A branch flag is simply a boolean variable that is considered when doing the control flow analysis.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the TypeScript example and confirming the current definite-assignment error. Read the compiler's control-flow analysis implementation and existing tests for definite assignment and boolean narrowing. Done means branch-flag conditions are incorporated without regressing related control-flow behavior, with tests covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100