3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-08 04:20:06 +01:00

Fix pre- and post- ops

(cherry picked from commit 0f787a89b8f2b0f29e0e4a2327224a3b0d050171)
Dieser Commit ist enthalten in:
Octavia Togami 2020-02-25 16:20:21 -08:00 committet von MattBDev
Ursprung 6d9f30e6a6
Commit e20765beef
2 geänderte Dateien mit 11 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -269,13 +269,14 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
return ExpressionHandles.call(data -> { return ExpressionHandles.call(data -> {
LocalSlot.Variable variable = ExpressionHandles.getVariable(data, target); LocalSlot.Variable variable = ExpressionHandles.getVariable(data, target);
double value = variable.getValue(); double value = variable.getValue();
double result = value;
if (opType == INCREMENT) { if (opType == INCREMENT) {
value++; value++;
} else { } else {
value--; value--;
} }
variable.setValue(value); variable.setValue(value);
return value; return result;
}); });
} }
@ -286,14 +287,13 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
return ExpressionHandles.call(data -> { return ExpressionHandles.call(data -> {
LocalSlot.Variable variable = ExpressionHandles.getVariable(data, target); LocalSlot.Variable variable = ExpressionHandles.getVariable(data, target);
double value = variable.getValue(); double value = variable.getValue();
double result = value;
if (opType == INCREMENT) { if (opType == INCREMENT) {
value++; value++;
} else { } else {
value--; value--;
} }
variable.setValue(value); variable.setValue(value);
return result; return value;
}); });
} }

Datei anzeigen

@ -84,6 +84,14 @@ class ExpressionTest extends BaseExpressionTest {
checkTestCase("3+1", 4); checkTestCase("3+1", 4);
} }
@Test
void testPostPreOps() {
checkTestCase("a=0; b=a++; a+b", 1);
checkTestCase("a=0; b=++a; a+b", 2);
checkTestCase("a=0; b=a--; a+b", -1);
checkTestCase("a=0; b=--a; a+b", -2);
}
@Test @Test
public void testErrors() { public void testErrors() {
// test lexer errors // test lexer errors