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. #2840

Open
ultraviolet-jordan opened this issue Apr 11, 2024 · 2 comments
Open

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

ultraviolet-jordan opened this issue Apr 11, 2024 · 2 comments
Labels

Comments

@ultraviolet-jordan
Copy link

Bug description

I have updated my package version from 0.27.23 to 0.27.27.

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);
}

It seems this problem is still occurring, if it helps, this is the full source code to my project using this:
https://github.com/2004scape/Client2/blob/main/assembly/bz2.ts

I've cleaned everything so I don't believe it is me.

@CountBleck @HerrCai0907

Ty!

AssemblyScript version

0.27.27

@HerrCai0907
Copy link
Member

HerrCai0907 commented Apr 11, 2024

It is fine for me. could you check the as version again?
image

@ultraviolet-jordan
Copy link
Author

Hm something strange happening, if it's just me somehow then no problem, sorry lol
image

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

No branches or pull requests

2 participants