microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
711 stars 586 forks source link

Square root function works in sim but does not compile #4277

Open microbit-mark opened 3 years ago

microbit-mark commented 3 years ago

Describe the bug This program works in the simulator, but does not compile. image https://makecode.microbit.org/_1CJeg23D0bYX

Switching to JS sometimes results in an error message on line 1 image

You can workaround this eg by using the count variable instead of num, but I would still expect num to work

image

You can also set a new variable for the result od the calculation

image

riknoll commented 3 years ago

Minimal repro:

function square (num: number) {
    return num * num
}
let count = 0
square(count)

The issue seems to be in the return statement; the + and - operators work fine, most others fail.