Skip to content

Round trip to blocks and back causes semantic differences for local scoped variables #3979

Open

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions