Exemple #1
0
  @Nullable
  public static OverrideCompatibilityInfo getBasicOverridabilityProblem(
      @NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
    if (superDescriptor instanceof FunctionDescriptor
            && !(subDescriptor instanceof FunctionDescriptor)
        || superDescriptor instanceof PropertyDescriptor
            && !(subDescriptor instanceof PropertyDescriptor)) {
      return OverrideCompatibilityInfo.incompatible("Member kind mismatch");
    }

    if (!(superDescriptor instanceof FunctionDescriptor)
        && !(superDescriptor instanceof PropertyDescriptor)) {
      throw new IllegalArgumentException(
          "This type of CallableDescriptor cannot be checked for overridability: "
              + superDescriptor);
    }

    // TODO: check outside of this method
    if (!superDescriptor.getName().equals(subDescriptor.getName())) {
      return OverrideCompatibilityInfo.incompatible("Name mismatch");
    }

    OverrideCompatibilityInfo receiverAndParameterResult =
        checkReceiverAndParameterCount(superDescriptor, subDescriptor);
    if (receiverAndParameterResult != null) {
      return receiverAndParameterResult;
    }

    return null;
  }
Exemple #2
0
  private void checkCallWithReceiver(
      @NotNull CallCheckerContext context,
      @NotNull CallableDescriptor targetDescriptor,
      @Nullable ReceiverValue receiver,
      @Nullable KtExpression expression) {
    if (receiver == null) return;

    CallableDescriptor varDescriptor = null;
    KtExpression receiverExpression = null;
    if (receiver instanceof ExpressionReceiver) {
      receiverExpression = ((ExpressionReceiver) receiver).getExpression();
      varDescriptor = getCalleeDescriptor(context, receiverExpression, true);
    } else if (receiver instanceof ExtensionReceiver) {
      ExtensionReceiver extensionReceiver = (ExtensionReceiver) receiver;
      CallableDescriptor extension = extensionReceiver.getDeclarationDescriptor();

      varDescriptor = extension.getExtensionReceiverParameter();
      assert varDescriptor != null
          : "Extension should have receiverParameterDescriptor: " + extension;

      receiverExpression = expression;
    }

    if (inlinableParameters.contains(varDescriptor)) {
      // check that it's invoke or inlinable extension
      checkLambdaInvokeOrExtensionCall(
          context, varDescriptor, targetDescriptor, receiverExpression);
    }
  }
Exemple #3
0
  /**
   * @return true iff this is a top-level declaration or a class member with no expected "this"
   *     object (e.g. static members in Java, values() and valueOf() methods of enum classes, etc.)
   */
  public static boolean isStaticDeclaration(@NotNull CallableDescriptor descriptor) {
    if (descriptor instanceof ConstructorDescriptor) return false;

    DeclarationDescriptor container = descriptor.getContainingDeclaration();
    return container instanceof PackageFragmentDescriptor
        || (container instanceof ClassDescriptor
            && descriptor.getDispatchReceiverParameter() == null);
  }
Exemple #4
0
 private static boolean isReturnTypeMoreSpecific(
     @NotNull CallableDescriptor a,
     @NotNull KotlinType aReturnType,
     @NotNull CallableDescriptor b,
     @NotNull KotlinType bReturnType) {
   KotlinTypeChecker typeChecker =
       DEFAULT.createTypeChecker(a.getTypeParameters(), b.getTypeParameters());
   return typeChecker.isSubtypeOf(aReturnType, bReturnType);
 }
