Open JoeStrout opened 1 year ago
OK, after discussion on Discord, here is the proposed behavior:
self
is always defined, but it will be null
in any context where the code is not inside a method invoked on an object.self
will produce a compile-time error.super
(except that super
is also null
when there is no further superclass).self
is used as a parameter name for anything but the first parameter.Point 1 is already the behavior in the C# (but not C++) version; C++ could be brought into line now. But points 2-4 are potentially code-breaking changes, and should probably wait for a larger MiniScript update.
There are optimizations in the C# code that were not ported to the C++ code, resulting in differences in behavior. In general, in C++ one can see
self
amonglocals
, monkey with its value, etc. In C#, it is stored separately in the call stack and not visible inlocals
; it's more like a proper keyword. (Though you can still assign to it, this assignment has little effect sinceself
lookups don't look in locals.)For an example of the difference in behavior, consider this function:
In C#, this prints
null
; in C++, this produces an Undefined Identifier error.So, it's clear the two implementations need to be brought back into agreement. And also that the optimizations are probably worth it for performance. However, we need to think carefully about exactly how we want
self
(andsuper
for that matter) to behave, in all the edge cases users might subject it to.