wiremod/wire

Array indexing doesn't count as variable usage

Denneisk opened this issue · 5 comments

Description:
Using array access on a variable does not mark the variable as used, therefore making it warn as unused.

To Reproduce:

  1. Create an array or table in E2
  2. Set an index to anything
  3. Receive warning
let Table = table()
Table[1] = "test"

Expected behavior:
The variable should be marked as used.

It's not using the variable though.

It's not using the variable though.

It's may be ambiguous whether array access is being used meaningfully or not, but I think it's worth assuming that it is. I think it should be apparently how this could be used meaningfully.

function setup(Input:table) { // Warning: Unused variable: Input
    Input[1] = 123
}

Table = table()

setup(Table)

print(Table[1, number])

Also, with wirelinks:

let WL = Lamp:wirelink() // Labeled unused 
WL["On", number] = 1

In those cases where the table is provided by something out of scope, could allow this behavior

Then again this is kind of just complicating things since we'll have to make another exception for wirelinks I guess..

I'd be fine with reverting the behavior for now. I mean that's how it initially was til it was suggested to be changed to the opposite. Maybe in the future I'd bring it back fully featured as I planned here but in the analyzer where the complexity would be isolated.

Not a bug though so converting to discussion.