2222import org .elasticsearch .painless .AnalyzerCaster ;
2323import org .elasticsearch .painless .Definition ;
2424import org .elasticsearch .painless .Definition .Method ;
25- import org .elasticsearch .painless .Definition .Type ;
25+ import org .elasticsearch .painless .Definition .def ;
2626import org .elasticsearch .painless .FunctionRef ;
2727import org .elasticsearch .painless .Globals ;
2828import org .elasticsearch .painless .Locals ;
@@ -101,14 +101,14 @@ void extractVariables(Set<String> variables) {
101101
102102 @ Override
103103 void analyze (Locals locals ) {
104- final Type returnType ;
105- final List <String > actualParamTypeStrs ;
104+ Class <?> returnType ;
105+ List <String > actualParamTypeStrs ;
106106 Method interfaceMethod ;
107107 // inspect the target first, set interface method if we know it.
108108 if (expected == null ) {
109109 interfaceMethod = null ;
110110 // we don't know anything: treat as def
111- returnType = locals . getDefinition (). DefType ;
111+ returnType = def . class ;
112112 // don't infer any types, replace any null types with def
113113 actualParamTypeStrs = new ArrayList <>(paramTypeStrs .size ());
114114 for (String type : paramTypeStrs ) {
@@ -131,9 +131,9 @@ void analyze(Locals locals) {
131131 "] in [" + Definition .ClassToName (expected ) + "]" );
132132 // for method invocation, its allowed to ignore the return value
133133 if (interfaceMethod .rtn .equals (locals .getDefinition ().voidType )) {
134- returnType = locals . getDefinition (). DefType ;
134+ returnType = def . class ;
135135 } else {
136- returnType = interfaceMethod .rtn ;
136+ returnType = Definition . TypeToClass ( interfaceMethod .rtn ) ;
137137 }
138138 // replace any null types with the actual type
139139 actualParamTypeStrs = new ArrayList <>(paramTypeStrs .size ());
@@ -169,11 +169,11 @@ void analyze(Locals locals) {
169169 paramNames .addAll (paramNameStrs );
170170
171171 // desugar lambda body into a synthetic method
172- desugared = new SFunction (reserved , location , returnType . name , name ,
172+ desugared = new SFunction (reserved , location , Definition . ClassToName ( returnType ) , name ,
173173 paramTypes , paramNames , statements , true );
174174 desugared .generateSignature (locals .getDefinition ());
175- desugared .analyze (Locals .newLambdaScope (locals .getProgramScope (), returnType , desugared . parameters ,
176- captures .size (), reserved .getMaxLoopCounter ()));
175+ desugared .analyze (Locals .newLambdaScope (locals .getProgramScope (), locals . getDefinition (). ClassToType ( returnType ) ,
176+ desugared . parameters , captures .size (), reserved .getMaxLoopCounter ()));
177177
178178 // setup method reference to synthetic method
179179 if (expected == null ) {
@@ -190,12 +190,12 @@ void analyze(Locals locals) {
190190
191191 // check casts between the interface method and the delegate method are legal
192192 for (int i = 0 ; i < interfaceMethod .arguments .size (); ++i ) {
193- Type from = interfaceMethod .arguments .get (i );
194- Type to = desugared .parameters .get (i + captures .size ()).type ;
195- AnalyzerCaster .getLegalCast (location , Definition . TypeToClass ( from ), Definition . TypeToClass ( to ) , false , true );
193+ Class <?> from = Definition . TypeToClass ( interfaceMethod .arguments .get (i ) );
194+ Class <?> to = Definition . TypeToClass ( desugared .parameters .get (i + captures .size ()).type ) ;
195+ AnalyzerCaster .getLegalCast (location , from , to , false , true );
196196 }
197197
198- if (interfaceMethod .rtn .equals ( locals . getDefinition (). voidType ) == false ) {
198+ if (interfaceMethod .rtn .clazz != void . class ) {
199199 AnalyzerCaster .getLegalCast (
200200 location , Definition .TypeToClass (desugared .rtnType ), Definition .TypeToClass (interfaceMethod .rtn ), false , true );
201201 }
@@ -212,7 +212,7 @@ void write(MethodWriter writer, Globals globals) {
212212 writer .writeDebugInfo (location );
213213 // load captures
214214 for (Variable capture : captures ) {
215- writer .visitVarInsn (capture .type .type .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
215+ writer .visitVarInsn (MethodWriter . getType ( capture .type .clazz ) .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
216216 }
217217
218218 writer .invokeDynamic (
@@ -230,7 +230,7 @@ void write(MethodWriter writer, Globals globals) {
230230 writer .push ((String )null );
231231 // load captures
232232 for (Variable capture : captures ) {
233- writer .visitVarInsn (capture .type .type .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
233+ writer .visitVarInsn (MethodWriter . getType ( capture .type .clazz ) .getOpcode (Opcodes .ILOAD ), capture .getSlot ());
234234 }
235235 }
236236
@@ -247,7 +247,7 @@ public String getPointer() {
247247 public org .objectweb .asm .Type [] getCaptures () {
248248 org .objectweb .asm .Type [] types = new org .objectweb .asm .Type [captures .size ()];
249249 for (int i = 0 ; i < types .length ; i ++) {
250- types [i ] = captures .get (i ).type .type ;
250+ types [i ] = MethodWriter . getType ( captures .get (i ).type .clazz ) ;
251251 }
252252 return types ;
253253 }
0 commit comments