public override Expression DoResolve(ResolveContext rc) { eclass = ExprClass.Value; MemberAccess mre = expr as MemberAccess; SimpleName typeorvar = mre != null ? mre.LeftExpression as SimpleName : null; if (typeorvar != null && typeorvar.TypeArguments.Count == 0) { // Special handling for §7.6.4.1 Identicial simple names and type names typeorvar.lookupMode = NameLookupMode.Expression; Expression idRR = typeorvar.DoResolve(rc); Expression target = ResolveMemberReferenceOnGivenTarget(rc, idRR, mre); TypeExpression trr; if (rc.IsVariableReferenceWithSameType(idRR, out trr)) { // It's ambiguous Expression rr = ResolveInvocationOnGivenTarget(rc, target, arguments); Expression simpleNameRR = IsStaticResult(target, rr) ? trr : idRR; rc.Report.Warning(0, 1, loc, "Ambiguous simple name '{0}' was resolved to {1}", typeorvar.GetSignatureForError(), simpleNameRR.GetSignatureForError()); return(rr); } else { // It's not ambiguous return(ResolveInvocationOnGivenTarget(rc, target, arguments)); } } return(this); }
public override Expression DoResolve(TypeSystem.Resolver.ResolveContext rc) { Expression e = expr.DoResolve(rc); if (e == null) return null; if (e.eclass == ExprClass.MethodGroup) { rc.Report.Error(0, loc, "An anonymous type property `{0}' cannot be initialized with `{1}'", Name, e.GetSignatureForError()); return null; } ResolvedType = e.Type; if (ResolvedType.Kind == TypeKind.Void || ResolvedType.Kind == TypeKind.Pointer) { rc.Report.Error(0, loc, "An anonymous type property `{0}' cannot be initialized with `{1}'", Name, ResolvedType.ToString()); return null; } return e; }
public override string GetSignatureForError() { return(expr.GetSignatureForError() + "." + base.GetSignatureForError()); }
/// <summary> /// Resolves an invocation. /// </summary> /// <param name="target">The target of the invocation. Usually a MethodGroupResolveResult.</param> /// <param name="arguments"> /// Arguments passed to the method. /// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s! /// </param> /// <param name="argumentNames"> /// The argument names. Pass the null string for positional arguments. /// </param> /// <returns>InvocationExpression</returns> private Expression ResolveInvocation(ResolveContext rc, Expression target, Expression[] arguments, string[] argumentNames, bool allowOptionalParameters) { // C# 4.0 spec: §7.6.5 MethodGroupExpression mgrr = target as MethodGroupExpression; if (mgrr != null) { OverloadResolution or = mgrr.PerformOverloadResolution(rc.compilation, arguments, argumentNames, checkForOverflow: rc.checkForOverflow, conversions: rc.conversions, allowOptionalParameters: allowOptionalParameters); if (or.BestCandidate != null) { var m = or.BestCandidate; if (arguments == null && m.Name == DestructorDeclaration.MetadataName) { rc.Report.Error(0, loc, "Destructors cannot be called directly. Consider calling IDisposable.Dispose if available"); } CheckSpecialMethod(rc, m); if (or.BestCandidate.IsStatic && !or.IsExtensionMethodInvocation && !(mgrr.TargetResult is TypeExpression)) { return(or.CreateInvocation(new TypeExpression(mgrr.TargetType), returnTypeOverride: null)); } else { return(or.CreateInvocation(mgrr.TargetResult, returnTypeOverride: null)); } } else { // No candidate found at all (not even an inapplicable one). // This can happen with empty method groups (as sometimes used with extension methods) rc.Report.Error(0, loc, "`{0}' does not contain a definition for `{1}'", mgrr.TargetType.ToString(), mgrr.MethodName); return(null); } } if (target == null && expr is SimpleName) { rc.Report.Error(0, loc, "`{0}' does not contain a definition for `{1}'", rc.CurrentTypeDefinition.ToString(), expr.GetSignatureForError()); return(null); } else if (target == null) { return(null); } IMethod invokeMethod = target.Type.GetDelegateInvokeMethod(); if (invokeMethod != null) { // is it a delegate ? if (target.Type.Kind != TypeKind.Delegate) { rc.Report.Error(0, loc, "Cannot invoke a non-delegate type `{0}'", target.Type.ToString()); return(null); } OverloadResolution or = rc.CreateOverloadResolution(arguments, argumentNames); or.AddCandidate(invokeMethod); return(new Invocation( target, invokeMethod, //invokeMethod.ReturnType.Resolve(context), or.GetArgumentsWithConversionsAndNames(), or.BestCandidateErrors, isExpandedForm: or.BestCandidateIsExpandedForm, isDelegateInvocation: true, argumentToParameterMap: or.GetArgumentToParameterMap(), returnTypeOverride: null)); } rc.Report.Error(0, loc, "The member `{0}' cannot be used as method or delegate", target.GetSignatureForError()); return(ErrorResult); }