First Draft: ref For Variable Declarations

Walter Bright newshound2 at digitalmars.com
Sat Apr 13 16:15:49 UTC 2024


On 4/12/2024 3:13 PM, Richard (Rikki) Andrew Cattermole wrote:
>> Scope would apply to what the ref points to, not what the ref is.
> So this is introducing a non-transitive scope.

That's always been true of scope.


> This sounds like a consequence due to not having scope on the variable.

That's correct.

> Hmm, non-transitive scope, now that I'm thinking about this, it seems like the 
> limitation is in the lack of DFA, not in the type system. Another thing for type 
> state analysis DFA I suppose.

I don't think it's possible to do that for data structures.

> Ugh what?
> 
> wrapper died, item still alive.
> 
> You shouldn't be able to access item after that.
> 
> This would likely be the primary use case to using ref on a variable declaration 
> and people will try it as soon as they learn they can put ref on a variable.

Having the data structure control its contents is the usual method to deal with 
that.


> Borrowing memory from other variables will be attempted, and will be attempted 
> often and that will cause frustration as an obvious feature isn't supported.

This is not a proposal to add DFA.



More information about the dip.development mailing list