This bug report has helped to reveal three individual bugs or problems. 1 and 2 are related. 3 is a whole other issue.
1. The runtime access operator : can make the compiler throw an error due to type checking a type that doesn't exist.
2. You can typecast an object's variable to a non-existent type, and it compiles without an error.
3. The look-down path operator : does not function exactly as the DM Guide claims it does. It says that at the beginning of a path, it causes the search to take place from the root. If that's the case, then it must have been broken, and the only way it could feasibly work is if it functioned according to this example:
mob
:thing // If we do a look-down search for thing,
obj
thing // then this thing will be found only if
mob
thing // this thing does not exist.
You can disregard the rest of this original post simply because it may be misleading.
Descriptive Problem Summary:
By using path operators, it is possible to define whole new object types, procs, and vars from within another type's definition. The problem is that vars defined this way are somehow only "partially visible" to the compiler. Such vars are actually compiled and can be accessed indirectly through the vars list, but if you try to access them normally through either . or :, the compiler just won't recognize them, and refuses to compile, throwing an "undefined type" error.
This seems to be a very ancient bug, present in the earliest build available. Apparently defining vars this way worked fine at some point when the DM Guide was being written, because you can see an example of it on Chapter 6, Section 15.3. The example shown there is basically broken, because you can't access the dragon_meat var without using the vars list. It just won't compile if you try to use the normal methods of access.
Numbered Steps to Reproduce Problem:
1. Compile and run the following code:
mob
var
/obj/myobj/var/myvar {myvar = "Impossible!"}
obj/myobj/myobj = new
verb
doesitwork()
set name = "Does this even work?"
// src << myobj:myvar // Doesn't compile.
src << myobj:vars["myvar"] // Actually, it does!
2. Click "Does this even work?" and watch the impossible happen.
3. Next, try uncommenting the commented line of code and see that it doesn't compile, even though it should.
Expected Results:
You can use . or : to read and set vars that were defined at an arbitrary point within another object type's definition.
Actual Results:
The compiler throws an "undefined type" error, even though it can be proven that the var is defined.
Does the problem occur:
Every time? Or how often?
It occurs every time.
In other games?
N/A
In other user accounts?
N/A
On other computers?
N/A
When does the problem NOT occur?
It always occurs.
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 can't really tell. The builds don't go back far enough. I guess that it might have broke somewhere between 2.0 and 354.
Workarounds:
Use the name of the var as an index to the vars list, like vars["varname"], quotes included.