UFCS for struct opCall?

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 9 11:49:44 PDT 2013


On Mon, 08 Apr 2013 19:48:12 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> On request by Maxim Fomin I ask an opinion here. This is a very small  
> enhancement request, that for me is borderline bug report (so originally  
> I didn't plan in showing it in the main D newsgroup):
>
> http://d.puremagic.com/issues/show_bug.cgi?id=9857
>
>
>
> Maybe this should be valid:
>
>
> struct Foo {
>      int opCall(bool b) {
>          return 0;
>      }
> }
> void main() {
>     Foo foo;
>     auto b1 = foo(true); // OK
>     auto b2 = true.foo;  // Error
> }
>
>
> dmd 2.063alpha gives:
>
> temp.d(9): Error: no property 'foo' for type 'bool'

I agree, it should be valid.

A rewrite should be a rewrite, not some special-cased thing.

The rules are simple:

given a.b(...)

1. if a.b(...) compiles, then call it
2. otherwise if b(a, ...) compiles, call it.
3. otherwise, error.

-Steve


More information about the Digitalmars-d mailing list