Browse Source

Added checkcast in function interface wrapping's result

kindlich 4 years ago
parent
commit
8173105c2b
No known key found for this signature in database

+ 17
- 5
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

2075
 			}
2075
 			}
2076
 			
2076
 			
2077
 			bridgeWriter.invokeVirtual(new JavaMethod(JavaClass.fromInternalName(className, JavaClass.Kind.CLASS), JavaMethod.Kind.INSTANCE, methodInfo.name, methodInfo.compile, descriptor, methodInfo.modifiers, methodInfo.genericResult));
2077
 			bridgeWriter.invokeVirtual(new JavaMethod(JavaClass.fromInternalName(className, JavaClass.Kind.CLASS), JavaMethod.Kind.INSTANCE, methodInfo.name, methodInfo.compile, descriptor, methodInfo.modifiers, methodInfo.genericResult));
2078
-			if(expression.header.getReturnType().type != BasicTypeID.VOID) {
2079
-				bridgeWriter.returnType(context.getType(expression.header.getReturnType()));
2080
-			}
2078
+            final StoredType returnType = expression.header.getReturnType();
2079
+            if(returnType.type != BasicTypeID.VOID) {
2080
+                final Type returnTypeASM = context.getType(returnType);
2081
+                if(!CompilerUtils.isPrimitive(returnType.type)) {
2082
+                    bridgeWriter.checkCast(returnTypeASM);
2083
+                }
2084
+                bridgeWriter.returnType(returnTypeASM);
2085
+            }
2081
 			
2086
 			
2082
 			bridgeWriter.ret();
2087
 			bridgeWriter.ret();
2083
 			bridgeWriter.end();
2088
 			bridgeWriter.end();
4200
 			{
4205
 			{
4201
 				final Class<?>[] methodParameterTypes = functionalInterfaceMethod.getParameterTypes();
4206
 				final Class<?>[] methodParameterTypes = functionalInterfaceMethod.getParameterTypes();
4202
 				for (int i = 0; i < methodParameterTypes.length; i++) {
4207
 				for (int i = 0; i < methodParameterTypes.length; i++) {
4203
-					functionWriter.load(Type.getType(methodParameterTypes[i]), i + 1);
4208
+                    final Class<?> methodParameterType = methodParameterTypes[i];
4209
+                    final Type type = Type.getType(methodParameterType);
4210
+                    functionWriter.load(type, i + 1);
4204
 				}
4211
 				}
4205
 			}
4212
 			}
4206
 
4213
 
4207
 			//Invokes the wrapped interface's method and returns the result
4214
 			//Invokes the wrapped interface's method and returns the result
4208
 			functionWriter.invokeInterface(wrappedMethod);
4215
 			functionWriter.invokeInterface(wrappedMethod);
4209
-			functionWriter.returnType(context.getType(((FunctionTypeID) expression.value.type.type).header.getReturnType()));
4216
+            final StoredType returnType = ((FunctionTypeID) expression.value.type.type).header.getReturnType();
4217
+            final Type type = context.getType(returnType);
4218
+            if(!CompilerUtils.isPrimitive(returnType.type)) {
4219
+                functionWriter.checkCast(type);
4220
+            }
4221
+            functionWriter.returnType(type);
4210
 
4222
 
4211
 			functionWriter.ret();
4223
 			functionWriter.ret();
4212
 			functionWriter.end();
4224
 			functionWriter.end();

Loading…
Cancel
Save