The next iteration of scope

via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 16 10:17:29 PDT 2015


On Monday, 16 March 2015 at 13:55:43 UTC, Marc Schütz wrote:
> On Monday, 16 March 2015 at 04:00:51 UTC, Zach the Mystic wrote:
>> "Functions and methods can be overloaded on scope. This allows 
>> efficient passing of RC wrappers for instance..."
>>
>> How does the compiler figure out which of the variables it's 
>> passing to the parameters are `scope` or not? Does the caller 
>> try the scoped overloads first by default, and only if there's 
>> an error tries the non-scoped overloads? If so, what causes 
>> the error?
>
> Hmm... I guess it only makes sense for postblits and 
> destructors. I'm not sure about constructors and opAssign, so 
> I'll leave these out for now. I've changed the wiki page 
> accordingly.

To clarify: When a scoped variable is assigned to a location with 
infinite lifetime (`static`), this assignment will fail unless 
the type provides an assignment operator/postblit that is 
correctly annotated. Depending on whether `this` is implicitly 
passed as `scope` or not, this annotation needs to be `scope`, 
otherwise, conversely, the non-scope overload needs to be marked 
as `static`. Likewise, a scope variable without a destructor 
accepting scope cannot be destroyed.

I added the rules for overloading in the wiki. Now that I'm 
seeing clearer, I've restored the part where it says that all 
functions can be overloaded. No need to restrict it artificially.


More information about the Digitalmars-d mailing list