www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20559] New: Reference type + alias this + AA + AA.clear


          Issue ID: 20559
           Summary: Reference type + alias this + AA + AA.clear causes
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

Test code:
import std.stdio;

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

void main ()
    scope b = new Bar;
    b["Hello"] = 42;
    b.clear; // SEGV happens here, next line is never reached

This happens because 'clear' is defined as:
 void clear(T : Value[Key], Value, Key)(T aa)
And the code just blindly casts T to a `struct AA`: https://github.com/dlang/druntime/blob/1049bb806679436103f8174c1f77541d5ad99091/src/object.d#L2167-L2170 --
Feb 03 2020