Bug 9809 – Need a better diagnostic on accessing 'alias this' to private symbols

Status
REOPENED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-24T19:39:08Z
Last change time
2024-12-13T18:05:17Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: dmd#18545 →

Comments

Comment #0 by andrej.mitrovich — 2013-03-24T19:39:08Z
module foo; struct S { void func() { } } struct X { public alias s this; private S s; } module test; import foo; void main() { X x; x.func(); } $ rdmd test.d > test.d(8): Error: undefined identifier 'func' I'm not exactly sure, perhaps the public alias to a private symbol should be disallowed in the first place. Otherwise a better diagnostic should be made.
Comment #1 by andrej.mitrovich — 2013-03-24T19:42:13Z
(In reply to comment #0) > struct X > { > public alias s this; > private S s; > } Btw, the reason I needed this is because I want 's' fields/methods to be accessible, but I do not want the user to be able to assign 's' to something else. Perhaps I should have used: struct NoAssign { @disable void opAssign(T...)(T t) { } S s; alias s this; } struct X { alias s this; NoAssign s; } Not too sure..
Comment #2 by andrej.mitrovich — 2013-09-17T16:12:24Z
The diagnostic in 2.063.2 is now: > Error: struct foo.X member s is not accessible
Comment #3 by nick — 2022-09-06T16:57:33Z
(In reply to Andrej Mitrovic from comment #2) > The diagnostic in 2.063.2 is now: > > > Error: struct foo.X member s is not accessible Can't reproduce that with v2.100.2-beta.1-dirty: privaliasthis.d(6): Error: no property `func` for type `foo.X` > perhaps the public alias to a private symbol should be disallowed in the first place. I think a warning for that is needed, because people might not always test their type outside the module it's defined in.
Comment #4 by robert.schadek — 2024-12-13T18:05:17Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18545 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB