-
-
Notifications
You must be signed in to change notification settings - Fork 598
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
Issue 2803 - template + default argument = doesn't work #4261
Conversation
I had a gut feeling you were going to work on this! Very very nice. :) |
This makes me uneasy. First, there's the (deleted) comment that default parameters do not participate in type deduction. I don't remember the reason for that decision. The next issue it the comment about a workaround for existing code - doesn't this make the language more complex than necessary? |
/* Bugzilla 2803: Before the starting of type deduction from the function | ||
* default arguments, lock the already deduced parameters into paramscope. | ||
* It's necessary to avoid breaking some existing code. See the regression cases | ||
* in `runnable/template9.d`. |
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.
Please show the cases being worked around here, rather than a reference to something in template9.d which is a 4000+ line file and would surely get out of sync with this comment regardless.
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 had just specified the issue 2803 test case. It's only 500 lines so finding it would be easy.
But OK, I added acceptable cases in the comment.
I know the comment, but I couldn't understand the reason. As far as I see, issue 2803 is possible.
This PR will add just only one more IFTI rule - if a default argument is used for the type deduction, it can refer already deduced types. For example: auto foo(A, B)(A a, B b = A.stringof) {}
foo(1); At the function parameter |
4c069ea
to
66baefd
Compare
Seems to me, that existing code here means the newly added test cases.
I'd say it makes the language simpler because default arguments should behave like normal arguments. void foo(T)(T t = 0) {}
void main() {
foo();
foo(0);
} And the possibility to refer to already deduced types matches default template arguments. void foo(T, U = T.U)(T t, U u) {}
struct Foo {
alias U = size_t;
}
void main() {
foo(Foo(), 12);
} |
This is failing with ddmd because of a goto-skips-init error. |
@yebblies Thanks, updated. |
Auto-merge toggled on |
Issue 2803 - template + default argument = doesn't work
This seems to have introduced a small regression Issue 14468 – [Reg 2.068.0-devel] overload mismatch for template instance with typesafe variadic parameter. |
Another regression: https://issues.dlang.org/show_bug.cgi?id=15668 |
https://issues.dlang.org/show_bug.cgi?id=2803