Skip to content

Incorrect type optimizations in loop conditions #276

@GarboMuffin

Description

@GarboMuffin

Was looking over the quicksort snapshot changes again in #275 and something felt weird. Found this minimal test case

Image

Before #275

b0.value = p0;
while (!(("" + listGet(b1.value, b0.value)).toLowerCase() === "something".toLowerCase())) {
b0.value = ((+b0.value || 0) + 1);
}

After #275

b0.value = p0;
while (!(("" + (b1.value[(b0.value | 0) - 1] ?? "")).toLowerCase() === "something".toLowerCase())) {
b0.value = ((+b0.value || 0) + 1);
}

It's now assuming that b0.value is always a number but it's getting initialized to p0 which could instead be set to "random" or "last"

tw-loop-condition-optimization-gh-276.sb3.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions