I am curious whether initializing a variable of type T using the following code is any good for type stability. The type is usually alot more complex than the example used below with significant allocations and a dependence on the conditions, so I don’t want to initialize a full instance before the if-statement with dummy input, too much waste. On the other hand, if declared inside the if statement, it will not be visible outside, and that’s a no go. I also couldn’t find a way to initialize a global-but-not-too-global variable inside an if statement, so the following seems like the next most reasonable approach.
a = nothing if b > 1 a = T(1) else a = T(2) end