TemporaryVariableReference expr_tree_variable;
- HoistedVariable hoisted_variant;
+ HoistedParameter hoisted_variant;
public Parameter (FullNamedExpression type, string name, Modifier mod, Attributes attrs, Location loc)
{
if (HasOptionalExpression) {
a.Report.Error (1745, a.Location,
"Cannot specify `{0}' attribute on optional parameter `{1}'",
- TypeManager.CSharpName (a.Type).Replace ("Attribute", ""), Name);
+ a.Type.GetSignatureForError ().Replace ("Attribute", ""), Name);
}
if (a.Type == pa.DefaultParameterValue)
return null;
}
- TypeManager.CheckTypeVariance (parameter_type,
+ VarianceDecl.CheckTypeVariance (parameter_type,
(modFlags & Parameter.Modifier.RefOutMask) != 0 ? Variance.None : Variance.Contravariant,
rc);
if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic)) {
rc.Module.Compiler.Report.Error (1103, Location, "The extension method cannot be of type `{0}'",
- TypeManager.CSharpName (parameter_type));
+ parameter_type.GetSignatureForError ());
}
return parameter_type;
TypeSpec caller_type;
foreach (var attr in attributes.Attrs) {
- var atype = attr.ResolveType ();
+ var atype = attr.ResolveTypeForComparison ();
if (atype == null)
continue;
} else {
rc.Report.Error (1909, default_expr.Location,
"The DefaultParameterValue attribute is not applicable on parameters of type `{0}'",
- default_expr.Type.GetSignatureForError ()); ;
+ default_expr.Type.GetSignatureForError ());
}
default_expr = null;
//
// Hoisted parameter variant
//
- public HoistedVariable HoistedVariant {
+ public HoistedParameter HoistedVariant {
get {
return hoisted_variant;
}
{
string type_name;
if (parameter_type != null)
- type_name = TypeManager.CSharpName (parameter_type);
+ type_name = parameter_type.GetSignatureForError ();
else
type_name = texpr.GetSignatureForError ();
if (OptAttributes != null)
OptAttributes.Emit ();
- if (HasDefaultValue) {
+ if (HasDefaultValue && default_expr.Type != null) {
//
// Emit constant values for true constants only, the other
// constant-like expressions will rely on default value expression
if (inflated_param == types[i])
continue;
- default_value |= FixedParameters[i] is DefaultValueExpression;
+ default_value |= FixedParameters[i].HasDefaultValue;
inflated_types = new TypeSpec[types.Length];
- Array.Copy (types, inflated_types, types.Length);
+ Array.Copy (types, inflated_types, types.Length);
+ } else {
+ if (inflated_param == types[i])
+ continue;
+
+ default_value |= FixedParameters[i].HasDefaultValue;
}
inflated_types[i] = inflated_param;
var clone = (AParametersCollection) MemberwiseClone ();
clone.types = inflated_types;
+
+ //
+ // Default expression is original expression from the parameter
+ // declaration context which can be of nested enum in generic class type.
+ // In such case we end up with expression type of G<T>.E and e.g. parameter
+ // type of G<int>.E and conversion would fail without inflate in this
+ // context.
+ //
if (default_value) {
+ clone.parameters = new IParameterData[Count];
for (int i = 0; i < Count; ++i) {
- var dve = clone.FixedParameters[i] as DefaultValueExpression;
- if (dve != null) {
- throw new NotImplementedException ("net");
- // clone.FixedParameters [i].DefaultValue = new DefaultValueExpression ();
- }
+ var fp = FixedParameters[i];
+ clone.FixedParameters[i] = fp;
+
+ if (!fp.HasDefaultValue)
+ continue;
+
+ var expr = fp.DefaultValue;
+
+ if (inflated_types[i] == expr.Type)
+ continue;
+
+ var c = expr as Constant;
+ if (c != null) {
+ //
+ // It may fail we are inflating before type validation is done
+ //
+ c = Constant.ExtractConstantFromValue (inflated_types[i], c.GetValue (), expr.Location);
+ if (c == null)
+ expr = new DefaultValueExpression (new TypeExpression (inflated_types[i], expr.Location), expr.Location);
+ else
+ expr = c;
+ } else if (expr is DefaultValueExpression)
+ expr = new DefaultValueExpression (new TypeExpression (inflated_types[i], expr.Location), expr.Location);
+
+ clone.FixedParameters[i] = new ParameterData (fp.Name, fp.ModFlags, expr);
}
}
if (types == null || types [pos] == null)
return ((Parameter)FixedParameters [pos]).GetSignatureForError ();
- string type = TypeManager.CSharpName (types [pos]);
+ string type = types [pos].GetSignatureForError ();
if (FixedParameters [pos].HasExtensionMethodModifier)
return "this " + type;
- Parameter.Modifier mod = FixedParameters [pos].ModFlags;
+ var mod = FixedParameters[pos].ModFlags & Parameter.Modifier.ModifierMask;
if (mod == 0)
return type;
{
}
- protected override Expression DoResolve (ResolveContext rc)
- {
- return base.DoResolve (rc);
- }
-
public void Resolve (ResolveContext rc, Parameter p)
{
var expr = Resolve (rc);
- if (expr == null)
+ if (expr == null) {
+ this.expr = ErrorExpression.Instance;
return;
+ }
expr = Child;
rc.Report.Error (1750, Location,
"Optional parameter expression of type `{0}' cannot be converted to parameter type `{1}'",
type.GetSignatureForError (), parameter_type.GetSignatureForError ());
+
+ this.expr = ErrorExpression.Instance;
}
public override object Accept (StructuralVisitor visitor)