From 95a1b5b2a368b30369e522c972f5e2b53462af9c Mon Sep 17 00:00:00 2001 From: Jack Conradson Date: Mon, 16 May 2016 14:18:05 -0700 Subject: [PATCH] Fixed a casting bug in Painless. --- .../java/org/elasticsearch/painless/node/EChain.java | 10 ++++++++-- .../org/elasticsearch/painless/node/LDefArray.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java index 4b89fcbcb08..484440cd981 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EChain.java @@ -233,6 +233,7 @@ public final class EChain extends AExpression { if (last instanceof ADefLink) { final ADefLink lastDef = (ADefLink) last; expression.analyze(settings, definition, variables); + // TODO: does it make more sense to just re-use last.after instead of using storeValueType? lastDef.storeValueType = expression.expected = expression.actual; this.actual = read ? lastDef.storeValueType : definition.voidType; } else { @@ -241,7 +242,7 @@ public final class EChain extends AExpression { expression.analyze(settings, definition, variables); this.actual = read ? last.after : definition.voidType; } - + expression = expression.cast(settings, definition, variables); this.statement = true; } @@ -316,7 +317,12 @@ public final class EChain extends AExpression { expression.write(settings, definition, adapter); if (link.load) { - WriterUtility.writeDup(adapter, link.after.sort.size, link.size); + // storeValueType may be different from after, so use storeValueType if last is an ADefLink + if (last instanceof ADefLink) { + WriterUtility.writeDup(adapter, ((ADefLink)last).storeValueType.sort.size, link.size); + } else { + WriterUtility.writeDup(adapter, link.after.sort.size, link.size); + } } link.store(settings, definition, adapter); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java index df1c5ffac0a..10271c35df2 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/LDefArray.java @@ -41,7 +41,6 @@ final class LDefArray extends ADefLink { this.index = index; } - @Override ALink analyze(final CompilerSettings settings, final Definition definition, final Variables variables) { index.analyze(settings, definition, variables); @@ -69,6 +68,7 @@ final class LDefArray extends ADefLink { if (storeValueType == null) { throw new IllegalStateException(error("Illegal tree structure.")); } + final String desc = Type.getMethodDescriptor(definition.voidType.type, definition.defType.type, index.actual.type, storeValueType.type); adapter.invokeDynamic("arrayStore", desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.ARRAY_STORE);