Round trip to blocks and back causes semantic differences for local scoped variables
Open
@riknoll is already working on this.
Since Mar 14, 2018.
bug
decompiler
P2
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 641
- Avg merge
- 12h 4m
- Merged PRs (30d)
- 57
Description
Copy past the following program to typescript
function gameOfLife() {
for (let b = 0; b <= 4; b++) {
let count = 0
basic.showNumber(count + b)
count += 1
}
}
gameOfLife()
Output: 0,1,2,3,4
Convert to blocks and back to typescript.
let count = 0
function gameOfLife() {
for (let b = 0; b <= 4; b++) {
basic.showNumber(count + b)
count += 1
}
}
gameOfLife()
Now the count variable is hoisted and output is different (0,2,4,6,8). This is due to fact that set to count is not reset.
count is treated as global variable in typescript. But we shouldn't get rid of set at the local scope.
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.
Assessment
This issue has not been assessed yet.