[Issue 3452] Can't alias member functions such that the object name is implicitly stored in the alias
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 6 10:12:03 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=3452
Maxim Fomin <maxim at maxim-fomin.ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |maxim at maxim-fomin.ru
--- Comment #3 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-08-06 10:12:00 PDT ---
(In reply to comment #0)
> struct Foo {
> void bar() {}
> void baz() {}
> }
>
> void doStuff(Foo foo) {
> alias foo.bar fun;
> fun(); // Error: need 'this' to access member bar
> }
>
Actually error message is reasonable for the same reason as Foo.bar requires
this pointer. The root of the issue is that alias does not capture local
variable in this context - it captures only type name. The code above is
essentially alias Foo.bar fun and since bar() is nonstatic the code doesn't
compile.
> I can't think of any reason why this shouldn't work. foo.bar is a compile-time
> symbol for the member function Foo.bar() on the instance foo. Once I alias
> foo.bar to fun, calling fun() should be equivalent to calling foo.bar().
Because of underspecification many view things different to what compiler does.
> Even if there's some language legalese reason why this shouldn't work according
> to the spec, it's still a reasonable enhancement request.
Yes, but this isn't a minor enhancement.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list