[Issue 9100] Weird behavior on template instance argument

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 9 13:20:56 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9100


timon.gehr at gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr at gmx.ch


--- Comment #6 from timon.gehr at gmx.ch 2012-12-09 13:20:55 PST ---
(In reply to comment #2)
> As a related note, this program runs successfully with no error in current
> compiler.
> It looks weird, but is expected from the view of language consistency.
> 
> void main(){ (new C(1)).test(); }
> template Id(alias A) { alias Id = A; }
> class C
> {
>   int n;
>   this(int x){ n = x; }
>   int fun(){ return n; }
> 
>   void test()
>   {
>     auto c = new C(2);
>     assert(c.fun() == 2);
>     alias f = Id!(c.fun);
>     assert(f() == 1);  // calls this.fun, not c.fun
>   }
> }

Language _sanity_ is what is important. It should call c.fun or be a compile
time error. Deliberately assigning unsupported code strange semantics in order
to be consistent with existing buggy compiler behaviour just makes it harder to
lift restrictions later.

-- 
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