Fix loss of converter info with ExprLoopValue #8109
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.
Problem
In specific cases,
loop-valuefailed to convert to the expected type due to a loss of converter info that lead to simplification ultimately determining that it only needed an Object -> Object converter, which is effectivelyreturn this. This lead to issues like #8108 where the name of loop-value could not be determined due to an ItemStack being returned, which is not AnyNamed, rather than the ItemStack being converted to AnyNamed via ItemType.Solution
The problem stemmed from ExprLoopValue#getConvertedExpression, which had a special implementation that at one point was probably useful? It effectively just made a dynamic converter using Converters.convert to attempt each possible to type in order.
Sharp-eyed viewers may note this as being what ConvertedExpression#newInstance does during init, so really it's just a runtime call to CE#newInstance, if we're matching high level behavior. However, it results in a CE that thinks it's just a simple Object->Object converter and doesn't actually know what it's supposed to be doing, leading to the loss of info mentioned previously.
Replacing this special converter with CE#newInstance results in the expected ConvertedExpression being formed, with CInfos to each of the possible return types, and all the necessary information retained. This also makes the condition in ELV#gCE() useless, since the super impl is just CE#newInstance, so the whole method can be and was removed.
Testing Completed
Added a new regression test based on the code provided in #8108.
Supporting Information
Completes: #8108
Related: none