[enh] Issue 3011 - alias should have assignment syntax #1187

Merged
merged 2 commits into from Oct 22, 2012

Conversation

Projects
None yet
8 participants
@9rnsr
Member

9rnsr commented Oct 16, 2012

http://d.puremagic.com/issues/show_bug.cgi?id=3011

This change never break existing code.

@yebblies

This comment has been minimized.

Show comment Hide comment
@yebblies

yebblies Oct 16, 2012

Member

What about alias this?

Member

yebblies commented Oct 16, 2012

What about alias this?

@9rnsr

This comment has been minimized.

Show comment Hide comment
@9rnsr

9rnsr Oct 16, 2012

Member

Yet not care it. Tomorrow I'll update for that.

Member

9rnsr commented Oct 16, 2012

Yet not care it. Tomorrow I'll update for that.

+
+alias X4 = void delegate() const, X5 = Test!int;
+static assert(is(X4 == void delegate() const));
+static assert(is(X5.Type == int));

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Oct 16, 2012

Shouldn't this be:

static assert(is(X5 == int));
@ghost

ghost Oct 16, 2012

Shouldn't this be:

static assert(is(X5 == int));

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Oct 16, 2012

Oh nevermind the template is called Test not type. (thought it was eponymous)

@ghost

ghost Oct 16, 2012

Oh nevermind the template is called Test not type. (thought it was eponymous)

This comment has been minimized.

Show comment Hide comment
@9rnsr

9rnsr Oct 17, 2012

Member

It is a test for aliasing template itself.

@9rnsr

9rnsr Oct 17, 2012

Member

It is a test for aliasing template itself.

@stasoid

This comment has been minimized.

Show comment Hide comment
@stasoid

stasoid Oct 17, 2012

What confuses me a little is using function parseType. Does it work good for other symbols as well?
I checked aliasing function, function template and enum constant, all work fine.
Maybe there exists other type of symbol I can't think of that parseType would fail to parse?

stasoid commented Oct 17, 2012

What confuses me a little is using function parseType. Does it work good for other symbols as well?
I checked aliasing function, function template and enum constant, all work fine.
Maybe there exists other type of symbol I can't think of that parseType would fail to parse?

@9rnsr

This comment has been minimized.

Show comment Hide comment
@9rnsr

9rnsr Oct 17, 2012

Member

@stasoid : For all types which yet not known whether that is really type or not in parsing phase, parseType returns TypeIdentifer(will be user-defined type, or symbol), TypeInstance(will be type, expression, or symbol), or TypeSlice(will be dynamic array type or tuple slicing). Then, in semantic analysis phase, they are resolved to actual entities. (It will be done in Type::resolve).
So, there is no problem.

Member

9rnsr commented Oct 17, 2012

@stasoid : For all types which yet not known whether that is really type or not in parsing phase, parseType returns TypeIdentifer(will be user-defined type, or symbol), TypeInstance(will be type, expression, or symbol), or TypeSlice(will be dynamic array type or tuple slicing). Then, in semantic analysis phase, they are resolved to actual entities. (It will be done in Type::resolve).
So, there is no problem.

@9rnsr

This comment has been minimized.

Show comment Hide comment
@9rnsr

9rnsr Oct 17, 2012

Member

Updated for the syntax alias this = identifier;

Member

9rnsr commented Oct 17, 2012

Updated for the syntax alias this = identifier;

@donc

This comment has been minimized.

Show comment Hide comment
@donc

donc Oct 17, 2012

Collaborator

The code looks good to me. But this changes the language syntax, needs approval from Walter. I think it's a HUGE improvement over the existing syntax.

Collaborator

donc commented Oct 17, 2012

The code looks good to me. But this changes the language syntax, needs approval from Walter. I think it's a HUGE improvement over the existing syntax.

@andralex

This comment has been minimized.

Show comment Hide comment
@andralex

andralex Oct 17, 2012

Owner

Walter and I have discussed this many times, and we're both in favor of it. I hereby submit my formal approval. @WalterBright please advise. Thanks!

Owner

andralex commented Oct 17, 2012

