public static Arguments CreateDelegateMethodArguments(ResolveContext rc, AParametersCollection pd, TypeSpec[] types, Location loc) { Arguments delegate_arguments = new Arguments(pd.Count); for (int i = 0; i < pd.Count; ++i) { Argument.AType atype_modifier; switch (pd.FixedParameters [i].ModFlags & Parameter.Modifier.RefOutMask) { case Parameter.Modifier.REF: atype_modifier = Argument.AType.Ref; break; case Parameter.Modifier.OUT: atype_modifier = Argument.AType.Out; break; default: atype_modifier = 0; break; } var ptype = types[i]; if (ptype.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { ptype = rc.BuiltinTypes.Object; } delegate_arguments.Add(new Argument(new TypeExpression(ptype, loc), atype_modifier)); } return(delegate_arguments); }
static MetaType[] GetVarargsTypes(MethodSpec method, Arguments arguments) { AParametersCollection pd = method.Parameters; Argument a = arguments[pd.Count - 1]; Arglist list = (Arglist)a.Expr; return(list.ArgumentTypes); }
protected override ParametersCompiled ResolveParameters(ResolveContext ec, TypeInferenceContext tic, TypeSpec delegateType) { if (!delegateType.IsDelegate) { return(null); } AParametersCollection d_params = Delegate.GetParameters(delegateType); if (HasExplicitParameters) { if (!VerifyExplicitParameters(ec, delegateType, d_params)) { return(null); } return(Parameters); } // // If L has an implicitly typed parameter list we make implicit parameters explicit // Set each parameter of L is given the type of the corresponding parameter in D // if (!VerifyParameterCompatibility(ec, delegateType, d_params, ec.IsInProbingMode)) { return(null); } TypeSpec [] ptypes = new TypeSpec [Parameters.Count]; for (int i = 0; i < d_params.Count; i++) { // D has no ref or out parameters if ((d_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask) != 0) { return(null); } TypeSpec d_param = d_params.Types [i]; // // When type inference context exists try to apply inferred type arguments // if (tic != null) { d_param = tic.InflateGenericArgument(ec, d_param); } ptypes [i] = d_param; ImplicitLambdaParameter ilp = (ImplicitLambdaParameter)Parameters.FixedParameters [i]; ilp.SetParameterType(d_param); ilp.Resolve(null, i); } Parameters.Types = ptypes; return(Parameters); }
public bool NoExactMatch(ResolveContext ec, MethodBase method) { AParametersCollection pd = TypeManager.GetParameterData(method); Type source_type = pd.ExtensionMethodType; if (source_type != null) { Argument a = arguments [0]; if (TypeManager.IsGenericType(source_type) && TypeManager.ContainsGenericParameters(source_type)) { #if GMCS_SOURCE TypeInferenceContext tic = new TypeInferenceContext(TypeManager.GetTypeArguments(source_type)); tic.OutputTypeInference(ec, a.Expr, source_type); if (tic.FixAllTypes(ec)) { source_type = TypeManager.DropGenericTypeArguments(source_type).MakeGenericType(tic.InferredTypeArguments); } #else throw new NotSupportedException(); #endif } if (!Convert.ImplicitConversionExists(ec, a.Expr, source_type)) { ec.Report.Error(1936, loc, "An implementation of `{0}' query expression pattern for source type `{1}' could not be found", mg.Name, TypeManager.CSharpName(a.Type)); return(true); } } if (!TypeManager.IsGenericMethod(method)) { return(false); } if (mg.Name == "SelectMany") { ec.Report.Error(1943, loc, "An expression type is incorrect in a subsequent `from' clause in a query expression with source type `{0}'", arguments [0].GetSignatureForError()); } else { ec.Report.Error(1942, loc, "An expression type in `{0}' clause is incorrect. Type inference failed in the call to `{1}'", mg.Name.ToLower(), mg.Name); } return(true); }
public static TypeSpec CreateDelegateType(ResolveContext rc, AParametersCollection parameters, TypeSpec returnType, Location loc) { Namespace type_ns = rc.Module.GlobalRootNamespace.GetNamespace("System", true); if (type_ns == null) { return(null); } if (returnType == rc.BuiltinTypes.Void) { var actArgs = parameters.Types; var actionSpec = type_ns.LookupType(rc.Module, "Action", actArgs.Length, LookupMode.Normal, loc).ResolveAsType(rc); if (actionSpec == null) { return(null); } if (actArgs.Length == 0) { return(actionSpec); } else { return(actionSpec.MakeGenericType(rc, actArgs)); } } else { TypeSpec[] funcArgs = new TypeSpec[parameters.Types.Length + 1]; parameters.Types.CopyTo(funcArgs, 0); funcArgs[parameters.Types.Length] = returnType; var funcSpec = type_ns.LookupType(rc.Module, "Func", funcArgs.Length, LookupMode.Normal, loc).ResolveAsType(rc); if (funcSpec == null) { return(null); } return(funcSpec.MakeGenericType(rc, funcArgs)); } }