Closed xanderstuff closed 1 month ago
Question: would it be beneficial to do something similar for logical operations (AND, OR)? or does @ModifyExpressionValue
cover every possible use-case scenario (since logical operations are much simpler)?
I haven't put much thought into the name yet, so here's some alternative names: @WrapComparisonArg, @ModifyComparisonExpression, @WrapComparisonExpression.
The trouble is that targeting such operations is inherently brittle because the instructions are so generic. Slices make it a bit better but it's still not ideal. I may implement something along these lines in the future but it's not a priority because the situations are fairly esoteric (I've yet to encounter anything like you've described in the wild). If there's any specific scenarios you'd like this for, feel free to ask about them.
I do have a plan for this now.
This would wrap the entire left-hand or right-hand side of a comparison, which could be chained by multiple mixins.
Example:
Code diff:
Note: in this example code diff, there is no way to add 5 to either side. If you used a
@ModifyExpressionValue
on foo.get(), then any value you add gets multiplied by 4 (which will not be the same result). And if you used a@ModifyConstant
or@Redirect
on the field access, then (in this example) any change you make will also get multiplied by the other values in the expression (again, not the same result), while also not being compatible with any other mixins using the same target.