Linear types are quite a powerful feature of type systems that ensure that "linear values" are used exactly once.
For example,
fn foo(): let handle = acquire_linear_value() // ... close(handle) The compiler would force passing handle to some function like close before the function ends; otherwise, handle would not have been used!
This seems fine until other features, which may non-deterministically alter the usual control flow, are introduced in the language. An example of such a feature would be exceptions. E.g.,
fn foo(): let handle = acquire_linear_value() // ... bar() // may throw // ... close(handle) Assuming that bar is a function that may diverge the usual control flow, handle would no longer be guaranteed to be used exactly once.
Can both features coexist in the same language? If so, how?