Union Return type consistency - #1508
Conversation
| return "hello" | ||
| end function | ||
|
|
||
| function test2() as double |
There was a problem hiding this comment.
I think brightscript would coerce an integer into a longinteger, which would technically not be expected behavior. Should this one be dynamic?
@chrisdp what do you think of this one?
There was a problem hiding this comment.
This is double or float ... that goes to double.
integer or longinteger (test3) -> longinteger
There was a problem hiding this comment.
Sorry, yeah I was talking more generally about those use cases. Must have selected the wrong one. My concern applies to both integer or longinteger -> longinteger and double or float -> double.
If a function returns a float sometimes, or a double other times, I think the original underlying return type should be respected at runtime. By transpiling to the "more precise" data type, it'll prevent the less precise data type from ever leaving the function. There could be code on the outside looking for "is this a float" or "is this a double" that wouldn't be properly respected with this.
My vote would be for these two situations to transpile to dynamic.
Fixes #1488
If a union can be reduced to a primitive type, use that type for transpilation.