Open jwunderl opened 5 years ago
microsoft/pxt#6155 will fix this issue by not hoisting the variable to global.
To verify:
custom.ts
custom.ts
:
namespace light {
export function test() { }
}
main.ts
:
if (true) {
let light = 5
basic.showNumber(light)
}
main.ts
with the code below:
basic.forever(function () {
let light = "T"
if (Math.randomBoolean()) {
basic.showString(light)
} else {
basic.showString("F")
}
})
Nice! There are three other 'sub-bugs' under additional context that should probably all be addressed as well (e.g. that creating a variable light
in an on start
should get renamed, not produce an error); if your PR gets merged / fixes the main issue I'll file those separately~
This ticket may be about another aspect of variable naming/renaming but I've noticed screen
is problematic in Blocks, mentioned in MakeCode Forum: Reserved Words and confusing errors.
Describe the bug
When a variable is hoisted to global scope while decompiling, it can conflict with namespace names
To Reproduce Steps to reproduce the behavior:
or
Expected behavior
shouldn't break; gets renamed to
light2
Additional context
naming a variable light in blocks doesn't get renamed as well with the same error message / you can repro this bug with just blocks
really needs a better error message than "Cannot assign to '{}' because it is not a variable."
It took me a minute to recognize what the error was, because I didn't realize we had a
light
namespace - it looks like it only haslight.sendBuffer
exported?