Exemple #5
0
  @NotNull
  public OverrideCompatibilityInfo isOverridableByWithoutExternalConditions(
      @NotNull CallableDescriptor superDescriptor,
      @NotNull CallableDescriptor subDescriptor,
      boolean checkReturnType) {
    OverrideCompatibilityInfo basicOverridability =
        getBasicOverridabilityProblem(superDescriptor, subDescriptor);
    if (basicOverridability != null) return basicOverridability;

    List<KotlinType> superValueParameters = compiledValueParameters(superDescriptor);
    List<KotlinType> subValueParameters = compiledValueParameters(subDescriptor);

    List<TypeParameterDescriptor> superTypeParameters = superDescriptor.getTypeParameters();
    List<TypeParameterDescriptor> subTypeParameters = subDescriptor.getTypeParameters();

    if (superTypeParameters.size() != subTypeParameters.size()) {
      for (int i = 0; i < superValueParameters.size(); ++i) {
        // TODO: compare erasure
        if (!KotlinTypeChecker.DEFAULT.equalTypes(
            superValueParameters.get(i), subValueParameters.get(i))) {
          return OverrideCompatibilityInfo.incompatible("Type parameter number mismatch");
        }
      }
      return OverrideCompatibilityInfo.conflict("Type parameter number mismatch");
    }

    KotlinTypeChecker typeChecker = createTypeChecker(superTypeParameters, subTypeParameters);

    for (int i = 0; i < superTypeParameters.size(); i++) {
      if (!areTypeParametersEquivalent(
          superTypeParameters.get(i), subTypeParameters.get(i), typeChecker)) {
        return OverrideCompatibilityInfo.incompatible("Type parameter bounds mismatch");
      }
    }

    for (int i = 0; i < superValueParameters.size(); i++) {
      if (!areTypesEquivalent(
          superValueParameters.get(i), subValueParameters.get(i), typeChecker)) {
        return OverrideCompatibilityInfo.incompatible("Value parameter type mismatch");
      }
    }

    if (checkReturnType) {
      KotlinType superReturnType = superDescriptor.getReturnType();
      KotlinType subReturnType = subDescriptor.getReturnType();

      if (superReturnType != null && subReturnType != null) {
        boolean bothErrors = subReturnType.isError() && superReturnType.isError();
        if (!bothErrors && !typeChecker.isSubtypeOf(subReturnType, superReturnType)) {
          return OverrideCompatibilityInfo.conflict("Return type mismatch");
        }
      }
    }

    return OverrideCompatibilityInfo.success();
  }
Exemple #6
0
 static List<KotlinType> compiledValueParameters(CallableDescriptor callableDescriptor) {
   ReceiverParameterDescriptor receiverParameter =
       callableDescriptor.getExtensionReceiverParameter();
   List<KotlinType> parameters = new ArrayList<KotlinType>();
   if (receiverParameter != null) {
     parameters.add(receiverParameter.getType());
   }
   for (ValueParameterDescriptor valueParameterDescriptor :
       callableDescriptor.getValueParameters()) {
     parameters.add(valueParameterDescriptor.getType());
   }
   return parameters;
 }
Exemple #7
0
  @Nullable
  static OverrideCompatibilityInfo checkReceiverAndParameterCount(
      CallableDescriptor superDescriptor, CallableDescriptor subDescriptor) {
    if ((superDescriptor.getExtensionReceiverParameter() == null)
        != (subDescriptor.getExtensionReceiverParameter() == null)) {
      return OverrideCompatibilityInfo.incompatible("Receiver presence mismatch");
    }

    if (superDescriptor.getValueParameters().size() != subDescriptor.getValueParameters().size()) {
      return OverrideCompatibilityInfo.incompatible("Value parameter number mismatch");
    }

    return null;
  }
Exemple #8
0
  @Nullable
  static OverrideCompatibilityInfo checkReceiverAndParameterCount(
      CallableDescriptor superDescriptor, CallableDescriptor subDescriptor) {
    if ((superDescriptor.getExtensionReceiverParameter() == null)
        != (subDescriptor.getExtensionReceiverParameter() == null)) {
      return OverrideCompatibilityInfo.receiverPresenceMismatch();
    }

    if (superDescriptor.getValueParameters().size() != subDescriptor.getValueParameters().size()) {
      return OverrideCompatibilityInfo.valueParameterNumberMismatch();
    }

    return null;
  }
Exemple #9
0
  private static boolean isInvokeOrInlineExtension(@NotNull CallableDescriptor descriptor) {
    if (!(descriptor instanceof SimpleFunctionDescriptor)) {
      return false;
    }

    DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
    boolean isInvoke =
        descriptor.getName().equals(OperatorNameConventions.INVOKE)
            && containingDeclaration instanceof ClassDescriptor
            && FunctionTypesKt.isFunctionType(
                ((ClassDescriptor) containingDeclaration).getDefaultType());

    return isInvoke || InlineUtil.isInline(descriptor);
  }
