[Issue 12872] Feature request: Allow ref in arguments at the callsite

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jun 6 20:00:55 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12872

--- Comment #3 from Brad Anderson <eco at gnuk.net> ---
> 1. It's essentially pointless unless it's required that ref be at the call site, otherwise while ref at the call site then tells that that argument is accepted by ref, it tells you _nothing_ about any argument that isn't marked with ref - maybe it's being passed by ref, and maybe it isn't. ...

I agree that without enforcement this enhancement request is less useful than
it could be but it is still beneficial for at least two things:

- Self documenting the code. Even if just optional it'd be nice to see at a
glance that a reference is being taken. Sure, you could add /* passed by ref */
in there but it's noisier than it needs to be.
- Error when the callsite ref disagrees with the function. If you've called
with ref but the function doesn't accept ref then you've made an obvious error
and should be told about it. This is very similar to the override keyword which
is genuinely useful and catches real bugs. This wouldn't be a breaking change
so it'd be safe to enforce.

> 2. Even if we could made the changes, they would _not_ play nicely with UFCS.

Yeah, and that's the first thing I thought of that would be a problem with
enforcing it and one of the reasons I'm not requesting enforcement with this
enhancement request, only mentioning that it could be done in the future
potentially.

> ...doing something with scope...

I'd love for this to happen (I wish reference types were scope by default
personally). I don't think scope pointers should just replace `out` though.

Side rant: If we had warning levels like every other compiler in existence than
we could have people opt into an enforcement warning for this but I don't think
Walter will budge on that. :(

--


More information about the Digitalmars-d-bugs mailing list