Type of variable isn't widened inside a conditional inside a loop
See original GitHub issueBug Report
🔎 Search Terms
ts2367 widen loop
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
Edit: shorter version by gabritto
let code: 0 | 1 = 0
while (true) {
code = code === 1 ? 0 : 1
}
And in practice:
🙁 Actual behavior
Error
🙂 Expected behavior
Since code
could be changed in previous iterations of the loop, the condition is not always false, so there shouldn’t be any error.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Variable gets expanded in a loop with condition, how to "reset ...
I have a loop that scans through each data point and checks for a certain condition: for i in range(0, 10): if x...
Read more >Can I nest an if statement in a for loop? - MATLAB Answers
Yes, you can put an if statement inside a for loop. Your syntax for the for loop is invalid though, not the if...
Read more >for Loop
Condition is an expression that is tested each time the loop repeats. As long as condition is true, the loop keeps running. Increment...
Read more >Loops and Strings | Think Java | Trinket
The loops we have written so far have three parts in common. They start by initializing a variable, they have a condition that...
Read more >Javanotes 9, Section 3.4 -- The for Statement
The value of the variable is tested in the continuation condition, and the loop ends when this condition evaluates to false. A variable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Clarification on above comment: I was responding to someone who mistakenly thought
code
andcode2
in the repro code were the same variable. That comment has since been deleted, but I left my response in case someone else makes the same mistake.No, there are actually two variables:
code
andcode2
. The latter is a loop variable.