Proper instructions for elvis operator
We should not mark elvis operator unused, for the rhs may have desired side-effects
This commit is contained in:
@@ -101,6 +101,7 @@ public interface JetControlFlowBuilder {
|
||||
enum PredefinedOperation {
|
||||
AND,
|
||||
OR,
|
||||
ELVIS,
|
||||
NOT_NULL_ASSERTION
|
||||
}
|
||||
void predefinedOperation(@NotNull JetExpression expression, @Nullable PredefinedOperation operation);
|
||||
|
||||
@@ -250,7 +250,7 @@ public class JetControlFlowProcessor {
|
||||
public void visitBinaryExpression(@NotNull JetBinaryExpression expression) {
|
||||
JetSimpleNameExpression operationReference = expression.getOperationReference();
|
||||
IElementType operationType = operationReference.getReferencedNameElementType();
|
||||
if (!ImmutableSet.of(ANDAND, OROR, EQ, ELVIS).contains(operationType)) {
|
||||
if (!ImmutableSet.of(ANDAND, OROR, EQ, JetTokens.ELVIS).contains(operationType)) {
|
||||
mark(expression);
|
||||
}
|
||||
JetExpression right = expression.getRight();
|
||||
@@ -296,13 +296,14 @@ public class JetControlFlowProcessor {
|
||||
generateBothArguments(expression);
|
||||
}
|
||||
}
|
||||
else if (operationType == ELVIS) {
|
||||
else if (operationType == JetTokens.ELVIS) {
|
||||
generateInstructions(expression.getLeft(), false);
|
||||
Label afterElvis = builder.createUnboundLabel();
|
||||
builder.jumpOnTrue(afterElvis);
|
||||
if (right != null) {
|
||||
generateInstructions(right, false);
|
||||
}
|
||||
builder.predefinedOperation(expression, JetControlFlowBuilder.PredefinedOperation.ELVIS);
|
||||
builder.bindLabel(afterElvis);
|
||||
}
|
||||
else if (operationType == JetTokens.EQEQ || operationType == JetTokens.EXCLEQ) {
|
||||
|
||||
Reference in New Issue
Block a user