On Monday, 23 January 2023 at 08:49:50 UTC, Richard (Rikki) Andrew Cattermole wrote:
>Vector!int vector;
vector ~= 3;
auto borrowed = vector[0];
func(borrowed);
void func(scope ref int value) {
}
Basically right now we're missing the lifetime checks surrounding borrowed & function parameter. Everything else is do-able right now, even if it isn't as cheap as it could be (like RC eliding).
I'm writing a language with borrowing and ref counting (Neat), and this is not a valid borrow. Basically you don't want to take on borrowing with variables that are mutable by default, because then you're asking for things like:
Vector!int vector;
vector ~= 3;
void evil() { vector = Vector!int.init; }
auto borrowed = vector[0];
func(borrowed);
void func(scope ref int value) {
// destroy the last non-borrowed reference to vector, where is your God now?
evil;