-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Consider this code:
func foo() {
somethingThatRaisesAnException();
var x = new Bar();
finally {
x.close();
}
}
x in this case is not a nullable type, and thus can never be null. BType does not (presently) trace whether a particular statement can throw, and it also does not analyze at runtime whether a variable has been declared or not.
In practice, the variable is hoisted to the top of the function, and the declaration at the original location is replaced with an assignment. While the variable may contain uninitialized memory between the point of declaration and use, symbol use is tracked at compile time and no symbols may reference the variable when it contains an undefined value. That said, in the example above, there is no way to know whether somethingThatRaisesAnException() has in fact raised an exception and whether x contains a value.
As such, one or more of the following must be done:
- Ban local variable access from inside
finallyandcatchblocks. - Require that only nullable local variables (which default to
null) may be accessed withinfinallyandcatchblocks.