Proposal
Enhance the null coalescing operator to also check for <uninitialized>. Either invalid or <uninitialized> will result in the alternate being selected. Example:
thing = notDefined
result = thing ?? "default"
Will now transpile to:
thing = notDefined
result = thing
if type(thing) = "<uninitialized>" or thing = invalid
result = "default"
end if
Justification:
Developer intent for null coalescing is to pick an alternate value if the consequent value is not defined. invalid and <uninitialized> both represent this concept of "not defined", and as such, we can produce safer code while maintaining the intent behind null coalescing.
Example:
thing = notDefined
result = thing ?? "default"
In the current releases of BrighterScript, this throws an exception when comparing thing (which is <uninitialized>) to invalid
Questions:
- should this be considered a breaking change or a bugfix? (i.e. should this only be added to v1, or can we also add to v0)
Proposal
Enhance the null coalescing operator to also check for
<uninitialized>. Eitherinvalidor<uninitialized>will result in the alternate being selected. Example:Will now transpile to:
Justification:
Developer intent for null coalescing is to pick an alternate value if the consequent value is not defined.
invalidand<uninitialized>both represent this concept of "not defined", and as such, we can produce safer code while maintaining the intent behind null coalescing.Example:
In the current releases of BrighterScript, this throws an exception when comparing
thing(which is<uninitialized>) toinvalidQuestions: