D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6479 - spurious alias this with struct and mixin template
Summary: spurious alias this with struct and mixin template
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-08-12 12:22 UTC by Trass3r
Modified: 2011-11-15 12:08 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Trass3r 2011-08-12 12:22:30 UTC
struct Memory
{
	mixin Wrapper!();
}
struct Image
{
	Memory sup;
	alias sup this;
}
mixin template Wrapper()
{
}

$ dmd -c test.d 
DMD v2.054 DEBUG
test.d(8): Error: alias this there can be only one alias this

As soon as the template precedes Image, it works.
In my real code this is all spread among different modules, so it also is an order of compilation dependent issue.
Comment 1 Trass3r 2011-08-12 12:26:12 UTC
Well, forget the last half sentence ;)
btw, I probably would never have figured this out without DustMite :)
Comment 2 Kenji Hara 2011-10-23 04:58:07 UTC
This is a bug related to forward reference.

struct Memory
{
    mixin Wrapper!();
}
//mixin template Wrapper() {}  // OK
struct Image
{
    Memory sup;
    alias sup this;
}
mixin template Wrapper() {}  // NG
Comment 3 Kenji Hara 2011-10-23 07:01:08 UTC
https://github.com/D-Programming-Language/dmd/pull/471

This patch does not solve forward reference order problem, and has an issue.

struct S
{
    int value;
    alias value this;
    alias value this;  // alias this forwards to same symbol is allowed
}

But I think this is acceptable issue.
Comment 4 Trass3r 2011-10-23 07:45:38 UTC
(In reply to comment #2)
> This is a bug related to forward reference.
> 
> struct Memory
> {
>     mixin Wrapper!();
> }
> //mixin template Wrapper() {}  // OK
> struct Image
> {
>     Memory sup;
>     alias sup this;
> }
> mixin template Wrapper() {}  // NG

Well as I said, the code is spread over several modules.
So it's hard to make sure Wrapper is processed first.
Comment 5 Trass3r 2011-11-11 09:12:29 UTC
btw, now it tells
Error: alias this test.Image.__anonymous there can be only one alias this