Exemple #10
0
 private static boolean isInlinableParameter(@NotNull CallableDescriptor descriptor) {
   JetType type = descriptor.getReturnType();
   return type != null
       && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)
       && !type.isMarkedNullable()
       && !InlineUtil.hasNoinlineAnnotation(descriptor);
 }
  /** @return true if the member is an inherited implementation of a method from Any */
  private boolean isTrivial(@NotNull FunctionDescriptor function) {
    if (function.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
      return false;
    }

    for (CallableDescriptor overridden : OverrideResolver.getOverriddenDeclarations(function)) {
      if (overridden instanceof CallableMemberDescriptor
          && ((CallableMemberDescriptor) overridden).getKind()
              == CallableMemberDescriptor.Kind.DECLARATION
          && !overridden.getContainingDeclaration().equals(builtIns.getAny())) {
        return false;
      }
    }

    return true;
  }
Exemple #12
0
  private static boolean isInvokeOrInlineExtension(@NotNull CallableDescriptor descriptor) {
    if (!(descriptor instanceof SimpleFunctionDescriptor)) {
      return false;
    }

    DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
    boolean isInvoke =
        descriptor.getName().asString().equals("invoke")
            && containingDeclaration instanceof ClassDescriptor
            && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(
                ((ClassDescriptor) containingDeclaration).getDefaultType());

    return isInvoke
        ||
        // or inline extension
        ((SimpleFunctionDescriptor) descriptor).getInlineStrategy().isInline();
  }
Exemple #13
0
 private void checkRecursion(
     @NotNull CallCheckerContext context,
     @NotNull CallableDescriptor targetDescriptor,
     @NotNull KtElement expression) {
   if (targetDescriptor.getOriginal() == descriptor) {
     context.getTrace().report(Errors.RECURSION_IN_INLINE.on(expression, expression, descriptor));
   }
 }
Exemple #14
0
 public void checkRecursion(
     @NotNull BasicCallResolutionContext context,
     @NotNull CallableDescriptor targetDescriptor,
     @NotNull JetElement expression) {
   if (targetDescriptor.getOriginal() == descriptor) {
     context.trace.report(Errors.RECURSION_IN_INLINE.on(expression, expression, descriptor));
   }
 }
Exemple #15
0
  public static boolean isMoreSpecific(
      @NotNull CallableDescriptor a, @NotNull CallableDescriptor b) {
    KotlinType aReturnType = a.getReturnType();
    KotlinType bReturnType = b.getReturnType();

    assert aReturnType != null : "Return type of " + a + " is null";
    assert bReturnType != null : "Return type of " + b + " is null";

    if (!isVisibilityMoreSpecific(a, b)) return false;

    if (a instanceof SimpleFunctionDescriptor) {
      assert b instanceof SimpleFunctionDescriptor : "b is " + b.getClass();

      return isReturnTypeMoreSpecific(a, aReturnType, b, bReturnType);
    }
    if (a instanceof PropertyDescriptor) {
      assert b instanceof PropertyDescriptor : "b is " + b.getClass();

      PropertyDescriptor pa = (PropertyDescriptor) a;
      PropertyDescriptor pb = (PropertyDescriptor) b;

      if (!isAccessorMoreSpecific(pa.getSetter(), pb.getSetter())) return false;

      if (pa.isVar() && pb.isVar()) {
        return DEFAULT
            .createTypeChecker(a.getTypeParameters(), b.getTypeParameters())
            .equalTypes(aReturnType, bReturnType);
      } else {
        // both vals or var vs val: val can't be more specific then var
        return !(!pa.isVar() && pb.isVar())
            && isReturnTypeMoreSpecific(a, aReturnType, b, bReturnType);
      }
    }
    throw new IllegalArgumentException("Unexpected callable: " + a.getClass());
  }
  public static boolean shouldBeInlined(@NotNull CallableDescriptor descriptor) {
    if (descriptor instanceof SimpleFunctionDescriptor) {
      return InlineUtil.isInline(descriptor);
    }

    if (descriptor instanceof ValueParameterDescriptor) {
      return InlineUtil.isInline(descriptor.getContainingDeclaration())
          && InlineUtil.isInlineLambdaParameter((ParameterDescriptor) descriptor);
    }

    return false;
  }
