if (!interfaceType.isInterface() || methods.size() != 1) {
throw Error.lambdaTypeMustBeSingleMethodInterface();
}
final MethodInfo method = methods.get(0);
final ParameterList methodParameters = method.getParameters();
if (methodParameters.size() > 0) {
if (parameters.size() != methodParameters.size()) {
throw Error.incorrectNumberOfLambdaArguments();
}
final Set<ParameterExpression> set = new HashSet<>(parameters.size());
for (int i = 0, n = methodParameters.size(); i < n; i++) {
final ParameterExpression pex = parameters.get(i);
final ParameterInfo pi = methodParameters.get(i);
verifyCanRead(pex, "parameters");
final Type pType = pi.getParameterType();
if (!TypeUtils.areEquivalent(pex.getType(), pType)) {
if (!pType.isGenericParameter() || !pType.isAssignableFrom(pex.getType())) {
throw Error.parameterExpressionNotValidForDelegate(pex.getType(), pType);
}
}
if (set.contains(pex)) {
throw Error.duplicateVariable(pex);
}
set.add(pex);
}
}
else if (parameters.size() > 0) {
throw Error.incorrectNumberOfLambdaDeclarationParameters();
}
final Type returnType = method.getReturnType();
if (returnType != PrimitiveTypes.Void &&
!TypeUtils.areEquivalent(returnType, body.getType())) {
if (/*!returnType.isGenericParameter() ||*/ !returnType.isAssignableFrom(body.getType())) {
throw Error.expressionTypeDoesNotMatchReturn(body.getType(), returnType);