For example:
@outputs DEFAULT_ENTITY:entity
function entity defaultEntity() { }
local NULL = noentity()
print(DEFAULT_ENTITY ? "[1] is operator failed!" : "[1] is operator passed.")
print(defaultEntity() ? "[2] is operator failed!" : "[2] is operator passed.")
print(NULL ? "[3] is operator failed!" : "[3] is operator passed.")
print("(DEFAULT_ENTITY == DEFAULT_ENTITY) " + (DEFAULT_ENTITY == DEFAULT_ENTITY ? "passed." : "failed!"))
print("(DEFAULT_ENTITY == defaultEntity()) " + (DEFAULT_ENTITY == defaultEntity() ? "passed." : "failed!"))
print("(DEFAULT_ENTITY == NULL) " + (DEFAULT_ENTITY == NULL ? "passed." : "failed!"))
print("(defaultEntity() == defaultEntity()) " + (defaultEntity() == defaultEntity() ? "passed." : "failed!"))
print("(defaultEntity() == NULL) " + (defaultEntity() == NULL ? "passed." : "failed!"))
print("(NULL == NULL) " + (NULL == NULL ? "passed." : "failed!"))
Output:
[1] is operator passed.
[2] is operator passed.
[3] is operator passed.
(DEFAULT_ENTITY == DEFAULT_ENTITY) passed.
(DEFAULT_ENTITY == defaultEntity()) passed.
(DEFAULT_ENTITY == NULL) failed!
(defaultEntity() == defaultEntity()) passed.
(defaultEntity() == NULL) failed!
(NULL == NULL) passed.
My guess would be some of them are nil, some are an invalid or null entity.
They should of course all compare as equal, since E2 otherwise treats them as equal
There are two bugs in here I think.
(defaultEntity() == NULL) failed!
1: E2 function which does not return any value (in this case it is entity=defaultEntity() function, which I think return a nil value at the moment as there is no return statement (yeah, currently the code I have posted above is valid E2) and that nil value in GLua is not equal to NULL entity obviously - different types (print(nil == NULL, type(nil), type(NULL)) -- false nil Entity).
(DEFAULT_ENTITY == NULL) failed!
2: Any variable of type Entity (that is persistent or an output) which is unassigned -- is not equal to NULL entity (noentity()).
I think there is a report for the 1st bug, while this is issue about the 2nd.
we can change all about what noentity() returns or what variables start with and still have a problem.
What about valid entities that become invalid? They'll evaluate as false, so I think they should still be in the same equivalence class as nil.
where are unit tests when we need them
Doesn't registerType have the ability to add an input and output serializer? Couldn't we make it so even if you're accessing the output/input from within the E2 it goes through those as well?
Also the UDF return issue should be fixed with #1095, or at least if it ever gets merged.
I believe this is a duplicate of #1374
Most helpful comment
where are unit tests when we need them