Warn for (list)string_var or (list)key_var in LSO.
Closed this issue · 0 comments
Sei-Lisa commented
LSO has a weird bug. Variables of type string
may have values of type key
, and vice versa. This happens with implicit or explicit type casts. For example:
key x = llGenerateKey();
string mystring = x; // implicit type cast
string myotherstring = (string)x; // explicit type cast
After the above code, both mystring
and myotherstring
hold values of type key
, despite the variable being of type string
. This is actually only visible when they are type cast to list
:
list mylist = (list)mystring;
if (llGetListEntryType(mylist, 0) == TYPE_STRING) llOwnerSay("the list entry is a string");
else if (llGetListEntryType(mylist, 0) == TYPE_KEY) llOwnerSay("the list entry is a key");
else llOwnerSay("not string nor key?!");
The above code prints "the list entry is a key" in LSO (in Mono it correctly prints "the list entry is a string").
A workaround is to use square brackets instead of a typecast:
list mylist = [mystring];
if (llGetListEntryType(mylist, 0) == TYPE_STRING) llOwnerSay("the list entry is a string");
else if (llGetListEntryType(mylist, 0) == TYPE_KEY) llOwnerSay("the list entry is a key");
else llOwnerSay("not string nor key?!");
The above code correctly prints "the list entry is a string" in both LSO and Mono.
It would be nice if lslint warned about typecasts of string or key variables to list when in LSO mode.