Exemple #17
0
 private void checkVisibility(
     @NotNull CallableDescriptor declarationDescriptor,
     @NotNull JetElement expression,
     @NotNull BasicCallResolutionContext context) {
   boolean declarationDescriptorIsPublicApi =
       getIsEffectivelyPublicApi(declarationDescriptor)
           || isDefinedInInlineFunction(declarationDescriptor);
   if (isEffectivelyPublicApiFunction
       && !declarationDescriptorIsPublicApi
       && declarationDescriptor.getVisibility() != Visibilities.LOCAL) {
     context.trace.report(
         Errors.INVISIBLE_MEMBER_FROM_INLINE.on(expression, declarationDescriptor, descriptor));
   }
 }
Exemple #18
0
 private void checkVisibilityAndAccess(
     @NotNull CallableDescriptor declarationDescriptor,
     @NotNull KtElement expression,
     @NotNull CallCheckerContext context) {
   boolean declarationDescriptorIsPublicApi =
       DescriptorUtilsKt.isEffectivelyPublicApi(declarationDescriptor)
           || isDefinedInInlineFunction(declarationDescriptor);
   if (isEffectivelyPublicApiFunction
       && !declarationDescriptorIsPublicApi
       && declarationDescriptor.getVisibility() != Visibilities.LOCAL) {
     context
         .getTrace()
         .report(
             Errors.NON_PUBLIC_CALL_FROM_PUBLIC_INLINE.on(
                 expression, declarationDescriptor, descriptor));
   } else {
     checkPrivateClassMemberAccess(declarationDescriptor, expression, context);
   }
 }
Exemple #19
0
 public static boolean isExtension(@NotNull CallableDescriptor descriptor) {
   return (descriptor.getExtensionReceiverParameter() != null);
 }
Exemple #20
0
  @NotNull
  private OverrideCompatibilityInfo isOverridableBy(
      @NotNull CallableDescriptor superDescriptor,
      @NotNull CallableDescriptor subDescriptor,
      boolean checkReturnType) {
    if (superDescriptor instanceof FunctionDescriptor) {
      if (!(subDescriptor instanceof FunctionDescriptor))
        return OverrideCompatibilityInfo.memberKindMismatch();
    } else if (superDescriptor instanceof PropertyDescriptor) {
      if (!(subDescriptor instanceof PropertyDescriptor))
        return OverrideCompatibilityInfo.memberKindMismatch();
    } else {
      throw new IllegalArgumentException(
          "This type of CallableDescriptor cannot be checked for overridability: "
              + superDescriptor);
    }

    // TODO: check outside of this method
    if (!superDescriptor.getName().equals(subDescriptor.getName())) {
      return OverrideCompatibilityInfo.nameMismatch();
    }

    OverrideCompatibilityInfo receiverAndParameterResult =
        checkReceiverAndParameterCount(superDescriptor, subDescriptor);
    if (receiverAndParameterResult != null) {
      return receiverAndParameterResult;
    }

    List<JetType> superValueParameters = compiledValueParameters(superDescriptor);
    List<JetType> subValueParameters = compiledValueParameters(subDescriptor);

    List<TypeParameterDescriptor> superTypeParameters = superDescriptor.getTypeParameters();
    List<TypeParameterDescriptor> subTypeParameters = subDescriptor.getTypeParameters();

    if (superTypeParameters.size() != subTypeParameters.size()) {
      for (int i = 0; i < superValueParameters.size(); ++i) {
        JetType superValueParameterType = getUpperBound(superValueParameters.get(i));
        JetType subValueParameterType = getUpperBound(subValueParameters.get(i));
        // TODO: compare erasure
        if (!JetTypeChecker.DEFAULT.equalTypes(superValueParameterType, subValueParameterType)) {
          return OverrideCompatibilityInfo.typeParameterNumberMismatch();
        }
      }
      return OverrideCompatibilityInfo.valueParameterTypeMismatch(
          null, null, OverrideCompatibilityInfo.Result.CONFLICT);
    }

    final Map<TypeConstructor, TypeConstructor> matchingTypeConstructors =
        new HashMap<TypeConstructor, TypeConstructor>();
    for (int i = 0, typeParametersSize = superTypeParameters.size(); i < typeParametersSize; i++) {
      TypeParameterDescriptor superTypeParameter = superTypeParameters.get(i);
      TypeParameterDescriptor subTypeParameter = subTypeParameters.get(i);
      matchingTypeConstructors.put(
          superTypeParameter.getTypeConstructor(), subTypeParameter.getTypeConstructor());
    }

    JetTypeChecker.TypeConstructorEquality localEqualityAxioms =
        new JetTypeChecker.TypeConstructorEquality() {
          @Override
          public boolean equals(@NotNull TypeConstructor a, @NotNull TypeConstructor b) {
            if (equalityAxioms.equals(a, b)) return true;
            TypeConstructor img1 = matchingTypeConstructors.get(a);
            TypeConstructor img2 = matchingTypeConstructors.get(b);
            if (!(img1 != null && img1.equals(b)) && !(img2 != null && img2.equals(a))) {
              return false;
            }
            return true;
          }
        };

    for (int i = 0, typeParametersSize = superTypeParameters.size(); i < typeParametersSize; i++) {
      TypeParameterDescriptor superTypeParameter = superTypeParameters.get(i);
      TypeParameterDescriptor subTypeParameter = subTypeParameters.get(i);

      if (!areTypesEquivalent(
          superTypeParameter.getUpperBoundsAsType(),
          subTypeParameter.getUpperBoundsAsType(),
          localEqualityAxioms)) {
        return OverrideCompatibilityInfo.boundsMismatch(superTypeParameter, subTypeParameter);
      }
    }

    for (int i = 0, unsubstitutedValueParametersSize = superValueParameters.size();
        i < unsubstitutedValueParametersSize;
        i++) {
      JetType superValueParameter = superValueParameters.get(i);
      JetType subValueParameter = subValueParameters.get(i);

      if (!areTypesEquivalent(superValueParameter, subValueParameter, localEqualityAxioms)) {
        return OverrideCompatibilityInfo.valueParameterTypeMismatch(
            superValueParameter, subValueParameter, INCOMPATIBLE);
      }
    }

    if (checkReturnType) {
      JetType superReturnType = superDescriptor.getReturnType();
      JetType subReturnType = subDescriptor.getReturnType();

      if (superReturnType != null && subReturnType != null) {
        boolean bothErrors = subReturnType.isError() && superReturnType.isError();
        if (!bothErrors
            && !JetTypeChecker.withAxioms(localEqualityAxioms)
                .isSubtypeOf(subReturnType, superReturnType)) {
          return OverrideCompatibilityInfo.returnTypeMismatch(superReturnType, subReturnType);
        }
      }
    }

    for (ExternalOverridabilityCondition externalCondition : EXTERNAL_CONDITIONS) {
      if (!externalCondition.isOverridable(superDescriptor, subDescriptor)) {
        return OverrideCompatibilityInfo.externalConditionFailed(externalCondition.getClass());
      }
    }

    return OverrideCompatibilityInfo.success();
  }
