www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14583] New: std.typecons.Rebindable works incorrectly with


          Issue ID: 14583
           Summary: std.typecons.Rebindable works incorrectly with classes
                    in which there is an 'alias this' to AA member.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: japplegame gmail.com

I spent several hours to discover this very weird bug. :(

import std.typecons;

class Foo {
    string[int] aa;

class Bar {
    string[int] aa;
    alias aa this;

void main() {
    auto foo = new immutable Foo;
    assert(rebindable(foo).get is foo); // ok

    auto bar = new immutable Bar;
    assert(rebindable(bar).get is bar);   // fails
    auto len = rebindable(bar).aa.length; // crash

Sometimes 'alias this' is very dangerous thing.

May 14 2015