ID:2830902
 
BYOND Version:514
Operating System:Windows 10 Pro 64-bit
Web Browser:Firefox 106.0
Applies to:Dream Maker
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:
Dream Maker emits an unused variable warning when a variable is only used for accessing a scoped static variable.

Numbered Steps to Reproduce Problem:
1. Write code where the only time a variable is referenced in its scope is to access a static var (see snippet for example).
2. Compile the code.
3. Receive an unused variable warning??

Code Snippet (if applicable) to Reproduce Problem:
/mob/var/obj/companion
/obj/best_friend/var/static/foo = "best friends foorever"
/obj/best_friend/var/static/bar = "barst friends forever"

// Emits a warning: only time BFF is used is to access /obj/best_friend::foo
/mob/proc/best_friend_foo()
if(istype(companion, /obj/best_friend))
var/obj/best_friend/BFF = src.companion
// ^ this line emits the warning "BFF: variable defined but not used"
return BFF.foo
return null

// Doesn't emit a warning; the istype(BFF) counts as a usage.
/mob/proc/best_friend_bar()
var/obj/best_friend/BFF = src.companion
if(istype(BFF))
return BFF.bar
return null

/world/New()
var/mob/m = new
m.companion = new /obj/best_friend
world.log << m.best_friend_foo()
world.log << m.best_friend_bar()


Expected Results:
Emits zero warnings and zero errors. Prints both "best friends foorever" and "barst friends forever".

Actual Results:
Emits a BFF: variable defined but not used warning. Still prints both strings as expected.

Does the problem occur:
Every time? Or how often?
Every time you do this.
In other games?
If they do this, yes.
In other user accounts?
Yes.
On other computers?
Yes.

When does the problem NOT occur?
When there are any other references to the variable in that scope.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
I'm not sure when it was introduced, but it happens in both 514 and 515.

Workarounds:
Adding any other code that uses that variable will suppress the warning, like if(istype(var_name)).