afw-org / afw

Adaptive Framework
https://afw.tools
MIT License
4 stars 1 forks source link

By default, return 'undefined' instead of 'null' if a return statement is missing #51

Closed mike000000000 closed 1 year ago

mike000000000 commented 1 year ago

Currently, 'null' is returned when there is not a 'return' statement or anything else that produces a return value. This should be changed to 'undefined' in these situations. It also might be that 'undefined' should be returned in some other cases as well which will be documented in this issues as found.

As a note, 'null' was historically being returned because we didn't have an 'undefined'. Now that we do, 'undefined' is more appropriate.

Also, change functions that currently have a data type of 'null' to be 'void' as appropriate.

mike000000000 commented 1 year ago

I had to mark src/afw/generate/object/AdaptiveFunctionTest/compiler_assert.json as "implemented": false because the result value needed to be undefined and there's not a way to put that in json.

mike000000000 commented 1 year ago

@JeremyGrieshop I didn't see anything in the app that needed to change to support function return type 'void', but just mentioning it here in case you think of anything. Other than that, all of the built-in functions that used to return 'null' now return 'undefined' and their return data type is 'void'. So it can be closed after any doc changes (if there are any) are made.

One other note, see the comment above about compiler_assert.json. I didn't know if you want to have a way to say result is undefined or just not worry about it.

JeremyGrieshop commented 1 year ago

Do we need to do something similar to how we came up with result and resultDataType in order for other languages to turn JSON back into workable values, such as undefined, NaN, Infinity?

mike000000000 commented 1 year ago

Do we need to do something similar to how we came up with result and resultDataType in order for other languages to turn JSON back into workable values, such as undefined, NaN, Infinity?

This is a JSON object that your python code reads and generates tests, so libafw is not involved in this particular case. However, let's discuss when it is.

mike000000000 commented 1 year ago

Fix so that expect: undefined does not match on thrown error.

JeremyGrieshop commented 1 year ago

The impacted test for compiler_assert has been fixed and moved into src/afw/tests/generated now. I believe this issue can be closed.