wiremod / wire

Garry's Mod add-on that allows users to wire up components in order to make more elaborate automatic and user-controlled contraptions.
http://www.wiremod.com
Apache License 2.0
551 stars 331 forks source link

[E2] Internal error but no compiler error/warning when trying to do operations on not-yet-defined variable #3016

Open CheezusChrust opened 5 months ago

CheezusChrust commented 5 months ago

Describe the bug sv: Expression 2 (oops): Internal error 'entities/gmod_wire_expression2/core/number.lua:81: attempt to perform arithmetic on local 'lhs' (a nil value)' at line 8, char 1

To Reproduce

@name bug
@strict

function bruh() {
    Piss = 5
}

print(Piss + 2)

Expected behavior A compiler error or something

Fasteroid commented 1 month ago

Oh god are you the same cheeze that made the horribly uncompressed button textures?

Vurv78 commented 3 weeks ago

This is intentional since @strict doesn't replace globals every time now, but I think it really should initialize on the first go, at least, since that wouldn't cost much.

That or make the compiler not stupid and include the scoping when deciding if a variable has already been assigned to. I'd prefer that.

ie https://github.com/wiremod/wire/blob/4038ae0a5cd2335d6af52d6baafb6fbc70d74e21/lua/entities/gmod_wire_expression2/base/compiler.lua#L1023 should also write down the scopeid it was initialized at (careful to only assign if currentid < assignid), then just check if assignid < currentid when checking if the variable is initialized or not.

Then you'll at least get a warning in advance.