Skip to content

Commit c1ecafa

Browse files
authored
Fix painless return type cast for list shortcut (elastic#126724)
This fixes an issue where if a Painless getter method return type didn't match a Java getter method return type we add a cast. Currentlythis is adding an extraneous cast. Closes: elastic#70682
1 parent 9d18d52 commit c1ecafa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

docs/changelog/126724.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 126724
2+
summary: Fix painless return type cast for list shortcut
3+
area: Infra/Scripting
4+
type: bug
5+
issues: []

modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultIRTreeToASMBytesPhase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ public void visitLoadDotShortcut(LoadDotShortcutNode irDotSubShortcutNode, Write
14651465
PainlessMethod getterPainlessMethod = irDotSubShortcutNode.getDecorationValue(IRDMethod.class);
14661466
methodWriter.invokeMethodCall(getterPainlessMethod);
14671467

1468-
if (getterPainlessMethod.returnType().equals(getterPainlessMethod.javaMethod().getReturnType()) == false) {
1468+
if (getterPainlessMethod.returnType() != getterPainlessMethod.javaMethod().getReturnType()) {
14691469
methodWriter.checkCast(MethodWriter.getType(getterPainlessMethod.returnType()));
14701470
}
14711471
}
@@ -1478,7 +1478,7 @@ public void visitLoadListShortcut(LoadListShortcutNode irLoadListShortcutNode, W
14781478
PainlessMethod getterPainlessMethod = irLoadListShortcutNode.getDecorationValue(IRDMethod.class);
14791479
methodWriter.invokeMethodCall(getterPainlessMethod);
14801480

1481-
if (getterPainlessMethod.returnType() == getterPainlessMethod.javaMethod().getReturnType()) {
1481+
if (getterPainlessMethod.returnType() != getterPainlessMethod.javaMethod().getReturnType()) {
14821482
methodWriter.checkCast(MethodWriter.getType(getterPainlessMethod.returnType()));
14831483
}
14841484
}

0 commit comments

Comments
 (0)