public ExpressionNode RemoveAmbiguity(ContextNode context, TypeReference expectedType)
 {
     if (!expectedType.IsFunctorType())
     {
         return(this);
     }
     try
     {
         var paramz = MetadataHelpers.GetFunctorParamTypes(context.Parser.Assembly, expectedType);
         var method = AssemblyRegistry.GetCompatibleMethod(methods.ToList(), paramz);
         return(new MethodNode(method, instance, context, SequencePoint));
     }
     catch (AssemblyRegistry.AmbiguousMethodException)
     {
         return(this);
     }
 }
        private static ExpressionNode AsFunctor(ContextNode context, ExpressionNode node, IEnumerable <ExpressionNode> args, SequencePoint point)
        {
            if (!node.IsGettable || !node.ExpressionReturnType.IsFunctorType())
            {
                return(null);
            }

            if (node.ExpressionReturnType.MatchesArgumentList(context.Parser.Assembly, args.Select(a => a.ExpressionReturnType).ToList()))
            {
                return(new MethodCallNode(node, MetadataHelpers.GetFunctorReturnType(context.Parser.Assembly, node.ExpressionReturnType), args.ToList(), point));
            }
            else
            {
                ErrorCode.TypeMismatch.ReportAndThrow(point, "Cannot call functor, requires parameters ({0}), called with ({1})",
                                                      String.Join(", ", MetadataHelpers.GetFunctorParamTypes(context.Parser.Assembly, node.ExpressionReturnType).Select(p => p.FullName)),
                                                      String.Join(", ", args.Select(a => a.ExpressionReturnType.FullName)));
                return(null);//unreachable
            }
        }