Returning a reference to be manipulated

Dennis dkorpel at gmail.com
Sat Apr 15 14:10:57 UTC 2023


On Saturday, 15 April 2023 at 13:20:09 UTC, kdevel wrote:
> Under which circumstances is it a mistake to insert the 
> `return` at the indicated position? If there are none why can't 
> it be done implicitly (automatically)?

It could be done in the easy example you posted, but generalizing 
it is harder.

When importing a module, the compiler currently doesn't need to 
analyze function bodies to get the signature of regular 
(non-auto/template) functions, which would have to change. 
Programmers can also currently rely on the fact that the 
signature they see is the signature they get, but not any longer.

The identity function is really simple, but as soon as control 
flow (if-statements) come into play, the annotations and their 
inference become a conservative approximation, which might give 
false positives in `@system` code. There would need to be a 
second system, one which assumes the best instead of assuming the 
worst.

This adds complexity, just to add some 'intermediate' safety 
between `@system` and `@safe` in a few cases. It's better to keep 
the rules simple and consistent.



More information about the Digitalmars-d-learn mailing list