Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DSSv3] Fix Issue 21685: add clearer message for private constructor #12919

Merged
merged 3 commits into from
Aug 2, 2021

Conversation

dandrei279
Copy link
Contributor

The error message for accessing the private constructor is clear now.
Old message:
Error: class <class_name>memberthis is not accessible

Current message:
Error: class <class_name> Constructor is not accessible

@dandrei279 dandrei279 requested a review from MartinNowak as a code owner July 25, 2021 14:51
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @dandrei279! 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 coverage diff by visiting the details link of the codecov check)
  • 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
21685 enhancement bad error message on private constructor: member this is not accessible

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12919"

src/dmd/access.d Outdated Show resolved Hide resolved
src/dmd/access.d Outdated Show resolved Hide resolved
src/dmd/access.d Outdated Show resolved Hide resolved
src/dmd/access.d Outdated Show resolved Hide resolved
Copy link
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

The simpler fix would be to simply include the .kind() result in the error message:

ad.error(loc, "`%s %s` is not accessible", smember, smember.isConstructor() ? smember.kind() : "member", ...);

This also does not require the phobos imported, which, as pointed out is forbidden in dmd.

Also, every new addition needs to be covered by tests.

@RazvanN7
Copy link
Contributor

ping @dandrei279

@dandrei279
Copy link
Contributor Author

ping @dandrei279

Hi. Sorry for delay. I 'm working on it

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

Looking good

src/dmd/access.d Outdated
@@ -60,7 +60,7 @@ bool checkAccess(AggregateDeclaration ad, Loc loc, Scope* sc, Dsymbol smember)
return false;
}

ad.error(loc, "member `%s` is not accessible%s", smember.toChars(), (sc.flags & SCOPE.onlysafeaccess) ? " from `@safe` code".ptr : "".ptr);
ad.error(loc, "`%s %s` is not accessible%s", smember.kind(), smember.toChars, (sc.flags & SCOPE.onlysafeaccess) ? " from `@safe` code".ptr : "".ptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the first format specifier should be outside the opening backtick. i.e. the format string to the error call should be

"%s `%s` is not accessible%s"

not

"`%s %s` is not accessible%s"

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree.

Copy link
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

Mind the nit and we're good to go.

@RazvanN7 RazvanN7 merged commit dff4824 into dlang:master Aug 2, 2021
UplinkCoder pushed a commit to UplinkCoder/dmd that referenced this pull request Aug 19, 2021
…lang#12919)

* Fix Issue 21685: add clearer message for private constructor

* Rewrite the error message for private members; Update and create tests.

* Fix backtick position in error message
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.

6 participants