holgerbrandl / r4intellij

An integration of the R programming language into Intellij IDEA
BSD 2-Clause "Simplified" License
148 stars 28 forks source link

unused variable in if else block: scoping issue? #196

Open stucash opened 5 years ago

stucash commented 5 years ago

It is not necessarily an issue but I wanted to raise it to you first before I ask it on SO as it might well be a plugin specific question.

if I have:

if (x == 1){
    a = 1
}else{
    a = 2
} 

the "a" in else block was marked as unused variable.

I understand R doesn't enforce scope on curly brackets, this means the a is available even outside the if statement. So why is the "a" in else statement an unused variable?

Note that I will have used "a" after this if else block.

holgerbrandl commented 5 years ago

No need to ask on SO, it's clearly a plugin issue. You're totally right about R scoping rules. The usage tracer in the plugin is simply not yet clever enough to "escape" the curly bracket else scope.

Though, I wonder why it does not fail in the same manner for the if scope...