|
19 | 19 |
|
20 | 20 | package org.elasticsearch.painless.node;
|
21 | 21 |
|
| 22 | +import org.elasticsearch.painless.AnalyzerCaster; |
22 | 23 | import org.elasticsearch.painless.Location;
|
23 | 24 | import org.elasticsearch.painless.Scope;
|
24 | 25 | import org.elasticsearch.painless.ir.BraceNode;
|
|
28 | 29 | import org.elasticsearch.painless.ir.ExpressionNode;
|
29 | 30 | import org.elasticsearch.painless.ir.ListSubShortcutNode;
|
30 | 31 | import org.elasticsearch.painless.ir.MapSubShortcutNode;
|
| 32 | +import org.elasticsearch.painless.lookup.PainlessCast; |
31 | 33 | import org.elasticsearch.painless.lookup.PainlessLookupUtility;
|
32 | 34 | import org.elasticsearch.painless.lookup.PainlessMethod;
|
33 | 35 | import org.elasticsearch.painless.lookup.def;
|
@@ -66,12 +68,13 @@ Output analyze(ClassNode classNode, ScriptRoot scriptRoot, Scope scope, Input in
|
66 | 68 | Input indexInput = new Input();
|
67 | 69 | indexInput.expected = int.class;
|
68 | 70 | Output indexOutput = index.analyze(classNode, scriptRoot, scope, indexInput);
|
69 |
| - index.cast(indexInput, indexOutput); |
| 71 | + PainlessCast indexCast = AnalyzerCaster.getLegalCast(index.location, |
| 72 | + indexOutput.actual, indexInput.expected, indexInput.explicit, indexInput.internal); |
70 | 73 |
|
71 | 74 | output.actual = prefixOutput.actual.getComponentType();
|
72 | 75 |
|
73 | 76 | BraceSubNode braceSubNode = new BraceSubNode();
|
74 |
| - braceSubNode.setChildNode(index.cast(indexOutput)); |
| 77 | + braceSubNode.setChildNode(cast(indexOutput.expressionNode, indexCast)); |
75 | 78 | braceSubNode.setLocation(location);
|
76 | 79 | braceSubNode.setExpressionType(output.actual);
|
77 | 80 | expressionNode = braceSubNode;
|
@@ -109,20 +112,22 @@ Output analyze(ClassNode classNode, ScriptRoot scriptRoot, Scope scope, Input in
|
109 | 112 | }
|
110 | 113 |
|
111 | 114 | Output indexOutput;
|
| 115 | + PainlessCast indexCast; |
112 | 116 |
|
113 | 117 | if ((input.read == false || getter != null) && (input.write == false || setter != null)) {
|
114 | 118 | Input indexInput = new Input();
|
115 | 119 | indexInput.expected = setter != null ? setter.typeParameters.get(0) : getter.typeParameters.get(0);
|
116 | 120 | indexOutput = index.analyze(classNode, scriptRoot, scope, indexInput);
|
117 |
| - index.cast(indexInput, indexOutput); |
| 121 | + indexCast = AnalyzerCaster.getLegalCast(index.location, |
| 122 | + indexOutput.actual, indexInput.expected, indexInput.explicit, indexInput.internal); |
118 | 123 |
|
119 | 124 | output.actual = setter != null ? setter.typeParameters.get(1) : getter.returnType;
|
120 | 125 | } else {
|
121 | 126 | throw createError(new IllegalArgumentException("Illegal map shortcut for type [" + canonicalClassName + "]."));
|
122 | 127 | }
|
123 | 128 |
|
124 | 129 | MapSubShortcutNode mapSubShortcutNode = new MapSubShortcutNode();
|
125 |
| - mapSubShortcutNode.setChildNode(index.cast(indexOutput)); |
| 130 | + mapSubShortcutNode.setChildNode(cast(indexOutput.expressionNode, indexCast)); |
126 | 131 | mapSubShortcutNode.setLocation(location);
|
127 | 132 | mapSubShortcutNode.setExpressionType(output.actual);
|
128 | 133 | mapSubShortcutNode.setGetter(getter);
|
@@ -150,20 +155,22 @@ Output analyze(ClassNode classNode, ScriptRoot scriptRoot, Scope scope, Input in
|
150 | 155 | }
|
151 | 156 |
|
152 | 157 | Output indexOutput;
|
| 158 | + PainlessCast indexCast; |
153 | 159 |
|
154 | 160 | if ((input.read == false || getter != null) && (input.write == false || setter != null)) {
|
155 | 161 | Input indexInput = new Input();
|
156 | 162 | indexInput.expected = int.class;
|
157 | 163 | indexOutput = index.analyze(classNode, scriptRoot, scope, indexInput);
|
158 |
| - index.cast(indexInput, indexOutput); |
| 164 | + indexCast = AnalyzerCaster.getLegalCast(index.location, |
| 165 | + indexOutput.actual, indexInput.expected, indexInput.explicit, indexInput.internal); |
159 | 166 |
|
160 | 167 | output.actual = setter != null ? setter.typeParameters.get(1) : getter.returnType;
|
161 | 168 | } else {
|
162 | 169 | throw createError(new IllegalArgumentException("Illegal list shortcut for type [" + canonicalClassName + "]."));
|
163 | 170 | }
|
164 | 171 |
|
165 | 172 | ListSubShortcutNode listSubShortcutNode = new ListSubShortcutNode();
|
166 |
| - listSubShortcutNode.setChildNode(index.cast(indexOutput)); |
| 173 | + listSubShortcutNode.setChildNode(cast(indexOutput.expressionNode, indexCast)); |
167 | 174 | listSubShortcutNode.setLocation(location);
|
168 | 175 | listSubShortcutNode.setExpressionType(output.actual);
|
169 | 176 | listSubShortcutNode.setGetter(getter);
|
|
0 commit comments