D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6842 - Can't use alias of instance member
Summary: Can't use alias of instance member
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
: 6619 8051 9105 9929 14848 20895 24720 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-10-22 18:14 UTC by Nick Sabalausky
Modified: 2024-12-13 17:56 UTC (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nick Sabalausky 2011-10-22 18:14:44 UTC
--------------------------------
struct Foo
{
    int a;
}

Foo foo;
alias foo.a b;

void main()
{
    b = 5;  // <-- Error
}
--------------------------------

>dmd test.d
test.d(11): Error: need 'this' to access member a
Comment 1 Kenji Hara 2011-10-22 22:28:33 UTC
This is an enhancement, not "rejects-valid".
Because foo.a is an expression, and it is neither type nor symbol.

http://d-programming-language.org/declaration.html
AliasDeclaration allows type or symbol as the first argument.
Comment 2 timon.gehr 2011-10-23 01:10:41 UTC
(In reply to comment #1)
> This is an enhancement, not "rejects-valid".
> Because foo.a is an expression, and it is neither type nor symbol.
> 
> http://d-programming-language.org/declaration.html
> AliasDeclaration allows type or symbol as the first argument.

If foo.a is not a symbol, why does alias foo.a b; compile without an error?
Comment 3 Kenji Hara 2011-10-23 02:21:48 UTC
(In reply to comment #2)
> If foo.a is not a symbol, why does alias foo.a b; compile without an error?

Now compiler treats foo.a as Foo.a, and Foo.a is a symbol.
I think this is "accepts-invalid" bug.
Comment 4 Andrej Mitrovic 2012-12-02 11:29:39 UTC
*** Issue 9105 has been marked as a duplicate of this issue. ***
Comment 5 Andrej Mitrovic 2012-12-02 11:30:55 UTC
*** Issue 8051 has been marked as a duplicate of this issue. ***
Comment 6 Andrej Mitrovic 2012-12-02 11:31:08 UTC
*** Issue 6619 has been marked as a duplicate of this issue. ***
Comment 7 Andrej Mitrovic 2013-04-13 14:08:20 UTC
*** Issue 9929 has been marked as a duplicate of this issue. ***
Comment 8 Andrej Mitrovic 2016-08-28 19:15:42 UTC
*** Issue 14848 has been marked as a duplicate of this issue. ***
Comment 9 John Hall 2023-02-08 20:17:15 UTC
*** Issue 20895 has been marked as a duplicate of this issue. ***
Comment 10 RazvanN 2024-08-26 08:19:16 UTC
*** Issue 24720 has been marked as a duplicate of this issue. ***
Comment 11 Nick Treleaven 2024-08-26 11:13:51 UTC
> Foo foo;
> alias foo.a b;

For the next edition, this is an error:
https://dlang.org/spec/legacy#alias-instance-member

Added in https://github.com/dlang/dmd/pull/15863.
Refinement: https://github.com/dlang/dmd/pull/16813.
Comment 12 Nick Treleaven 2024-08-28 11:36:54 UTC
> alias foo.a b;

Note you can instead write:

ref b() => foo.a;
Comment 13 dlangBugzillaToGithub 2024-12-13 17:56:38 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17532

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB