-
-
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
Fix Issue 22997 - DMD crash: copy ctor can't call other ctor #13976
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
|
|
Edit: I hammered it with a cast, following the example here https://github.com/dlang/dmd/blob/master/src/dmd/expressionsem.d#L4154 |
test/compilable/test22997.d
Outdated
|
|
||
| struct Foo | ||
| { | ||
| this(scope ref typeof(this) rhs) |
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.
Since Foo has no pointers, scope is stripped in type semantic. Is it relevant to the bug?
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.
Nope, I simply copy-pasted the provided bug report. I can strip it manually.
| @@ -4685,6 +4685,14 @@ extern (C++) final class TypeFunction : TypeNext | |||
| match = MATCH.convert; // match ... with a "conversion" match level | |||
| } | |||
|
|
|||
| if (parameterList.varargs == VarArg.none && nparams > nargs && !parameterList[nargs].defaultArg) | |||
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.
Can you add a link to https://issues.dlang.org/show_bug.cgi?id=22997 in a comment? It's not self-explanatory why this branch is 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.
Sure.
|
@dkorpel Done. |
|
This should go to stable. |
|
@thewilsonator I am intentionally targeting master since I need to do some follow-up changes that depend on this PR that have the potential to break user code. |
When calling the second constructor, the compiler needs to check all overloads to see the matches. Once it tries the 3rd constructor it tries to match its parameters and therefore it tries to copy construct rhs in the scope of the 3rd constructor. This leads to infinite recursion, because the new constructor call needs to check all of the constructors again. To break this cycle, I have added a new condition that checks whether the number of parameters non default parameters is greater than the number of arguments. If that is the case, then simply return no match and don't try to match args to params anymore. For that I needed to change a few tests, but I think that the error message is better anyway.
I am targeting master since I am going to do some follow up patches for the copy constructor that rely on this patch.