public void registerReturnTypeConstraints(PsiType returnType, @NotNull PsiType targetType, PsiElement context) {
    returnType = substituteWithInferenceVariables(returnType);
    if (myErased) {
      PsiSubstitutor currentSubstitutor = resolveSubset(myInferenceVariables, mySiteSubstitutor);
      addConstraint(new TypeCompatibilityConstraint(targetType,
                                                    TypeConversionUtil.erasure(currentSubstitutor.substitute(returnType))));
    }
    else if (FunctionalInterfaceParameterizationUtil.isWildcardParameterized(returnType)) {
      final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(returnType);
      final PsiClass psiClass = resolveResult.getElement();
      if (psiClass != null) {
        LOG.assertTrue(returnType instanceof PsiClassType);
        PsiClassType substitutedCapture = (PsiClassType)PsiUtil.captureToplevelWildcards(returnType, context);
        final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();
        final PsiType[] parameters = substitutedCapture.getParameters();
        final InferenceVariable[] copy = initFreshVariablesForCapturedBounds(typeParameters, parameters);
        final PsiType[] newParameters = new PsiType[parameters.length];
        final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myManager.getProject());
        int idx = 0;
        for (int i = 0; i < parameters.length; i++) {
          newParameters[i] = parameters[i];
          if (parameters[i] instanceof PsiCapturedWildcardType) {
            newParameters[i] = elementFactory.createType(copy[idx++]);
          }
        }
        substitutedCapture = elementFactory.createType(psiClass, newParameters);

        myIncorporationPhase.addCapture(copy, (PsiClassType)returnType);
        addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture));
      }
    } else {
      final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType);
      if (inferenceVariable != null) {
        final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor);
        final PsiType substitutedReturnType = substitutor.substitute(inferenceVariable);
        if (substitutedReturnType != null) {
          addConstraint(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutedReturnType, context)));
        }
      }
      else {
        addConstraint(new TypeCompatibilityConstraint(targetType, returnType));
      }
    }
  }
public void registerReturnTypeConstraints(PsiType returnType, @NotNull PsiType targetType, PsiElement context)