Walter and I have discussed this many times, and we're both in favor of it. I hereby submit my formal approval. @WalterBright please advise. Thanks!

@WalterBright

This comment has been minimized.

Show comment Hide comment
@WalterBright

WalterBright Oct 17, 2012

Owner

LGTM, but doc changes have to be done, too.

Owner

WalterBright commented Oct 17, 2012

LGTM, but doc changes have to be done, too.

@tgehr

This comment has been minimized.

Show comment Hide comment
@tgehr

tgehr Oct 17, 2012

What about
alias blah = int, this = identifier;
alias this = identifier, blah = int;
?

What about
alias blah = int, this = identifier;
alias this = identifier, blah = int;
?

This comment has been minimized.

Show comment Hide comment
@9rnsr

9rnsr Oct 17, 2012

Owner

I don't implement it. Because alias ident this; is allowed, but alias ident this, X; doesn't.

Owner

9rnsr replied Oct 17, 2012

I don't implement it. Because alias ident this; is allowed, but alias ident this, X; doesn't.

This comment has been minimized.

Show comment Hide comment
@tgehr

tgehr Oct 17, 2012

Then why have you implemented it for other aliases?

Then why have you implemented it for other aliases?

This comment has been minimized.

Show comment Hide comment
@9rnsr

9rnsr Oct 18, 2012

Owner

Reasons:

  1. Multiple alias this is not implemented in current. So alias this = ident1, this = ident2; is illegal. and it's future enhancement.
  2. alias this and normal alias declaration are completely different thing, even if their syntax are similar. So mixing them is just wrong to me.
Owner

9rnsr replied Oct 18, 2012

Reasons:

  1. Multiple alias this is not implemented in current. So alias this = ident1, this = ident2; is illegal. and it's future enhancement.
  2. alias this and normal alias declaration are completely different thing, even if their syntax are similar. So mixing them is just wrong to me.
@9rnsr

This comment has been minimized.

Show comment Hide comment
@9rnsr

9rnsr Oct 17, 2012

Member

doc changes have to be done, too.

Website fix:
D-Programming-Language/d-programming-language.org#177

Member

9rnsr commented Oct 17, 2012

doc changes have to be done, too.

Website fix:
D-Programming-Language/d-programming-language.org#177

@azizk

This comment has been minimized.

Show comment Hide comment
@azizk

azizk Oct 17, 2012

I think alias this = X; shouldn't be treated specially, because there's no good reason for it. Since we're changing the syntax anyway, which surely doesn't happy very often, why not do it properly and with foresight? If I remember right, it was mentioned that multiple aliases to 'this' will be supported some time. In that case it wouldn't be smart to restrict the new syntax like that.

azizk commented Oct 17, 2012

I think alias this = X; shouldn't be treated specially, because there's no good reason for it. Since we're changing the syntax anyway, which surely doesn't happy very often, why not do it properly and with foresight? If I remember right, it was mentioned that multiple aliases to 'this' will be supported some time. In that case it wouldn't be smart to restrict the new syntax like that.

@andralex

This comment has been minimized.

Show comment Hide comment
@andralex

andralex Oct 22, 2012

Owner

Will pull now both compiler and dox. This is great! I think it would be good to implement alias this = xxx; for several reasons. But we can leave that to a future pull request.

Owner

andralex commented Oct 22, 2012

Will pull now both compiler and dox. This is great! I think it would be good to implement alias this = xxx; for several reasons. But we can leave that to a future pull request.

andralex added a commit that referenced this pull request Oct 22, 2012

Merge pull request #1187 from 9rnsr/fix3011
[enh] Issue 3011 - alias should have assignment syntax

@andralex andralex merged commit 6c01188 into dlang:master Oct 22, 2012

1 check was pending

default Pass: 4, In Progress: 1, Pending: 4
Details

@JinShil JinShil referenced this pull request in dlang/dlang.org Jun 13, 2014

Closed

Change new alias syntax to `alias this : identifier` #200

@JinShil JinShil referenced this pull request in dlang/dlang.org Nov 5, 2014

Merged

Added new type alias syntax as a preference #682

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment