Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR TS2454: Variable is used before being assigned. #2838

Closed
ultraviolet-jordan opened this issue Apr 9, 2024 · 1 comment · Fixed by #2839
Closed

ERROR TS2454: Variable is used before being assigned. #2838

ultraviolet-jordan opened this issue Apr 9, 2024 · 1 comment · Fixed by #2839
Labels

Comments

@ultraviolet-jordan
Copy link

ultraviolet-jordan commented Apr 9, 2024

Bug description

I have updated my package version from 0.27.23 to 0.27.26.

There is now a compiling issue where:
ERROR TS2454: Variable 'zj' is used before being assigned.

Steps to reproduce

Here is the code block:

let zn: i32 = gMinlen;
let zvec: i32;
let zj: u8;
for (zvec = getBits(gMinlen, state); zvec > unchecked(gLimit[zn]); zvec = (zvec << 1) | zj) {
    zn++;
    zj = getBit(state);
}

The fix is simple like:

let zn: i32 = gMinlen;
let zvec: i32;
let zj: u8 = 0; // <=== FIX
for (zvec = getBits(gMinlen, state); zvec > unchecked(gLimit[zn]); zvec = (zvec << 1) | zj) {
    zn++;
    zj = getBit(state);
}

I do not know if this is intended or not, here is valid Java code for example:

int zn = gMinlen;
int zvec;
byte zj;
for (zvec = getBits(gMinlen, s); zvec > gLimit[zn]; zvec = zvec << 1 | zj) {
    zn++;
    zj = getBit(s);
}

Just wanted to report just in case. ty

AssemblyScript version

0.27.26

@CountBleck
Copy link
Member

This looks like a regression from #2826...sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@ultraviolet-jordan @CountBleck and others