Add resolvedOrVirtualFunction, fix issue #6542 #7332
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR takes two steps to fix issue #6542:
CallExpr::resolvedOrVirtualFunction
, factoring out a code pattern used already in callDestructors and errorHandling. The pattern is to find the resolved function, or, for a PRIM_VIRTUAL_METHOD_CALL, find one of the possible virtual methods that could be called at runtime. This function is appropriate to call for code that identifies calls to transform based upon the signature of the called function.What was going wrong with issue #6542? The compiler includes a transformation that happens during resolution,
insertReturnTemps
, which finds all calls to functions that return a value that don't use the result of that return. In that case it adds a temporary variable to capture the returned value.Code in callDestructors / ReturnByRef relied on calls to transformable functions having a variable to capture the returned value.
In the case of virtual method calls,
insertReturnTemps
was not transforming the call, and so the code pattern in issue #6542 led to failed assertions in callDestructors.The important part of this fix is to adjust
insertReturnTemps
to handle virtual calls (PRIM_VIRTUAL_METHOD_CALL).Passed full local testing.
Reviewed by @noakesmichael - thanks!