D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21685 - bad error message on private constructor: member this is not accessible
Summary: bad error message on private constructor: member this is not accessible
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: Andrei David
URL:
Keywords: pull, trivial
Depends on:
Blocks:
 
Reported: 2021-03-07 15:10 UTC by Tobias Pankrath
Modified: 2021-08-02 08:11 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tobias Pankrath 2021-03-07 15:10:20 UTC
--bad_error_main.d
import bad_error;

void main()
{
    new E;
}
--

--bad_error.d
module bad_error;

class E
{
    private this() {}
}
--

Gives: bad_error_main.d(5): Error: class bad_error.E member this is not accessible

That confused me a lot. I first thought that there is somehow a problem with the this-pointer, not with the constructor.

My proposal is to fit `constructor` somewhere in there: constructor `this` is not accessible or similar.
Comment 1 Tobias Pankrath 2021-03-07 15:11:03 UTC
This confused other people on discord, too. So I am not the only one.
Comment 2 Ahmet Sait 2021-03-07 15:29:52 UTC
Can confirm.
Comment 3 RazvanN 2021-03-08 11:09:55 UTC
Yes, the type of the member should be explicitly stated to avoid any type of confusion.
Comment 4 Dlang Bot 2021-07-25 14:51:20 UTC
@dandrei279 created dlang/dmd pull request #12919 "[DSSv3] Fix Issue 21685: add clearer message for private constructor" fixing this issue:

- Fix Issue 21685: add clearer message for private constructor

https://github.com/dlang/dmd/pull/12919
Comment 5 Dlang Bot 2021-08-02 08:11:32 UTC
dlang/dmd pull request #12919 "[DSSv3] Fix Issue 21685: add clearer message for private constructor" was merged into master:

- 0b1f5d661a3528231aa6b856642c25976a7a8e28 by Andrei David:
  Fix Issue 21685: add clearer message for private constructor

https://github.com/dlang/dmd/pull/12919