rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
158 stars 46 forks source link

Incorrect validation error for dimmed vars #663

Closed TwitchBronBron closed 2 years ago

TwitchBronBron commented 2 years ago

image

function buildArray(numItems)
    dim result[3]
    for i = 0 to numItems
        result.push(i)
    end for
    return result
end function
TwitchBronBron commented 2 years ago

The fix for this is to add the variable name to the symbol table in the parser, here-ish: https://github.com/rokucommunity/brighterscript/blob/7ef24cf89a11ab3a659e106d27874040206d0e49/src/parser/Parser.ts#L1732

Here's an example of adding to the symbol table: https://github.com/rokucommunity/brighterscript/blob/7ef24cf89a11ab3a659e106d27874040206d0e49/src/parser/Parser.ts#L606

Also, add a unit test around here with something like this:

it('recognizes dimmed vars', () => {
    program.setFile(`source/file.brs`, `
        function buildArray(numItems)
            dim result[3]
            for i = 0 to numItems
                result.push(i)
            end for
            return result
        end function
    `);
    program.validate();
    expectZeroDiagnostics(program);
});