www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6924] New: An alias this problem to implement a Typedef

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6924

           Summary: An alias this problem to implement a Typedef
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



I find typedef useful still. While trying to create something like a typedef
using a struct with "alias this", I have found this problem:



struct Typedef(T) {
    T data;
    alias data this;
}

alias int[] TA1;
typedef int[] TA2;
alias Typedef!(int[]) TA3;

immutable TA1 a1;
immutable TA2 a2;
TA3 a3a;
immutable TA3 a3b;

static this() {
    a1 = [1, 2, 3];  // OK
    a2 = [1, 2, 3];  // OK
    a3a = [1, 2, 3]; // OK
    a3b = [1, 2, 3]; // line 16, error
}
void main() {}



DMD 2.057beta gives:

test.d(16): Error: cannot implicitly convert expression ([1,2,3]) of type int[]
to immutable(Typedef!(int[]))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6924


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



I think this is a same issue with bug 6174.

The assignment expression

  a3b = [1, 2, 3];

is translated to

  a3b.data = [1, 2, 3];

, and current dmd does not allow indirect initialization of members with
assignment.

*** This issue has been marked as a duplicate of issue 6174 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 12 2011