pxt-arcade icon indicating copy to clipboard operation
pxt-arcade copied to clipboard

variable scoping failure with anonymous function parameter referencing new decl

Open jwunderl opened this issue 2 years ago • 0 comments

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:

  1. Go to https://makecode.com/_7doPvH7MVez5
  2. see error only on call to 'b'

Expected behavior

not break :/

jwunderl avatar Apr 15 '22 20:04 jwunderl