MarketSquare / robotframework-robocop

Tool for static code analysis of Robot Framework language
Apache License 2.0
178 stars 37 forks source link

[Bug] unused-variable not detected within IF block #1093

Open niallmcgee opened 1 month ago

niallmcgee commented 1 month ago

What happened?

robocop doesn't report unused-variable errors if the variable is set within a IF block. It seems to catch those in other control blocks (eg FOR) OK.

What command/code did you try to run?

*** Test Cases ***
TC1
  ${U1}  Set Variable  UNUSED1

  IF  True
    ${U2}  Set Variable  UNUSED2
  END

  FOR  ${_}  IN RANGE  1
    ${U3}  Set Variable  UNUSED3
  END

What is the full error message?

$ robocop -e missing-doc* foo.robot
/tmp/pyvenv/foo.robot:3:3 [I] 0920 Variable '${U1}' is assigned but not used (unused-variable)
/tmp/pyvenv/foo.robot:8:5 [I] 0920 Variable '${U3}' is assigned but not used (unused-variable)

What did you expect to happen instead?

I expected ${U2} to be reported as an unused variable as well as ${U1} and ${U3}

Operating System

Linux

Robocop version

5.2.0

bhirsz commented 1 month ago

It is most likely outcome of the logic where we try to find variables defined only for given scope (we don't always want to check if given variable is used if it's defined in specific place). I will look into it how it can be mitigated