Exemple #21
0
  @NotNull
  public OverrideCompatibilityInfo isOverridableByWithoutExternalConditions(
      @NotNull CallableDescriptor superDescriptor,
      @NotNull CallableDescriptor subDescriptor,
      boolean checkReturnType) {
    if (superDescriptor instanceof FunctionDescriptor
            && !(subDescriptor instanceof FunctionDescriptor)
        || superDescriptor instanceof PropertyDescriptor
            && !(subDescriptor instanceof PropertyDescriptor)) {
      return OverrideCompatibilityInfo.incompatible("Member kind mismatch");
    }

    if (!(superDescriptor instanceof FunctionDescriptor)
        && !(superDescriptor instanceof PropertyDescriptor)) {
      throw new IllegalArgumentException(
          "This type of CallableDescriptor cannot be checked for overridability: "
              + superDescriptor);
    }

    // TODO: check outside of this method
    if (!superDescriptor.getName().equals(subDescriptor.getName())) {
      return OverrideCompatibilityInfo.incompatible("Name mismatch");
    }

    OverrideCompatibilityInfo receiverAndParameterResult =
        checkReceiverAndParameterCount(superDescriptor, subDescriptor);
    if (receiverAndParameterResult != null) {
      return receiverAndParameterResult;
    }

    List<KotlinType> superValueParameters = compiledValueParameters(superDescriptor);
    List<KotlinType> subValueParameters = compiledValueParameters(subDescriptor);

    List<TypeParameterDescriptor> superTypeParameters = superDescriptor.getTypeParameters();
    List<TypeParameterDescriptor> subTypeParameters = subDescriptor.getTypeParameters();

    if (superTypeParameters.size() != subTypeParameters.size()) {
      for (int i = 0; i < superValueParameters.size(); ++i) {
        // TODO: compare erasure
        if (!KotlinTypeChecker.DEFAULT.equalTypes(
            superValueParameters.get(i), subValueParameters.get(i))) {
          return OverrideCompatibilityInfo.incompatible("Type parameter number mismatch");
        }
      }
      return OverrideCompatibilityInfo.conflict("Type parameter number mismatch");
    }

    KotlinTypeChecker typeChecker = createTypeChecker(superTypeParameters, subTypeParameters);

    for (int i = 0; i < superTypeParameters.size(); i++) {
      if (!areTypeParametersEquivalent(
          superTypeParameters.get(i), subTypeParameters.get(i), typeChecker)) {
        return OverrideCompatibilityInfo.incompatible("Type parameter bounds mismatch");
      }
    }

    for (int i = 0; i < superValueParameters.size(); i++) {
      if (!areTypesEquivalent(
          superValueParameters.get(i), subValueParameters.get(i), typeChecker)) {
        return OverrideCompatibilityInfo.incompatible("Value parameter type mismatch");
      }
    }

    if (checkReturnType) {
      KotlinType superReturnType = superDescriptor.getReturnType();
      KotlinType subReturnType = subDescriptor.getReturnType();

      if (superReturnType != null && subReturnType != null) {
        boolean bothErrors = subReturnType.isError() && superReturnType.isError();
        if (!bothErrors && !typeChecker.isSubtypeOf(subReturnType, superReturnType)) {
          return OverrideCompatibilityInfo.conflict("Return type mismatch");
        }
      }
    }

    return OverrideCompatibilityInfo.success();
  }
