Issue 9569 - 'alias this' syntax is not accepted by dmd
Summary: 'alias this' syntax is not accepted by dmd
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Andrej Mitrovic
URL:
Keywords: pull, spec
Depends on:
Blocks:
 
Reported: 2013-02-22 09:25 UTC by Ali Cehreli
Modified: 2013-11-09 02:31 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ali Cehreli 2013-02-22 09:25:51 UTC
struct Test
{
    int i;
    alias this = i;    // <-- Compilation error
}

void main()
{}

The compiler says:

deneme.d(121089): Error: no identifier for declarator this
deneme.d(121089): Error: alias cannot have initializer
Comment 1 bearophile_hugs 2013-02-22 09:36:44 UTC
This is working as designed, and probably should be closed.

See also:

http://forum.dlang.org/thread/evldispcxhyarckmkycg@forum.dlang.org

https://github.com/D-Programming-Language/dmd/issues/1413
Comment 2 Andrej Mitrovic 2013-02-22 09:58:26 UTC
This is a spec issue covered with http://d.puremagic.com/issues/show_bug.cgi?id=9569
Comment 4 Michael 2013-02-23 14:00:38 UTC
We have a one alias beast, so  now will have two beast... after month three beast ... (period) ... nth beast. 

Bad idea.

Alias this used like class inheritance is bad idea too, because it's not a class inheritance.

One syntax, one alias beast - it's good.

About multiple alias this:

alias this = ...;
alias this = ...;
...
alias this = ...;

It's good because many uses of alias this is not desirable (although allowed) and people will think twice to use this feature.

And I think it's more demonstrable when I want to show what I was mean when put it (alias this) into source code.
Comment 5 Denis Shelomovskii 2013-11-09 02:31:30 UTC
(In reply to comment #4)
> One syntax, one alias beast - it's good.

`alias this = ...;` is reserved for aliasing of superclass constructors. See e.g. discussion of
https://github.com/D-Programming-Language/dmd/pull/1341

Also documentation is correct now and the error is improved:
---
Error: Cannot use syntax 'alias this = i', use 'alias i this' instead
---