D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6924 - An alias this problem to implement a Typedef
Summary: An alias this problem to implement a Typedef
Status: RESOLVED DUPLICATE of issue 6174
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 20:03 UTC by bearophile_hugs
Modified: 2011-11-12 06:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-11-09 20:03:18 UTC
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[]))
Comment 1 Kenji Hara 2011-11-12 06:56:29 UTC
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 ***