-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Implement named argument for functions #14575
Conversation
|
Thanks for your pull request and interest in making D better, @dkorpel! 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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14575" |
1c7c5e8
to
6fe4ace
Compare
|
The last one is in fact so tricky that I think we should refactor the overload resolution code first. The compiler is a complete cowboy logically when it comes to resolving this stuff. |
|
I just stumbled upon this issue: https://issues.dlang.org/show_bug.cgi?id=15692 . It asks for in-place struct initialization so if I'm not mistaken, implementing named parameters is going to fix this issue also, maybe you can link it. |
This PR doesn't implement that yet, but I might actually start doing that first since I can re-use logic from |
For now how about just error in that scenario when named arguments are supplied? It's still useful even if it can't be used to choose an overload. |
I mostly agree with that. I also think we should get all of this in-tree. I still think that parsing "foo: 3" as an expression is really weird (and basically guaranteed require a change of course when considering any non-trivial error messages or execution in the right order - it's argument-lexical) but better to have something to change than start again. |
I still don't know what error messages you're talking about, but in #14776 I switched to a parallel array of |
6fe4ace
to
d86a6bc
Compare
compiler/src/dmd/expressionsem.d
Outdated
| @@ -1398,7 +1398,10 @@ private Expression resolvePropertiesX(Scope* sc, Expression e1, Expression e2 = | |||
|
|
|||
| if (!e1.type) | |||
| { | |||
| error(loc, "cannot resolve type for %s", e1.toChars()); | |||
| if (e1.isNamedArgExp()) | |||
| error(loc, "named argument `%s` not allowed here", e1.toChars()); | |||
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.
Could one ever get here? assert?
Any error message that happens after semantic analysis in dmd can end up looking weird because the compiler doesn't keep track of the original expression (it would be nicer if it freed it). In original scheme presented (IIRC), a CallExp using named arguments would be resolved to an Array of expressions with no additional context, thus no additional context could be given in an error message if something fails either during the semantic analysis of that call or even an entirely unrelated expression containing a CallExp (user then sees their function called with args they don't recognize). I introduced a PR to rectify this slightly a few weeks ago (Aimed at making of an array literal resolved from a manifest constant print the identifier of that manifest constant rather than a the whole array - which is useless). A parallel set of symbols ( |
d86a6bc
to
63f82d4
Compare
7341cf7
to
233df01
Compare
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.
Looks good at a first glance, however, @WalterBright should probably take a look at it.
Another approach is to simply merge this behind a preview switch, announce it on the forums, fix any reported bugs and make the preview the default after a few releases.
|
I prefer this to be merged soon so I can continue working on it. If it's not ready when master gets cut for 2.103.0, I'll put it behind a preview switch on the stable branch. |
658d470
to
6442ad2
Compare
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.
along with the small nits I mentioned
6442ad2
to
e798774
Compare
|
This PR caused a regression https://issues.dlang.org/show_bug.cgi?id=23758 |
On top of #14475
Not implemented:
The last one is tricky because of how it currently works:
The problem is that
FuncDeclaration.leastAsSpecializedcompiler simply creates a dummy argument list to see what happens when one overload gets called with the types of the other. This doesn't take into account the re-ordering based on named parameters, so it will think whatever overload is tried first is better.