Fix Issue 22039 - ICE on infinite recursion in default parameter#14934
Fix Issue 22039 - ICE on infinite recursion in default parameter#14934RazvanN7 merged 1 commit intodlang:stablefrom
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 run digger -- build "stable + dmd#14934" |
thewilsonator
left a comment
There was a problem hiding this comment.
ICEs should go to stable though
|
As per @ibuclaw 's suggestion, retarget to stable. |
|
Documentation failure is unrelated. |
|
Stable seems to be broken for MacOS. I am seeing the failure on multiple PRs. |
* Fix Issue 22039 - ICE on infinite recursion in default parameter (#14934) * remove IRState.falseBlock - stable version --------- Co-authored-by: Razvan Nitu <razvan.nitu1305@gmail.com> Co-authored-by: Walter Bright <walter@walterbright.com>
When
functionParametersis called, a pointer to the type of the call expression is passed so that the type is set. This is done because inout needs to be matched to one of the mutable, const, immutable qualifiers. As a measure of precaution, the first thingfunctionParametersdoes is to set that pointer to point to a TypeError. I guess this is done to catch any error that falls between the cracks, however, the downside is that you might end up with errors in your AST for which you have not outputted an error message.This mechanism interferes with how default arguments are processed in the provided bug report:
When the type of function
funcis analyzed, it needs to check that the type of the default arg matches the type of the parameter. As a consequence it performs semantic analysis on the function call offunc. Then it ends up callingfunctionParameterswith the type of functionfunc(int(int x = func())) and a pointer to the type of the call expression. The catch is that this pointer points to a part of the type offunc, therefore, when the pointer is set to TypeError the type offuncis automatically updated to contain an error that is unaccounted for. This messes up the analysis of the default arg insidefunctionParametersand leads to the error being caught somewhere down the road where the compiler has no idea where it comes from, hence the ICE.To fix this, I am deleting the line that bluntly sets the call type to error and if a default argument is missing its type information I'm just performing semantic on it on the spot. This seems to fix the issue and correctly output the recursive evaluation error.
Anyway, I find that
functionParameteresis a complex beast doing all kinds of stuff. In my opinion, the wayinoutis handled here and how it uglifies the code is another justification for deprecatinginout.Although this is a regression, I'm not targeting stable since it's possible that some erroneous cases that would have been caught by the older mechanism slip through. Let's see what the tester says.