Uniform call syntax for implicit this.

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 3 10:42:30 PST 2011


On Thursday, February 03, 2011 09:54:44 Michel Fortin wrote:
> On 2011-02-03 12:43:12 -0500, Daniel Gibson <metalcaedes at gmail.com> said:
> > Am 03.02.2011 15:57, schrieb Michel Fortin:
> >> On 2011-02-02 23:48:15 -0500, %u <dflgkd at sgjds.com> said:
> >>> When implemented, will uniform call syntax work for the "this"
> >>> object even if not specified?
> >>> 
> >>> For example, will foo() get called in the following example?
> >>> 
> >>> void foo(A a, int b) {}
> >>> 
> >>> class A {
> >>> void test() {
> >>> this.foo(10);
> >>> foo(10);
> >>> }
> >>> }
> >> 
> >> I think it should work.
> > 
> > I think foo(10) should *not* be equivalent to foo(this, 10).
> 
> Personally, I'm not sure whether the uniform call syntax will be this
> much useful or not, but if it gets implemented I think foo(10) should
> be equivalent to foo(this, 10) in the case above. That said, it should
> not be ambiguous: if there is a member function foo and a global
> function foo and both matches the call, it's ambiguous and it should be
> an error.
> 
> Can this work in practice? We probably won't know until we have an
> implementation to play with.

Except that if you have both a member function foo and a free function foo, how 
can you tell the compiler which to use? Assuming that foo(10) unambigously calls 
the free function, then you have a way to call the free function - or if 
.foo(10) calls the free function, then you have a way to call the free function. 
But how would you call the member function? this.foo(10) is ambiguous, and what 
other way is there? It seems to me that we'll be forced to make it so that if 
there's any ambiguity between a free function and a member function, then it's 
the member function that gets called rather than making the programmer be more 
explicit like we usually would - simply because there is no way for the 
programmer to be more explicit.

- Jonathan M Davis


More information about the Digitalmars-d mailing list