ID:2798254
 
Resolved
The compiler will now correctly throw an error when trying to access proc-local vars such as src or usr inside of a static var declaration. This is because the related bug id:2798255 caused world.init to throw runtime errors. (This is a breaking change for some games, especially several variants of Space Station 13. For cases where this is being done to confirm a var is valid, use type::varname (the literal word "type") instead.)
BYOND Version:514
Operating System:Windows 10 Pro 64-bit
Web Browser:
Applies to:Dream Maker
Status: Resolved (515.1590)

This issue has been resolved.
Descriptive Problem Summary:
The right side of a
var/static/varname =
statement inside a proc that belongs to an object will behave as if src is instead the world datum.
Numbered Steps to Reproduce Problem:
Run the following project, zipped here: https://github.com/DamianX/byondbugs/raw/main/statics1/ statics1.zip
Code Snippet (if applicable) to Reproduce Problem:
/obj/canister
icon_state = "canister"

/obj/canister/proc/get_overlay()
var/static/a = icon_state
return a

//

/obj/tank/proc/get_overlay_icon_state()
return "this is never called"

/obj/tank/proc/get_overlay()
var/static/a = get_overlay_icon_state()
return a

/world/proc/get_overlay_icon_state()
return "world was here"

//

/world/New()
..()
var/obj/canister/C = new
world.log << json_encode(C.get_overlay()) // Outputs null

var/obj/tank/T = new
world.log << json_encode(T.get_overlay()) // Outputs "world was here"


Expected Results:
It should output "canister" and "this is never called", respectively.

Actual Results:
It outputs null and "world was here", respectively.

Does the problem occur:
Every time? Or how often? Every time.
In other games? Yes.
In other user accounts? Yes.
On other computers? Yes.

When does the problem NOT occur?
Don't know.

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.)
Don't know.

Workarounds:
Don't reference src in the initialization of a proc-local static var.
I believe using static in that sense makes it so it's always whatever it is at compile-time.
Lummox JR resolved issue (Not a bug)
How does any of this make sense?
/obj/tank/proc/get_overlay_icon_state()
return "this is never called"

/obj/tank/proc/get_overlay()
var/static/a = get_overlay_icon_state()
return a

/world/proc/get_overlay_icon_state()
return "world was here"

Can you look at that snippet and tell me that "a" should be set to "world was here"? The only reason the first example doesn't throw a runtime error is because of https://www.byond.com/forum/post/2798255, which makes attempting to read "world.icon_state" return null instead.
Lummox JR changed status to 'Open'
Reopened pending closure for 515. Static var initializations no longer allow src to be used at all in 515.
Lummox JR resolved issue with message:
The compiler will now correctly throw an error when trying to access proc-local vars such as src or usr inside of a static var declaration. This is because the related bug id:2798255 caused world.init to throw runtime errors. (This is a breaking change for some games, especially several variants of Space Station 13. For cases where this is being done to confirm a var is valid, use type::varname (the literal word "type") instead.)