painless: make compound statement like a[1]++ work with def. There was also a bug with the size of LDefArray: fixed
This commit is contained in:
parent
d221cd14d2
commit
65aca4f71c
|
@ -23,6 +23,8 @@ import org.elasticsearch.painless.Definition.Type;
|
|||
|
||||
/**
|
||||
* The superclass for all LDef* (link) nodes that store or return a DEF. (Internal only.)
|
||||
* For this node it is allowed to change {@link ALink#after} from outside, by default
|
||||
* {@code after} is {@code DEF}.
|
||||
*/
|
||||
abstract class ADefLink extends ALink {
|
||||
|
||||
|
|
|
@ -215,6 +215,12 @@ public final class EChain extends AExpression {
|
|||
there = AnalyzerCaster.getLegalCast(definition, location, last.after, promote, false);
|
||||
back = AnalyzerCaster.getLegalCast(definition, location, promote, last.after, true);
|
||||
|
||||
if (last instanceof ADefLink) {
|
||||
final ADefLink lastDef = (ADefLink) last;
|
||||
// Unfortunately, we don't know the real type because we load from DEF and store to DEF!
|
||||
lastDef.storeValueType = last.after;
|
||||
}
|
||||
|
||||
statement = true;
|
||||
actual = read ? last.after : definition.voidType;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ final class LDefArray extends ADefLink {
|
|||
AExpression index;
|
||||
|
||||
LDefArray(final int line, final String location, final AExpression index) {
|
||||
super(line, location, 0);
|
||||
super(line, location, 2);
|
||||
|
||||
this.index = index;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,14 @@ public class ArrayTests extends ScriptTestCase {
|
|||
assertEquals(5, exec("def x = new def[4]; x[0] = 5; return x[0];"));
|
||||
}
|
||||
|
||||
public void testArrayCompoundInt() {
|
||||
assertEquals(6, exec("int[] x = new int[5]; x[0] = 5; x[0]++; return x[0];"));
|
||||
}
|
||||
|
||||
public void testArrayCompoundDef() {
|
||||
assertEquals(6, exec("def x = new int[5]; x[0] = 5; x[0]++; return x[0];"));
|
||||
}
|
||||
|
||||
public void testForLoop() {
|
||||
assertEquals(999*1000/2, exec("def a = new int[1000]; for (int x = 0; x < a.length; x++) { a[x] = x; } "+
|
||||
"int total = 0; for (int x = 0; x < a.length; x++) { total += a[x]; } return total;"));
|
||||
|
|
Loading…
Reference in New Issue