UFCS for D

deadalnix deadalnix at gmail.com
Fri Mar 30 05:22:12 PDT 2012


Le 30/03/2012 14:13, Steven Schveighoffer a écrit :
> On Fri, 30 Mar 2012 08:10:14 -0400, deadalnix <deadalnix at gmail.com> wrote:
>
>> I would expect this not to work, because bar isn't defined in module1
>> and template are supposed to use declaration scope, not instantiation
>> scope (unless it is mixin template).
>
> Right, I think it's the way it works now. But consider that the template
> instantiation *does* pull in some stuff from the instantiation scope
> (i.e. the template's module may not import the type being used to
> instantiate). I think it would be OK for the compiler to consider UFCS
> functions from the type's defining module as well, since you cannot
> instantiate the template for that particular type without having
> imported that module (i.e. it's guaranteed to instantiate the same no
> matter what module does it first).
>
> -Steve

It does pull information from it's own scope and what is passed as 
parameter. So it would still fail for the UFCS case.

I don't see a clean solution for that, because of ambiguities. That 
something that is not new and not specific to UFCS.

Immagine you want to define your own to!xxx() for your type xxx. (It is 
dumb case because you have toString, but an interesting exercise because 
for your own stuff, not something that is specified in the language - 
like toString - the same could happen with no easy solution.


More information about the Digitalmars-d-announce mailing list