UFCS for D

Walter Bright newshound2 at digitalmars.com
Fri Mar 30 12:36:51 PDT 2012


On 3/30/2012 12:11 PM, Steven Schveighoffer wrote:
> On Fri, 30 Mar 2012 14:27:43 -0400, Walter Bright <newshound2 at digitalmars.com>
> wrote:
>
>>
>> I would argue that:
>>
>> 3. An extension method for an argument of type template parameter T will be
>> looked up only in the instantiation scope.
>
> I don't think you looked at my counter case in detail. Your idea leads to two
> different instantiations of tmpl!Foo having two different implementations,
> depending on which extension methods you include. In fact, in one place, the
> instantiation might succeed, but in another, the instantiation might fail.

Yes, you're right. I missed that nuance. I don't really know how to fix it.


> Given that the compiler simply trims out identically defined symbols, assuming
> they are the same, this could have disastrous consequences. You could end up
> with code being different based on the link order, or possibly arbitrary
> decisions made by the linker!
>
> My argument is that the one thing in common is that the module that defines the
> type has to have been included. I think you would agree that the one truth we
> must maintain is that X!Y must be implemented exactly the same no matter what
> module instantiates it.
>
> I realize that the compiler likely doesn't keep enough information to know what
> functions would fall under the rules I specified, so this is probably a
> difficult change to effect. But it could be an incremental change later.
>
> -Steve



More information about the Digitalmars-d-announce mailing list