-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
Fix Issue 19645 - Default parameters not checked for @safe #9428
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
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
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9428" |
| @@ -314,6 +314,7 @@ immutable Msgtable[] msgtable = | |||
| { "dup" }, | |||
| { "_aaApply" }, | |||
| { "_aaApply2" }, | |||
| { "__tmpFunc"}, | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to give a bit of a description here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temporary function used as mock-up for the scope to evaluate function parameters ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that now, I might not in 6 months time.
|
Shouldn't the function attributes of the default argument expressions be judged based on the caller and not the function declaration? |
Why don't you add that? |
| @@ -1206,6 +1206,10 @@ extern(C++) Type typeSemantic(Type t, Loc loc, Scope* sc) | |||
| argsc.stc = 0; // don't inherit storage class | |||
| argsc.protection = Prot(Prot.Kind.public_); | |||
| argsc.func = null; | |||
| Loc tloc = Loc(); | |||
| auto mockFunc = new FuncDeclaration(tloc, tloc, Id.__tmpFunc, sc.stc, new TypeFunction(ParameterList(), Type.tvoid, LINK.d, sc.stc)); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving the function declaration and identifier will add it to the symbol table which might make it accessible to user code.
Default parameters are not checked for
@safe/pure/@nogc/nothrow. This is mainly because dmd implemented these checks only for expressions that are in a functions' scope. Before this patch dmd created a normal scope (not function scope) for parameters to be evaluated; this led to default parameters not being checked for@safe/pure/@nogc/nothrow.To solve the issue I created a mock-up function declaration to trick the compiler that the parameters are in a functions's scope. It would have been ideal to use the initial function declaration for this, but there is no way of obtaining it from a TypeFunction.
nothrowis not handled in this PR as it is a bit different.