Exemple #22
0
        @NotNull
        @Override
        public Collection<MutableResolvedCall<FunctionDescriptor>> transformCall(
            @NotNull CallCandidateResolutionContext<CallableDescriptor> context,
            @NotNull CallResolver callResolver,
            @NotNull ResolutionTask<CallableDescriptor, FunctionDescriptor> task) {
          CallableDescriptor descriptor = context.candidateCall.getCandidateDescriptor();
          if (descriptor instanceof FunctionDescriptor) {
            return super.transformCall(context, callResolver, task);
          }

          assert descriptor instanceof VariableDescriptor;
          JetType returnType = descriptor.getReturnType();
          if (returnType == null) {
            return Collections.emptyList();
          }

          final MutableResolvedCall<VariableDescriptor> variableResolvedCall =
              (MutableResolvedCall) context.candidateCall;

          JetExpression calleeExpression = task.call.getCalleeExpression();
          if (calleeExpression == null) return Collections.emptyList();

          ExpressionReceiver variableReceiver =
              new ExpressionReceiver(
                  calleeExpression, variableResolvedCall.getResultingDescriptor().getType());
          Call functionCall =
              new CallForImplicitInvoke(
                  context.explicitExtensionReceiverForInvoke, variableReceiver, task.call);

          DelegatingBindingTrace variableCallTrace = context.candidateCall.getTrace();
          BasicCallResolutionContext basicCallResolutionContext =
              BasicCallResolutionContext.create(
                  context
                      .replaceBindingTrace(variableCallTrace)
                      .replaceContextDependency(ContextDependency.DEPENDENT),
                  functionCall,
                  context.checkArguments,
                  context.dataFlowInfoForArguments);

          // 'invoke' call resolve
          TracingStrategyForInvoke tracingForInvoke =
              new TracingStrategyForInvoke(
                  calleeExpression, functionCall, variableReceiver.getType());
          OverloadResolutionResults<FunctionDescriptor> results =
              callResolver.resolveCallForInvoke(basicCallResolutionContext, tracingForInvoke);
          Collection<MutableResolvedCall<FunctionDescriptor>> calls =
              ((OverloadResolutionResultsImpl<FunctionDescriptor>) results).getResultingCalls();

          return Collections2.transform(
              calls,
              new Function<
                  MutableResolvedCall<FunctionDescriptor>,
                  MutableResolvedCall<FunctionDescriptor>>() {
                @Override
                public MutableResolvedCall<FunctionDescriptor> apply(
                    MutableResolvedCall<FunctionDescriptor> functionResolvedCall) {
                  return new VariableAsFunctionResolvedCallImpl(
                      functionResolvedCall, variableResolvedCall);
                }
              });
        }