Skip to content

Conversation

@ghost91-
Copy link
Contributor

…for expressions

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @ghost91-! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
18104 trivial Alias example compiles where it states that it should be illegal

alias a = s.i; // illegal, s.i is an expression
alias b = S.i; // ok
alias a = s.i; // ok, s.i is a symbol
alias b = S.i; // ok, S.i also is a symbol
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alias b = s.i seems redundant and doesn't illustrate anything new. I suggest maybe adding a member static int j; to S and use that instead to illustrate the idea, or something like that.

Copy link
Contributor Author

@ghost91- ghost91- Aug 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean something like this?

struct S
{
    int i; 
    static int j;
}
S s;

alias a = s.i;   // ok, s.i is a symbol
alias b = S.j;   // ok, S.j also is a symbol
alias c = a + b; // illegal, a + b is an expression
a = 2;           // sets s.i to 2
b = 4;           // sets S.j to 4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a = 2; // sets s.i to 2

Doesn't work like that. An alias of s.i is the same as one of S.i. It doesn't carry this with it. It can't be used to access s.i.

Copy link
Contributor Author

@ghost91- ghost91- Aug 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, of course 🤦‍♂️ I suppose I was bit too quick here. Do you think, we should just omit the non static case in the example, or show that accessing in the non static case is not actually possible:

struct S
{
    int i; 
    static int j;
}
S s;

alias a = s.i;   // ok, s.i is a symbol
alias b = S.j;   // ok, S.j also is a symbol
alias c = a + b; // illegal, a + b is an expression
a = 2;           // error, a is aliased to S.i, but does not carry a this pointer with it
b = 4;           // sets S.j to 4

Copy link
Contributor Author

@ghost91- ghost91- Aug 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we simplify the example even more? After all, it is about alias not working on expressions. Structs are not necessary to show this:

int a;

alias b = a;     // ok, a is a symbol
alias c = a + a; // illegal, a + a is an expression

@JinShil
Copy link
Contributor

JinShil commented Aug 27, 2018

I recommend this:

struct S 
{
    static int i;
    static int j;
}

alias a = S.i; // OK, `S.i` is a symbol
alias b = S.j; // OK. `S.j` is also a symbol
alias c = a + b; // illegal, `a + b` is an expression
a = 2;         // sets `S.i` to `2`
b = 4;         // sets `S.j` to `4`

This purpose of this example is simply to illustrate the one can't alias an expression. Trying to show that S.i and s.i are equivalent is irrelevant, and actually that feature is currently being debated.

@ghost91-
Copy link
Contributor Author

Sounds good to me, I will change things accordingly this evening

@dlang-bot dlang-bot merged commit 92ff7aa into dlang:master Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants