Skip to content

Fails to find + or - for math on numbers in a loop #1413

@dv-extrarius

Description

@dv-extrarius

Under the new solver and --!strict, simple math in a loop seems to confuse it and it complains about failing to find operators + and -

local function KahanSum(values: {number}): number
    local sum: number = 0
    local compensator: number = 0
    for _, value in values do
        local y = value - compensator
        local t = sum + y
        compensator = (t - sum) - y
        sum = t
    end
    return sum
end

It throws errors on every line in the loop but the last. If I manually type y as local y: number = value - compensator the errors vanish.

Another snippet that triggers a similar issue for other operators:

local function HistogramString(values: {number})
    local histogram = {}
    values = table.clone(values)
    table.sort(values)

    local count = #values
    local range = (count - 1)

    local digitIndex = range // 2 + 1
    while digitIndex < count and values[digitIndex] == 0 do
        digitIndex = count - ((count - digitIndex) // 2)
    end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnew solverThis issue is specific to the new solver.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions