robotcodedev / robotcode

RobotFramework support for Visual Studio Code
https://robotcode.io
Apache License 2.0
177 stars 14 forks source link

[BUG] bad warning about variable not used in IF ELSE statement #289

Closed gohierf closed 3 weeks ago

gohierf commented 1 month ago

Describe the bug A variable is considered not used if defined with VAR statement in both IF and ELSE clause.

To Reproduce Steps to reproduce the behavior:

  1. Paste example code
  2. Wait for diagnostic to finish
  3. Observe warning about variable not used in IF block.

If possible, add some example source code like:

*** Keywords ***
My Keyword
    [Documentation]    Unused variable error and collapsing error
    [Arguments]    ${arg}
    IF    $arg == 1
        VAR    ${my var}    foo
    ELSE
        VAR    ${my var}    bar
    END
    RETURN    ${my var}

Expected behavior No warning.

Screenshots/ Videos image

Logs NA

Desktop (please complete the following information):

Additional context I get a warning if the same variable is defined in an ELSE IF bloc.

I get the same warning if the variable is used in a keyword rather than RETURN statement.

gohierf commented 3 weeks ago

On a similar topic, I get "variable not used" for counter in this case:

image

*** Test Cases ***
My Test
    VAR    ${counter}    ${0}
    WHILE    True    limit=2s
        Log To Console    ${counter}
        VAR    ${counter}    ${counter+1}
    END