What is the current state of scope and member functions?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Sep 11 00:12:29 UTC 2023


On Sunday, September 10, 2023 4:15:48 PM MDT Dennis via Digitalmars-d wrote:
> On Sunday, 10 September 2023 at 21:23:06 UTC, Jonathan M Davis
>
> wrote:
> > in both cases, so this doesn't seem to be a problem with
> > std.traits or my usage of it. Rather, it seems to indicate that
> > not only is scope not being inferred for popFront, but it's
> > being outright ignored when it's used explicitly.
>
> `scope` on a variable is implicitly removed when the variable's
> type has no pointers. This includes the `this` parameter, and
> your example struct has 0 members, so 0 pointers.
>
> I removed this behavior a few months ago for regular parameters
> because checking if the type had pointers caused forward
> reference errors: https://github.com/dlang/dmd/pull/14561
>
> The `this` parameter doesn't cause forward reference errors, but
> perhaps `scope` should also stay there for consistency and
> simplicity.

Well, I don't know what the overall pros and cons of the current behavior
are, but I found it to be very confusing. AFAIK, no other attributes
magically disappear like that. And having the behavior between the this
parameter and explicit parameters differ is likely to add to the confusion
for folks as well. DIP 1000 is already arguably overly complicated for what
it buys us, and I'd think that removing unnecessary complexity with regards
to what's going on with scope would be a good thing.

- Jonathan M Davis





More information about the Digitalmars-d mailing list