SpacemanDMM icon indicating copy to clipboard operation
SpacemanDMM copied to clipboard

Lint for non-const switch range cases

Open ike709 opened this issue 3 years ago • 0 comments

See http://www.byond.com/forum/post/2750423

tl;dr BYOND doesn't throw a compiler error if you use a non-const in a switch range case (see code below) and instead silently uses null in place of the non-const. Since lummox hasn't fixed it after over 5 months I'm hoping someone will add a lint for it.

Example code:

proc/test_code()
    var/T = 5 // Making this "var/const/T = 5" fixes it. Also, to clarify, this bug applies to non-local vars too.
    switch(1)
        if(T to 10e31)
            world.log << "Yes" // Actual result, because T is actually "null"
        else
            world.log << "No" // Expected result, because 1 isn't in the range of 5 to 10e31. Well actually the real expected result is a compiler error for T being non-const.

This bug only applies to range cases, aka the ones using A to B.

ike709 avatar May 23 '22 01:05 ike709