ID:1623440
 
Keywords: associations, list, scope
BYOND Version:506
Operating System:Windows 7 Home Premium 64-bit
Web Browser:Chrome 35.0.1916.153
Applies to:Dream Daemon
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:
The documentation for the list() associations says

"When the index values happen to be text strings that satisfy all the requirements for variable names, this may also be written in a convenient short-hand:
var/list/lst = list(player = "James Byond", score = 2000)
"

However, it currently seems to be true that this applies to variables in the current scope, for example:
var/obj/O = new
list(null = 2, O = 4)
produces list("null" = 2, "O" = 4)

This could be considered intended behavior, but it makes it impossible to make a well-formatted list with objects or null as keys.

In particular I want to assign null as a key to associative lists in variable definitions, which is to say, outside of a code block. As long as list() is interpreting null in this way, that is impossible (excepting the workaround below).

Which is to say, if this is NOT a bug, I am going to reopen it as a feature removal request, because that shit is making it impossible to write legible code that works correctly.

Code Snippet (if applicable) to Reproduce Problem:
/mob/verb/test()
var/obj/O = new
O.name = "Object O"
var/obj/P = new
P.name = "Object P"
var/list/L = list(null = O, O = 3)
L[P] = 4
for(var/entry in L)
world << entry


Expected Results:
Variables and constants in scope could be used as indexes to list()

Actual Results:
The names of variables and constants in scope are used as text strings in an index to a list

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 swear it used to but I don't know

Workarounds:
For globals and null, global.[varname] prevents it from being read as a text string. The same is true for object scope and src.varname; I do not know if there is a similar "local scope" keyword for variables defined in the local proc.
You make a good case that when the var name is available in scope, it's worth using the var contents as the key instead of the name. This is probably compile-time behavior.

I also think a local scope operator would be nice.