pxt-arcade
pxt-arcade copied to clipboard
variable scoping failure with anonymous function parameter referencing new decl
Describe the bug
variable scoping errors out with anonymous function param references the variable the function returns, only when in function scope
// works
const renderable = scene.createRenderable(1, () => {
renderable.destroy();
})
// works
if (true) {
const renderable = scene.createRenderable(1, () => {
renderable.destroy();
});
}
// works
function a() {
let renderable: scene.Renderable;
renderable = scene.createRenderable(1, () => {
renderable.destroy();
})
}
a();
// breaks
function b() {
const renderable = scene.createRenderable(1, () => {
renderable.destroy();
});
}
b();
To Reproduce Steps to reproduce the behavior:
- Go to https://makecode.com/_7doPvH7MVez5
- see error only on call to 'b'
Expected behavior
not break :/